File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -253,6 +253,21 @@ defmodule IEx.ANSIDocs do
253253 end
254254
255255 defp handle_links ( text ) do
256+ text
257+ |> remove_square_brackets_in_link
258+ |> escape_underlines_in_link
259+ end
260+
261+ defp escape_underlines_in_link ( text ) do
262+ case Regex . match? ( % r { . * ( https? \S* ) } , text ) do
263+ true ->
264+ Regex . replace ( % r { _ } , text , "\\ \\ _" )
265+ _ ->
266+ text
267+ end
268+ end
269+
270+ defp remove_square_brackets_in_link ( text ) do
256271 Regex . replace ( % r { \[ ( .* ?) \] \( ( . * ?) \) } , text , "\\ 1 (\\ 2)" )
257272 end
258273
Original file line number Diff line number Diff line change @@ -194,4 +194,11 @@ defmodule IEx.AnsiDocsTest do
194194 result = format ( "(`hello world`)" )
195195 assert result == "(\e [36mhello world\e [0m)\n \e [0m"
196196 end
197+
198+ test "escaping of underlines within links" do
199+ result = format ( "(http://en.wikipedia.org/wiki/ANSI_escape_code)" )
200+ assert result == "(http://en.wikipedia.org/wiki/ANSI_escape_code)\n \e [0m"
201+ result = format ( "[ANSI escape code](http://en.wikipedia.org/wiki/ANSI_escape_code)" )
202+ assert result == "ANSI escape code (http://en.wikipedia.org/wiki/ANSI_escape_code)\n \e [0m"
203+ end
197204end
You can’t perform that action at this time.
0 commit comments