Skip to content

Commit

Permalink
Merge pull request #8739 from kikofernandez/kiko/stdlib/fix-markdown-…
Browse files Browse the repository at this point in the history
…format-within-parens/GH-8738/OTP-19200

stdlib: fix markdown parsing within parens

OTP-19200
  • Loading branch information
kikofernandez authored Aug 22, 2024
2 parents 50cc3be + 8441966 commit f7ddb9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/stdlib/src/shell_docs_markdown.erl
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,15 @@ process_format(<<Char, Format, Char2, Rest/binary>>, [<<Format>>], Buffer)
%% so no formatting of code should happen
process_format(<<Char, Format, Char2, Rest/binary>>, Fs, Buffer)
when ?VALID_FORMAT(Format) andalso
(Char =/= Format andalso Char =/= $\s andalso Char =/= $\n andalso not ?VALID_FORMAT(Char)) andalso
(Char =/= Format andalso Char =/= $\s andalso Char =/= $\n andalso not ?VALID_FORMAT(Char) andalso
not ?VALID_PUNCTUATION(Char)) andalso
(Char2 =/= Format andalso Char2 =/= $\s andalso Char2 =/= $\n andalso not ?VALID_FORMAT(Char2) andalso
not ?VALID_PUNCTUATION(Char2)) ->
process_format(Rest, Fs, merge_buffers([<<Char, Format, Char2>>], Buffer));
process_format(<<Char, Format, Format, Char2, Rest/binary>>, Fs, Buffer)
when ?VALID_FORMAT(Format) andalso
(Char =/= Format andalso Char =/= $\s andalso Char =/= $\n andalso not ?VALID_FORMAT(Char)) andalso
(Char =/= Format andalso Char =/= $\s andalso Char =/= $\n andalso not ?VALID_FORMAT(Char) andalso
not ?VALID_PUNCTUATION(Char)) andalso
(Char2 =/= Format andalso Char2 =/= $\s andalso Char2 =/= $\n andalso not ?VALID_FORMAT(Char2) andalso
not ?VALID_PUNCTUATION(Char2)) ->
process_format(Rest, Fs, merge_buffers([<<Char, Format, Char2>>], Buffer));
Expand Down
24 changes: 22 additions & 2 deletions lib/stdlib/test/shell_docs_markdown_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
list_format_with_italics_in_sentence/1, list_format_with_bold_in_sentence/1,
new_lines_test/1, format_separator_test/1, list_with_format/1, multi_word_format_test/1,
multiline_link/1, multiline_link_not_allowed/1, inline_mfa_link/1,
escaped_character/1]).
escaped_character/1, parens_with_italics/1]).

%% Bullet lists
-export([singleton_bullet_list/1, singleton_bullet_list_followed_new_paragraph/1, singleton_bullet_list_with_format/1,
Expand Down Expand Up @@ -234,7 +234,8 @@ format_tests() ->
multiline_link,
multiline_link_not_allowed,
inline_mfa_link,
escaped_character
escaped_character,
parens_with_italics
].

bullet_list_tests() ->
Expand Down Expand Up @@ -754,6 +755,25 @@ escaped_character(_Config) ->
inline_code(~"`test`")]),
compile_and_compare(Input, Result).

parens_with_italics(_Config) ->
Input = ~"Test ( _Optional_). ( _Optional_ .) ( _Optional_ ). (_Optional_). (_Optional._)",
Result = p([~"Test ( ", it(~"Optional"), ~"). ( "
, it(~"Optional"), ~" .) ( "
, it(~"Optional"), ~" ). ("
, it(~"Optional"), ~"). ("
, it(~"Optional."), ~")"]),
compile_and_compare(Input, Result),

Input1 = ~"Test ( __Optional__). ( __Optional__ .) ",
Input2 = ~"( __Optional__ ). (__Optional__). (__Optional.__)",
InputEm = <<Input1/binary, Input2/binary>>,
ResultEm = p([~"Test ( ", em(~"Optional"), ~"). ( "
, em(~"Optional"), ~" .) ( "
, em(~"Optional"), ~" ). ("
, em(~"Optional"), ~"). ("
, em(~"Optional."), ~")"]),
compile_and_compare(InputEm, ResultEm).

list_with_format(_Config) ->
Input = ~"- **`--help` (or `-h`)** - Print this message and exit.",
Result = ul([li(p([em([inline_code(~"--help"),
Expand Down

0 comments on commit f7ddb9c

Please sign in to comment.