From 8441966f7923b70ac890bf7e03931f73a799c05e Mon Sep 17 00:00:00 2001 From: Kiko Fernandez-Reyes Date: Wed, 21 Aug 2024 10:56:50 +0200 Subject: [PATCH] stdlib: fix markdown parsing within parens fixes the markdown produce by `shell_docs_markdown` which was producing incorrect markdown code for `Text (_Option._) Text`, where the italics (`_`) where not parsed correcly, producing incorrect format. --- lib/stdlib/src/shell_docs_markdown.erl | 6 +++-- lib/stdlib/test/shell_docs_markdown_SUITE.erl | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/stdlib/src/shell_docs_markdown.erl b/lib/stdlib/src/shell_docs_markdown.erl index e9b3a9545294..34a9b4736dd7 100644 --- a/lib/stdlib/src/shell_docs_markdown.erl +++ b/lib/stdlib/src/shell_docs_markdown.erl @@ -596,13 +596,15 @@ process_format(<>, [<>], Buffer) %% so no formatting of code should happen process_format(<>, 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([<>], Buffer)); process_format(<>, 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([<>], Buffer)); diff --git a/lib/stdlib/test/shell_docs_markdown_SUITE.erl b/lib/stdlib/test/shell_docs_markdown_SUITE.erl index def3d0b56a1e..8304ccccae50 100644 --- a/lib/stdlib/test/shell_docs_markdown_SUITE.erl +++ b/lib/stdlib/test/shell_docs_markdown_SUITE.erl @@ -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, @@ -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() -> @@ -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 = <>, + 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"),