Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/elixir/lib/io/ansi/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ defmodule IO.ANSI.Docs do

doc
|> String.split(["\r\n", "\n"], trim: false)
|> Enum.map(&String.trim_trailing/1)
|> Enum.map(&remove_ial/1)
|> process([], "", options)
end

Expand Down Expand Up @@ -228,6 +228,11 @@ defmodule IO.ANSI.Docs do
end
end

defp remove_ial(text) do
ial_and_ws = ~r/(?:\s*\{:\s+.+?\})?\s*\z/
Regex.replace(ial_and_ws, text, "")
end

### Headings

defp write_heading(heading, rest, text, indent, options) do
Expand Down
27 changes: 27 additions & 0 deletions lib/elixir/test/elixir/io/ansi/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ defmodule IO.ANSI.DocsTest do
assert result == "\e[33m# wibble\e[0m\n\e[0m\ntext\n\e[0m"
end

test "ial of first level heading is removed (non regression)" do
result = format_markdown("# wibble {: .warning}\n\ntext\n")
assert result == "\e[33m# wibble\e[0m\n\e[0m\ntext\n\e[0m"
end

test "second level heading is converted" do
result = format_markdown("## wibble\n\ntext\n")
assert result == "\e[33m## wibble\e[0m\n\e[0m\ntext\n\e[0m"
Expand Down Expand Up @@ -181,6 +186,28 @@ defmodule IO.ANSI.DocsTest do
"""
end

test "ial removed from multi-line quote block's headline (use case from String.split_at's)" do
result =
format_markdown("""
> #### Linear Access {: .warning}
>
> This function splits on graphemes and for such it has to linearly traverse
> the string.
> If you want to split a string or a binary based on the number of bytes,
> use `Kernel.binary_part/3` instead.
""")

assert result ==
"""
\e[90m> \e[0m#### Linear Access
\e[90m> \e[0m
\e[90m> \e[0mThis function splits on graphemes and for such it has to linearly traverse
\e[90m> \e[0mthe string. If you want to split a string or a binary based on the number of
\e[90m> \e[0mbytes, use \e[36mKernel.binary_part/3\e[0m instead.
\e[0m\
"""
end

test "code block is converted" do
result = format_markdown("line\n\n code\n code2\n\nline2\n")
assert result == "line\n\e[0m\n\e[36m code\n code2\e[0m\n\e[0m\nline2\n\e[0m"
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/test/elixir/kernel/fn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ defmodule Kernel.FnTest do

test "capture with assignment in module" do
mod = :outer
assert (&(mod = List).flatten(&1)).([1, [2], 3]) == [1, 2, 3]
assert (&(_mod = List).flatten(&1)).([1, [2], 3]) == [1, 2, 3]
assert mod == :outer
end

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/test/elixir/module/types/expr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4018,7 +4018,7 @@ defmodule Module.Types.ExprTest do
%{limit: l} ->
is_map_key(x, :a) and
case "" do
<<_::size(l)>> -> true
<<_::size(^l)>> -> true
_ -> false
end

Expand Down
Loading