Skip to content

Commit bed0a68

Browse files
committed
Do not use unicode chars if ANSI is disabled
See #10481 (comment)
1 parent 60642c3 commit bed0a68

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
defmodule IO.ANSI.Docs do
22
@moduledoc false
33

4-
@bullet_text "• "
4+
@bullet_text_unicode "• "
5+
@bullet_text_ascii "* "
56
@bullets [?*, ?-, ?+]
67
@spaces [" ", "\n", "\t"]
78

@@ -219,7 +220,10 @@ defmodule IO.ANSI.Docs do
219220
end
220221

221222
defp traverse_erlang_html({:dt, _, entries}, indent, options) do
222-
["#{indent} ", @bullet_text | handle_erlang_html_text(entries, indent <> " ", options)]
223+
[
224+
"#{indent} ",
225+
bullet_text(options) | handle_erlang_html_text(entries, indent <> " ", options)
226+
]
223227
end
224228

225229
defp traverse_erlang_html({:dd, _, entries}, indent, options) do
@@ -240,7 +244,10 @@ defmodule IO.ANSI.Docs do
240244
end
241245
else
242246
for {:li, _, lines} <- entries do
243-
["#{indent} ", @bullet_text | handle_erlang_html_text(lines, indent <> " ", options)]
247+
[
248+
"#{indent} ",
249+
bullet_text(options) | handle_erlang_html_text(lines, indent <> " ", options)
250+
]
244251
end
245252
end
246253
end
@@ -424,7 +431,7 @@ defmodule IO.ANSI.Docs do
424431
case stripped do
425432
<<bullet, ?\s, item::binary>> when bullet in @bullets ->
426433
write_text(text, indent, options)
427-
process_list(@bullet_text, item, rest, count, indent, options)
434+
process_list(bullet_text(options), item, rest, count, indent, options)
428435

429436
<<d1, ?., ?\s, item::binary>> when d1 in ?0..?9 ->
430437
write_text(text, indent, options)
@@ -930,6 +937,10 @@ defmodule IO.ANSI.Docs do
930937
end
931938
end
932939

940+
defp bullet_text(options) do
941+
if options[:enabled], do: @bullet_text_unicode, else: @bullet_text_ascii
942+
end
943+
933944
defp color(style, colors) do
934945
IO.ANSI.format_fragment(colors[style], colors[:enabled])
935946
end

lib/elixir/test/elixir/io/ansi/docs_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ defmodule IO.ANSI.DocsTest do
192192
assert result == " • one\n • two\n • three\n\e[0m"
193193
end
194194

195+
test "* list is converted without ansi" do
196+
result = format_markdown("* one\n* two\n* three\n", enabled: false)
197+
assert result == " * one\n * two\n * three"
198+
end
199+
195200
test "* list surrounded by text is converted" do
196201
result = format_markdown("Count:\n\n* one\n* two\n* three\n\nDone")
197202
assert result == "Count:\n\e[0m\n • one\n • two\n • three\n\e[0m\nDone\n\e[0m"

0 commit comments

Comments
 (0)