From 6ac93fd51bb809690f115f7e6441923d7431c278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 13:46:48 +0200 Subject: [PATCH 1/9] Update `CHANGES.md` --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5804b2954..d37ab55e6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,8 @@ Development: of YAML in all formats, not just in LaTeX. (#275, #349) - Add an optional argument to the `markdown` LaTeX environment. (#299, #351) +- Add support for Pandoc `mark` syntax extension. + (jgm/lunamark#67, #303, #352) Deprecation: From bd291d420964b1dd64713913e8d803eb3dce262a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:06:18 +0200 Subject: [PATCH 2/9] Add mark syntax extension to `extensions.bracketed_spans` (now `spans`) --- markdown.dtx | 72 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 037d9b28c..9cdfade4c 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -28523,16 +28523,19 @@ M.extensions = {} % \end{macrocode} % \begin{markdown} % -%#### Bracketed Spans +%#### Bracketed Spans and Highlighted Text % -% The \luamdef{extensions.bracketed_spans} function implements the Pandoc -% bracketed span syntax extension. +% The \luamdef{extensions.spans} function implements the Pandoc +% bracketed span and mark syntax extensions. When the `bracketed_spans` +% parameter is enabled, the Pandoc bracketed span syntax extension will +% be enabled. When the `mark` parameter is enabled, the Pandoc mark syntax +% extension will be enabled. % % \end{markdown} % \begin{macrocode} -M.extensions.bracketed_spans = function() +M.extensions.spans = function(bracketed_spans, mark) return { - name = "built-in bracketed_spans syntax extension", + name = "built-in spans syntax extension", extend_writer = function(self) % \end{macrocode} % \par @@ -28553,25 +28556,41 @@ M.extensions.bracketed_spans = function() local parsers = self.parsers local writer = self.writer - local span_label = parsers.lbracket - * (Cs((parsers.alphanumeric^1 - + parsers.inticks - + parsers.autolink - + V("InlineHtml") - + ( parsers.backslash * parsers.backslash) - + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) - + V("Space") + V("Endline") - + (parsers.any - - (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^1) - / self.parser_functions.parse_inlines) - * parsers.rbracket - - local Span = span_label - * Ct(parsers.attributes) - / writer.span + if bracketed_spans then + local span_label = parsers.lbracket + * (Cs((parsers.alphanumeric^1 + + parsers.inticks + + parsers.autolink + + V("InlineHtml") + + ( parsers.backslash * parsers.backslash) + + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) + + V("Space") + V("Endline") + + (parsers.any + - (parsers.newline + parsers.lbracket + parsers.rbracket + + parsers.blankline^2))))^1) + / self.parser_functions.parse_inlines) + * parsers.rbracket + + local Span = span_label + * Ct(parsers.attributes) + / writer.span - self.insert_pattern("Inline before LinkAndEmph", - Span, "Span") + self.insert_pattern("Inline before LinkAndEmph", + Span, "Span") + end + + if mark then + local doubleequals = P("==") + + local Mark = parsers.between(V("Inline"), doubleequals, doubleequals) + / function (inlines) + return writer.span(inlines, {".mark"}) + end + + self.add_special_character("=") + self.insert_pattern("Inline before LinkAndEmph", + Mark, "Mark") + end end } end @@ -30825,9 +30844,10 @@ function M.new(options) % \begin{macrocode} local extensions = {} - if options.bracketedSpans then - local bracketed_spans_extension = M.extensions.bracketed_spans() - table.insert(extensions, bracketed_spans_extension) + if options.bracketedSpans or options.mark then + local spans_extension = M.extensions.spans( + options.bracketedSpans, options.mark) + table.insert(extensions, spans_extension) end if options.contentBlocks then From e37a8ae88f613a5006853e028528e1a64c387bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:17:48 +0200 Subject: [PATCH 3/9] Add `mark` Lua option --- markdown.dtx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/markdown.dtx b/markdown.dtx index 9cdfade4c..6e408254f 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -7616,6 +7616,75 @@ defaultOptions.lineBlocks = false % %<*manual-options> +#### Option `mark` + +`mark` (default value: `false`) + +% \fi +% \begin{markdown} +% +% \Optitem[false]{mark}{\opt{true}, \opt{false}} +% +: true + + : Enable the Pandoc [mark syntax extension][pandoc-mark]: + + ``` md + This ==is highlighted text.== + `````` + +: false + + : Disable the Pandoc mark syntax extension. + + [pandoc-mark]: https://pandoc.org/MANUAL.html#extension-mark + +% \end{markdown} +% \iffalse + +##### \LaTeX{} Example {.unnumbered} + +Using a text editor, create a text document named `document.tex` with the +following content: +``` tex +\documentclass{article} +\usepackage[mark]{markdown} +\begin{document} +\begin{markdown} +This ==is highlighted text.== +\end{markdown} +\end{document} +``````` +Next, invoke LuaTeX from the terminal: +``` sh +lualatex document.tex +`````` +A PDF document named `document.pdf` should be produced and contain the +following text: + +> This is highlighted text. + +% +%<*tex> +% \fi +% \begin{macrocode} +\@@_add_lua_option:nnn + { mark } + { boolean } + { false } +% \end{macrocode} +% \iffalse +% +%<*lua,lua-cli> +% \fi +% \begin{macrocode} +defaultOptions.mark = false +% \end{macrocode} +% \par +% \iffalse +% +%<*manual-options> + #### Option `notes` `notes` (default value: `false`) From 0ca7b010b92bfe5c51413f17eca58610cc771173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:25:42 +0200 Subject: [PATCH 4/9] Split `extensions.spans` to `bracketed_spans` and `mark` --- markdown.dtx | 119 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 46 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 6e408254f..ea130a3ce 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -28592,19 +28592,16 @@ M.extensions = {} % \end{macrocode} % \begin{markdown} % -%#### Bracketed Spans and Highlighted Text +%#### Bracketed Spans % -% The \luamdef{extensions.spans} function implements the Pandoc -% bracketed span and mark syntax extensions. When the `bracketed_spans` -% parameter is enabled, the Pandoc bracketed span syntax extension will -% be enabled. When the `mark` parameter is enabled, the Pandoc mark syntax -% extension will be enabled. +% The \luamdef{extensions.bracketed_spans} function implements the Pandoc +% bracketed span syntax extension. % % \end{markdown} % \begin{macrocode} -M.extensions.spans = function(bracketed_spans, mark) +M.extensions.bracketed_spans = function() return { - name = "built-in spans syntax extension", + name = "built-in bracketed_spans syntax extension", extend_writer = function(self) % \end{macrocode} % \par @@ -28625,41 +28622,26 @@ M.extensions.spans = function(bracketed_spans, mark) local parsers = self.parsers local writer = self.writer - if bracketed_spans then - local span_label = parsers.lbracket - * (Cs((parsers.alphanumeric^1 - + parsers.inticks - + parsers.autolink - + V("InlineHtml") - + ( parsers.backslash * parsers.backslash) - + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) - + V("Space") + V("Endline") - + (parsers.any - - (parsers.newline + parsers.lbracket + parsers.rbracket - + parsers.blankline^2))))^1) - / self.parser_functions.parse_inlines) - * parsers.rbracket - - local Span = span_label - * Ct(parsers.attributes) - / writer.span - - self.insert_pattern("Inline before LinkAndEmph", - Span, "Span") - end - - if mark then - local doubleequals = P("==") + local span_label = parsers.lbracket + * (Cs((parsers.alphanumeric^1 + + parsers.inticks + + parsers.autolink + + V("InlineHtml") + + ( parsers.backslash * parsers.backslash) + + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) + + V("Space") + V("Endline") + + (parsers.any + - (parsers.newline + parsers.lbracket + parsers.rbracket + + parsers.blankline^2))))^1) + / self.parser_functions.parse_inlines) + * parsers.rbracket + + local Span = span_label + * Ct(parsers.attributes) + / writer.span - local Mark = parsers.between(V("Inline"), doubleequals, doubleequals) - / function (inlines) - return writer.span(inlines, {".mark"}) - end - - self.add_special_character("=") - self.insert_pattern("Inline before LinkAndEmph", - Mark, "Mark") - end + self.insert_pattern("Inline before LinkAndEmph", + Span, "Span") end } end @@ -29925,6 +29907,47 @@ end % \end{macrocode} % \begin{markdown} % +%#### Marked spans +% +% The \luamdef{extensions.mark} function implements the Pandoc mark syntax +% extension. +% +% \end{markdown} +% \begin{macrocode} +M.extensions.mark = function() + return { + name = "built-in mark syntax extension", + extend_writer = function(self) +% \end{macrocode} +% \par +% \begin{markdown} +% +% Define \luamdef{writer->mark} as a function that will transform an input +% marked span `s` to the output format. +% +% \end{markdown} +% \begin{macrocode} + function self.mark(s) + return {"\\markdownRendererMarkedSpan{", s, "}"} + end + end, extend_reader = function(self) + local parsers = self.parsers + local writer = self.writer + + local doubleequals = P("==") + + local Mark = parsers.between(V("Inline"), doubleequals, doubleequals) + / function (inlines) return writer.mark(inlines) end + + self.add_special_character("=") + self.insert_pattern("Inline before LinkAndEmph", + Mark, "Mark") + end + } +end +% \end{macrocode} +% \begin{markdown} +% %#### Link Attributes % % The \luamdef{extensions.link_attributes} function implements the Pandoc @@ -30913,10 +30936,9 @@ function M.new(options) % \begin{macrocode} local extensions = {} - if options.bracketedSpans or options.mark then - local spans_extension = M.extensions.spans( - options.bracketedSpans, options.mark) - table.insert(extensions, spans_extension) + if options.bracketedSpans then + local bracketed_spans_extension = M.extensions.bracketedSpans() + table.insert(extensions, bracketed_spans_extension) end if options.contentBlocks then @@ -30973,6 +30995,11 @@ function M.new(options) table.insert(extensions, line_block_extension) end + if options.mark then + local mark_extension = M.extensions.mark() + table.insert(extensions, mark_extension) + end + if options.pipeTables then local pipe_tables_extension = M.extensions.pipe_tables( options.tableCaptions, options.tableAttributes) From 86c52557ac28a636b0e6069d154f06c31a95353a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:38:00 +0200 Subject: [PATCH 5/9] Add `markedSpan` token renderer and token renderer prototype --- markdown.dtx | 83 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index ea130a3ce..3eccbcf30 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -1328,7 +1328,7 @@ local uni_case = require("lua-uni-case") % \pkg{soulutf8} % %: A package that is used in the default renderer prototype for -% strike-throughs. +% strike-throughs and marked spans. % % \pkg{ltxcmds} % @@ -7651,7 +7651,9 @@ following content: \usepackage[mark]{markdown} \begin{document} \begin{markdown} + This ==is highlighted text.== + \end{markdown} \end{document} ``````` @@ -16025,6 +16027,73 @@ following text: % % \begin{markdown} +#### Marked Span Renderer +The following macro is only produced, when the \Opt{mark} option is enabled. + +The \mdef{markdownRendererMarkedSpan} macro represents a span of marked or +highlighted text. The macro receives a single argument that corresponds to +the marked span. + +% \end{markdown} +% +% \iffalse + +##### \LaTeX{} Example {.unnumbered} + +Using a text editor, create a text document named `document.tex` with the +following content: +``` tex +\documentclass{article} +\usepackage[mark]{markdown} +\usepackage{soul} +\markdownSetup{ + renderers = { + markedSpan = {\hl{#1}}, + }, +} +\begin{document} +\begin{markdown} + +This ==is highlighted text.== + +\end{markdown} +\end{document} +``````` +Next, invoke LuaTeX from the terminal: +``` sh +lualatex document.tex +`````` +A PDF document named `document.pdf` should be produced and contain the +following text: + +> This is highlighted text. + +% +%<*tex> +% \fi +% +% \begin{macrocode} +\def\markdownRendererMarkedSpan{% + \markdownRendererMarkedSpanPrototype}% +\ExplSyntaxOn +\seq_gput_right:Nn + \g_@@_renderers_seq + { markedSpan } +\prop_gput:Nnn + \g_@@_renderer_arities_prop + { markedSpan } + { 1 } +\ExplSyntaxOff +% \end{macrocode} +% \par +% +% \iffalse +% +%<*manual-tokens> +% \fi +% +% \begin{markdown} + #### Markdown Document Renderers The \mdef{markdownRendererDocumentBegin} and \mdef{markdownRendererDocumentEnd} macros represent the beginning and the end of a *markdown* document. The macros @@ -33751,18 +33820,18 @@ end % \par % \begin{markdown} % -%#### Strike-Through -% If the \Opt{strikeThrough} option is enabled, we will load the -% \pkg{soulutf8} package and use it to implement strike-throughs. +%#### Marked Spans +% If the \Opt{mark} option is enabled, we will load the \pkg{soulutf8} package +% and use it to implement marked text. % % \end{markdown} % \begin{macrocode} -\markdownIfOption{strikeThrough}{% +\markdownIfOption{mark}{% \RequirePackage{soulutf8}% \markdownSetup{ rendererPrototypes = { - strikeThrough = {% - \st{#1}% + markedSpan = {% + \hl{#1}% }, } } From f07c3a6102f23d5858c7f26a99fce15723d42d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:42:37 +0200 Subject: [PATCH 6/9] Rename `markedSpan` token renderer (prototype) to `mark` --- markdown.dtx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 3eccbcf30..5d8f76277 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -1328,7 +1328,7 @@ local uni_case = require("lua-uni-case") % \pkg{soulutf8} % %: A package that is used in the default renderer prototype for -% strike-throughs and marked spans. +% strike-throughs and marked text. % % \pkg{ltxcmds} % @@ -16027,12 +16027,12 @@ following text: % % \begin{markdown} -#### Marked Span Renderer +#### Marked Text Renderer The following macro is only produced, when the \Opt{mark} option is enabled. -The \mdef{markdownRendererMarkedSpan} macro represents a span of marked or +The \mdef{markdownRendererMark} macro represents a span of marked or highlighted text. The macro receives a single argument that corresponds to -the marked span. +the marked text. % \end{markdown} % @@ -16048,7 +16048,7 @@ following content: \usepackage{soul} \markdownSetup{ renderers = { - markedSpan = {\hl{#1}}, + mark = {\hl{#1}}, }, } \begin{document} @@ -16073,15 +16073,15 @@ following text: % \fi % % \begin{macrocode} -\def\markdownRendererMarkedSpan{% - \markdownRendererMarkedSpanPrototype}% +\def\markdownRendererMark{% + \markdownRendererMarkPrototype}% \ExplSyntaxOn \seq_gput_right:Nn \g_@@_renderers_seq - { markedSpan } + { mark } \prop_gput:Nnn \g_@@_renderer_arities_prop - { markedSpan } + { mark } { 1 } \ExplSyntaxOff % \end{macrocode} @@ -29976,7 +29976,7 @@ end % \end{macrocode} % \begin{markdown} % -%#### Marked spans +%#### Marked text % % The \luamdef{extensions.mark} function implements the Pandoc mark syntax % extension. @@ -29992,12 +29992,12 @@ M.extensions.mark = function() % \begin{markdown} % % Define \luamdef{writer->mark} as a function that will transform an input -% marked span `s` to the output format. +% marked text `s` to the output format. % % \end{markdown} % \begin{macrocode} function self.mark(s) - return {"\\markdownRendererMarkedSpan{", s, "}"} + return {"\\markdownRendererMark{", s, "}"} end end, extend_reader = function(self) local parsers = self.parsers @@ -33820,7 +33820,7 @@ end % \par % \begin{markdown} % -%#### Marked Spans +%#### Marked Text % If the \Opt{mark} option is enabled, we will load the \pkg{soulutf8} package % and use it to implement marked text. % @@ -33830,7 +33830,7 @@ end \RequirePackage{soulutf8}% \markdownSetup{ rendererPrototypes = { - markedSpan = {% + mark = {% \hl{#1}% }, } From ecf7c1062e911ef6d3ac5a7fc5a835abe8b722f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:43:52 +0200 Subject: [PATCH 7/9] Fix a typo in the extension name --- markdown.dtx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown.dtx b/markdown.dtx index 5d8f76277..5410914b1 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -31006,7 +31006,7 @@ function M.new(options) local extensions = {} if options.bracketedSpans then - local bracketed_spans_extension = M.extensions.bracketedSpans() + local bracketed_spans_extension = M.extensions.bracketed_spans() table.insert(extensions, bracketed_spans_extension) end From 2445f14e8bd60790a199bf1dbe7a4886ff98d348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:46:59 +0200 Subject: [PATCH 8/9] Unit-test the `mark` Lua option and token renderer (prototype) --- tests/support/keyval-setup.tex | 2 ++ tests/testfiles/lunamark-markdown/mark.test | 13 +++++++++++++ tests/testfiles/lunamark-markdown/no-mark.test | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/testfiles/lunamark-markdown/mark.test create mode 100644 tests/testfiles/lunamark-markdown/no-mark.test diff --git a/tests/support/keyval-setup.tex b/tests/support/keyval-setup.tex index ec75db544..082d88b7a 100644 --- a/tests/support/keyval-setup.tex +++ b/tests/support/keyval-setup.tex @@ -290,6 +290,8 @@ \TYPE{END jekyllDataMappingBegin}}, jekyllDataMappingEnd = {% \TYPE{jekyllDataMappingEnd}}, + mark = {% + \TYPE{mark: #1}}, strikeThrough = {% \TYPE{strikeThrough: #1}}, superscript = {% diff --git a/tests/testfiles/lunamark-markdown/mark.test b/tests/testfiles/lunamark-markdown/mark.test new file mode 100644 index 000000000..a405d0505 --- /dev/null +++ b/tests/testfiles/lunamark-markdown/mark.test @@ -0,0 +1,13 @@ +\markdownSetup{mark=true} +<<< +This test ensures that the Lua `mark` option correctly propagates +through the plain TeX interface. + +Some ==highlighted text== and some \==regular text with equal signs==. +>>> +documentBegin +codeSpan: mark +softLineBreak +paragraphSeparator +mark: highlighted text +documentEnd diff --git a/tests/testfiles/lunamark-markdown/no-mark.test b/tests/testfiles/lunamark-markdown/no-mark.test new file mode 100644 index 000000000..b0c18266e --- /dev/null +++ b/tests/testfiles/lunamark-markdown/no-mark.test @@ -0,0 +1,9 @@ +<<< +This test ensures that the Lua `mark` option is disabled by default. + +Some ==highlighted text== and some \==regular text with equal signs==. +>>> +documentBegin +codeSpan: mark +paragraphSeparator +documentEnd From 781aaf3c57410408bc67114931b367921dca6fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Wed, 27 Sep 2023 14:51:32 +0200 Subject: [PATCH 9/9] Update `CHANGES.md` --- CHANGES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d37ab55e6..3956b4387 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changes -## 3.1.0 +## 3.2.0 + +## 3.1.0 (2023-09-27) Development: