diff --git a/CHANGES.md b/CHANGES.md index a892f591..12f68eac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,9 @@ Development: adds a new file `markdown-unicode-data.lua`, which must be properly installed with the rest of the Markdown package. +- Add renderers `warning` and `error` that represent warnings and errors + produced by the markdown parser. (#452, #473, #496) + Fixes: - Properly load LaTeX themes when `theme` or `import` is used in @@ -21,6 +24,8 @@ Fixes: prototype. (#500) - Correctly handle backslashes in `\markdownOptionOutputDir` on Windows. (#492, #500, reported by @l0th3r) +- Fix hard line breaks in blockquotes. + (#494, #495, reported by @l0th3r, #496, contributed by @lostenderman) ## 3.7.0 (2024-08-30) @@ -32,8 +37,6 @@ Development: (istqborg/istqb_product_base#46, #440, #451, sponsored by @istqborg) - Add option `ensureJekyllData` for processing standalone YAML files. (#452, #473, sponsored by @istqborg) -- Add renderers `warning` and `error` that represent warnings and errors - produced by the markdown parser. (#452, #473) - Support user-defined LaTeX environments with LaTeX markup. (#20, #477, suggested by @cdupont) diff --git a/markdown.dtx b/markdown.dtx index 0eaa6713..5ee7de7e 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -20097,7 +20097,16 @@ following text: The \mdef{markdownRendererWarning} and \mdef{markdownRendererError} macros represent warnings and errors produced by the markdown parser. Both macros -receive a single parameter with the text of the warning or error. +receive four parameters: + +1. The fully escaped text of the warning or error that can be directly typeset +2. The raw text of the warning or error that can be used outside typesetting + for e.g. logging the warning or error. +3. The fully escaped text with more details about the warning or error that + can be directly typeset. Can be empty, unlike the first two parameters. +4. The raw text with more details about the warning or error that can be used + outside typesetting for e.g. logging the warning or error. Can be empty, + unlike the first two parameters. % \end{markdown} % @@ -20118,14 +20127,14 @@ receive a single parameter with the text of the warning or error. \prop_gput:Nnn \g_@@_renderer_arities_prop { warning } - { 1 } + { 4 } \seq_gput_right:Nn \g_@@_renderers_seq { error } \prop_gput:Nnn \g_@@_renderer_arities_prop { error } - { 1 } + { 4 } \ExplSyntaxOff % \end{macrocode} % \par @@ -25758,24 +25767,28 @@ function M.writer.new(options) % \begin{markdown} % % Define \luamdef{writer->warning} as a function that will transform an input -% warning `t` to the output format. +% warning `t` with optional more warning text `m` to the output format. % % \end{markdown} % \begin{macrocode} - function self.warning(t) - return {"\\markdownRendererWarning{", self.identifier(t), "}"} + function self.warning(t, m) + return {"\\markdownRendererWarning{", self.escape(t), "}{", + escape_minimal(t), "}{", self.escape(m or ""), "}{", + escape_minimal(m or ""), "}"} end % \end{macrocode} % \par % \begin{markdown} % % Define \luamdef{writer->error} as a function that will transform an input -% error `t` to the output format. +% error text `t` with optional more error text `m` to the output format. % % \end{markdown} % \begin{macrocode} - function self.error(t) - return {"\\markdownRendererError{", self.identifier(t), "}"} + function self.error(t, m) + return {"\\markdownRendererError{", self.escape(t), "}{", + escape_minimal(t), "}{", self.escape(m or ""), "}{", + escape_minimal(m or ""), "}"} end % \end{macrocode} % \par @@ -28824,8 +28837,11 @@ function M.reader.new(writer, options) end local res = lpeg.match(grammar(), str) if res == nil then - return writer.error(format("%s failed on:\n%s", - name, str:sub(1,20))) + return writer.error( + format("Parser `%s` failed to process the input text.", name), + format("Here are the first 20 characters of the remaining " + .. "unprocessed text: `%s`.", str:sub(1,20)) + ) else return res end @@ -29680,7 +29696,7 @@ function M.reader.new(writer, options) parsers.link_and_emph_content = Ct( Cg(Cc("content"), "type") * Cg(Cs(( parsers.link_emph_precedence - + parsers.backslash * parsers.any + + parsers.backslash * parsers.linechar + parsers.link_and_emph_endline + (parsers.linechar - parsers.blankline^2 @@ -31144,7 +31160,7 @@ end input = uni_algos.normalize.NFKD(input) else return writer.error( - format("Unknown normalization form %s", form)) + format("Unknown normalization form %s.", form)) end end % \end{macrocode} @@ -33762,7 +33778,7 @@ M.extensions.jekyll_data = function(expect_jekyll_data, else local error = self.error(format( "Unexpected type %s for value of " - .. "YAML key %s", typ, k)) + .. "YAML key %s.", typ, k)) table.insert(buf, error) end end @@ -34739,8 +34755,28 @@ end \ExplSyntaxOff \def\markdownRendererSectionBeginPrototype{}% \def\markdownRendererSectionEndPrototype{}% -\let\markdownRendererWarningPrototype\markdownWarning -\let\markdownRendererErrorPrototype\markdownError +\ExplSyntaxOn +\cs_gset:Npn + \markdownRendererWarningPrototype + #1#2#3#4 + { + \tl_set:Nn + \l_tmpa_tl + { #2 } + \tl_if_empty:nF + { #4 } + { + \tl_put_right:Nn + \l_tmpa_tl + { \iow_newline: #4 } + } + \exp_args:NV + \markdownWarning + \l_tmpa_tl + } +\ExplSyntaxOff +\def\markdownRendererErrorPrototype#1#2#3#4{% + \markdownError{#2}{#4}}% % \end{macrocode} % \par % \begin{markdown} diff --git a/tests/support/keyval-setup.tex b/tests/support/keyval-setup.tex index 300c08e5..21f69763 100644 --- a/tests/support/keyval-setup.tex +++ b/tests/support/keyval-setup.tex @@ -194,5 +194,8 @@ (ellipsis|nbsp|*Brace|*Sign|ampersand|underscore|hash|circumflex|backslash|tilde|pipe|replacementCharacter) += {\GOBBLE}, (ticked|halfTicked|unticked)Box += {\GOBBLE}, warning|error = {% - \TYPE{#0: #1}}, + \TYPE{BEGIN #0}% + \TYPE{- text: #1}% + \TYPE{- more: #3}% + \TYPE{END #0}}, }% diff --git a/tests/testfiles/regression/github/issue-495.test b/tests/testfiles/regression/github/issue-495.test new file mode 100644 index 00000000..57469992 --- /dev/null +++ b/tests/testfiles/regression/github/issue-495.test @@ -0,0 +1,10 @@ +<<< +> **TITLE** \ +> Lorem ipsum dolor sit amet +>>> +BEGIN document +blockQuoteBegin +strongEmphasis: TITLE +hardLineBreak +blockQuoteEnd +END document diff --git a/tests/testfiles/unit/lunamark-markdown/ensure-jekyll-data.test b/tests/testfiles/unit/lunamark-markdown/ensure-jekyll-data.test index d4a89098..1aaa72a1 100644 --- a/tests/testfiles/unit/lunamark-markdown/ensure-jekyll-data.test +++ b/tests/testfiles/unit/lunamark-markdown/ensure-jekyll-data.test @@ -34,5 +34,8 @@ abstract: | --- >>> BEGIN document -error: parse_blocks failed on: title: The document +BEGIN error +- text: Parser `parse(underscore)blocks` failed to process the input text. +- more: Here are the first 20 characters of the remaining unprocessed text: `title: The document `. +END error END document