From 4e4b271befb431231ceffe30d6471d22d7dc8a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 5 Jan 2026 19:24:51 +0100 Subject: [PATCH 1/5] Support the prepending (`^=`) and the new appending (`$=`) operators --- markdown.dtx | 105 +++++++++++++++++++++++++++------ tests/support/keyval-setup.tex | 4 +- 2 files changed, 88 insertions(+), 21 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 64f6b0a63..41433a311 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -21729,6 +21729,8 @@ following text: } \tl_new:N \l_@@_renderer_definition_tl +\bool_new:N + \g_@@_prepending_renderer_bool \bool_new:N \g_@@_appending_renderer_bool \bool_new:N @@ -21746,16 +21748,28 @@ following text: { \cP\#0 } { #1 } \l_@@_renderer_definition_tl - \bool_if:NT - \g_@@_appending_renderer_bool + \bool_if:nT + { + \g_@@_prepending_renderer_bool || + \g_@@_appending_renderer_bool + } { \@@_tl_set_from_cs:NNn \l_tmpa_tl #2 { #3 } - \tl_put_left:NV - \l_@@_renderer_definition_tl - \l_tmpa_tl + \bool_if:NTF + \g_@@_prepending_renderer_bool + { + \tl_put_right:NV + \l_@@_renderer_definition_tl + \l_tmpa_tl + } + { + \tl_put_left:NV + \l_@@_renderer_definition_tl + \l_tmpa_tl + } } \bool_if:NTF \g_@@_unprotected_renderer_bool @@ -21888,9 +21902,12 @@ following text: \l_@@_renderer_glob_definition_tl \seq_new:N \l_@@_renderer_glob_results_seq +\regex_const:Nn + \c_@@_prepending_key_regex + { \^$ } \regex_const:Nn \c_@@_appending_key_regex - { \s*+$ } + { [\$\+]$ } \keys_define:nn { markdown/options/renderers } { @@ -21899,14 +21916,15 @@ following text: % \begin{markdown} % % Besides defining renderers at once, we can also define them incrementally -% using the appending operator (`+=`). This can be especially useful in -% defining rules for processing different \acro{HTML} class names and -% identifiers: +% using the prepending (`^=`) and appending (`$=` or `+=`) operators. This +% can be especially useful in defining rules for processing different +% \acro{HTML} class names and identifiers: % ``` tex % \markdownSetup{ % renderers = { % \% Start with empty renderers. -% headerAttributeContextBegin = {}, +% headerAttributeContextBegin = \begingroup, +% headerAttributeContextEnd = \endgroup, % attributeClassName = {}, % attributeIdentifier = {}, % \% Define the processing of a single specific HTML class name. @@ -21932,12 +21950,27 @@ following text: % \end{markdown} % \begin{macrocode} % TODO: Use `\regex_if_match` in TeX Live 2025. + \regex_match:NVTF + \c_@@_prepending_key_regex + \l_keys_key_str + { + \bool_gset_true:N + \g_@@_prepending_renderer_bool + } + % TODO: Use `\regex_if_match` in TeX Live 2025. \regex_match:NVTF \c_@@_appending_key_regex \l_keys_key_str { \bool_gset_true:N \g_@@_appending_renderer_bool + } + \bool_if:nTF + { + \g_@@_prepending_renderer_bool || + \g_@@_appending_renderer_bool + } + { \tl_set:NV \l_tmpa_tl \l_keys_key_str @@ -21954,6 +21987,8 @@ following text: \keys_set:nV { markdown/options/renderers } \l_tmpb_tl + \bool_gset_false:N + \g_@@_prepending_renderer_bool \bool_gset_false:N \g_@@_appending_renderer_bool } @@ -22568,6 +22603,8 @@ following text: } \tl_new:N \l_@@_renderer_prototype_definition_tl +\bool_new:N + \g_@@_prepending_renderer_prototype_bool \bool_new:N \g_@@_appending_renderer_prototype_bool \bool_new:N @@ -22585,16 +22622,28 @@ following text: { \cP\#0 } { #1 } \l_@@_renderer_prototype_definition_tl - \bool_if:NT - \g_@@_appending_renderer_prototype_bool + \bool_if:nT + { + \g_@@_prepending_renderer_prototype_bool || + \g_@@_appending_renderer_prototype_bool + } { \@@_tl_set_from_cs:NNn \l_tmpa_tl #2 { #3 } - \tl_put_left:NV - \l_@@_renderer_prototype_definition_tl - \l_tmpa_tl + \bool_if:NTF + \g_@@_prepending_renderer_prototype_bool + { + \tl_put_right:NV + \l_@@_renderer_prototype_definition_tl + \l_tmpa_tl + } + { + \tl_put_left:NV + \l_@@_renderer_prototype_definition_tl + \l_tmpa_tl + } } \bool_if:NTF \g_@@_unprotected_renderer_prototype_bool @@ -22670,14 +22719,15 @@ following text: % \begin{markdown} % % Besides defining renderer prototypes at once, we can also define them -% incrementally using the appending operator (`+=`). This can be especially -% useful in defining rules for processing different \acro{HTML} class names -% and identifiers: +% incrementally using the prepending (`^=`) and appending (`$=` or `+=`) +% operators. This can be especially useful in defining rules for processing +% different \acro{HTML} class names and identifiers: % ``` tex % \markdownSetup{ % rendererPrototypes = { % \% Start with empty renderer prototypes. -% headerAttributeContextBegin = {}, +% headerAttributeContextBegin = \begingroup, +% headerAttributeContextEnd = \endgroup, % attributeClassName = {}, % attributeIdentifier = {}, % \% Define the processing of a single specific HTML class name. @@ -22703,12 +22753,27 @@ following text: % \end{markdown} % \begin{macrocode} % TODO: Use `\regex_if_match` in TeX Live 2025. + \regex_match:NVTF + \c_@@_prepending_key_regex + \l_keys_key_str + { + \bool_gset_true:N + \g_@@_prepending_renderer_prototype_bool + } + % TODO: Use `\regex_if_match` in TeX Live 2025. \regex_match:NVTF \c_@@_appending_key_regex \l_keys_key_str { \bool_gset_true:N \g_@@_appending_renderer_prototype_bool + } + \bool_if:nTF + { + \g_@@_prepending_renderer_prototype_bool || + \g_@@_appending_renderer_prototype_bool + } + { \tl_set:NV \l_tmpa_tl \l_keys_key_str @@ -22725,6 +22790,8 @@ following text: \keys_set:nV { markdown/options/renderer-prototypes } \l_tmpb_tl + \bool_gset_false:N + \g_@@_prepending_renderer_prototype_bool \bool_gset_false:N \g_@@_appending_renderer_prototype_bool } diff --git a/tests/support/keyval-setup.tex b/tests/support/keyval-setup.tex index b6784819e..c4b1de785 100644 --- a/tests/support/keyval-setup.tex +++ b/tests/support/keyval-setup.tex @@ -188,8 +188,8 @@ \TYPE{END rawBlock}}, replacementCharacter = {% \TYPE{#0}}, - *AttributeContextEnd += {\GOBBLE}, - *(Separator|LineBreak) += {\GOBBLE}, + *AttributeContextEnd ^= {\GOBBLE}, + *(Separator|LineBreak) $= {\GOBBLE}, (ellipsis|nbsp|*Brace|*Sign|ampersand|underscore|hash|circumflex|backslash|tilde|pipe|replacementCharacter) += {\GOBBLE}, (ticked|halfTicked|unticked)Box += {\GOBBLE}, warning|error = {% From 118638da92b2003ebde9799562cc9af42ff79520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 5 Jan 2026 19:28:41 +0100 Subject: [PATCH 2/5] Update `CHANGES.md` --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6d2937bfb..0eb1066d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,13 @@ # Changes +## 3.14.0 (2026-01-XX) + +Development: + +- Support the new prepending (`^=`) and the appending (`$=`) operators for + renderers and renderer prototypes. (proposed by @witiko in #232, added by + @witiko in #617) + ## 3.13.0 (2026-01-02) Fixes: From 70ac12d393ac01f2c477cb6011c774ac31058f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 5 Jan 2026 22:27:00 +0100 Subject: [PATCH 3/5] Fix various typos --- markdown.dtx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 41433a311..4ca26e54d 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -21907,7 +21907,10 @@ following text: { \^$ } \regex_const:Nn \c_@@_appending_key_regex - { [\$\+]$ } + { [\$+]$ } +\regex_const:Nn + \c_@@_prepending_or_appending_key_regex + { [\^\$+]$ } \keys_define:nn { markdown/options/renderers } { @@ -21950,7 +21953,7 @@ following text: % \end{markdown} % \begin{macrocode} % TODO: Use `\regex_if_match` in TeX Live 2025. - \regex_match:NVTF + \regex_match:NVT \c_@@_prepending_key_regex \l_keys_key_str { @@ -21958,7 +21961,7 @@ following text: \g_@@_prepending_renderer_bool } % TODO: Use `\regex_if_match` in TeX Live 2025. - \regex_match:NVTF + \regex_match:NVT \c_@@_appending_key_regex \l_keys_key_str { @@ -21975,7 +21978,7 @@ following text: \l_tmpa_tl \l_keys_key_str \regex_replace_once:NnN - \c_@@_appending_key_regex + \c_@@_prepending_or_appending_key_regex { } \l_tmpa_tl \tl_set:Nx @@ -22082,7 +22085,7 @@ following text: % TODO: Use `\regex_if_match` in TeX Live 2025. \regex_match:Nn % noqa: w202 { NV } - { TF } + { T } \prop_new:N \g_@@_glob_cache_prop \tl_new:N @@ -22753,7 +22756,7 @@ following text: % \end{markdown} % \begin{macrocode} % TODO: Use `\regex_if_match` in TeX Live 2025. - \regex_match:NVTF + \regex_match:NVT \c_@@_prepending_key_regex \l_keys_key_str { @@ -22761,7 +22764,7 @@ following text: \g_@@_prepending_renderer_prototype_bool } % TODO: Use `\regex_if_match` in TeX Live 2025. - \regex_match:NVTF + \regex_match:NVT \c_@@_appending_key_regex \l_keys_key_str { @@ -22778,7 +22781,7 @@ following text: \l_tmpa_tl \l_keys_key_str \regex_replace_once:NnN - \c_@@_appending_key_regex + \c_@@_prepending_or_appending_key_regex { } \l_tmpa_tl \tl_set:Nx From ad7d6c138ac8073bebc6a9b4b32513c738030643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 5 Jan 2026 23:13:44 +0100 Subject: [PATCH 4/5] Correctly nest --- markdown.dtx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 4ca26e54d..326d966db 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -21968,11 +21968,10 @@ following text: \bool_gset_true:N \g_@@_appending_renderer_bool } - \bool_if:nTF - { - \g_@@_prepending_renderer_bool || - \g_@@_appending_renderer_bool - } + % TODO: Use `\regex_if_match` in TeX Live 2025. + \regex_match:NVTF + \c_@@_prepending_or_appending_key_regex + \l_keys_key_str { \tl_set:NV \l_tmpa_tl @@ -22085,7 +22084,7 @@ following text: % TODO: Use `\regex_if_match` in TeX Live 2025. \regex_match:Nn % noqa: w202 { NV } - { T } + { T, TF } \prop_new:N \g_@@_glob_cache_prop \tl_new:N @@ -22771,11 +22770,10 @@ following text: \bool_gset_true:N \g_@@_appending_renderer_prototype_bool } - \bool_if:nTF - { - \g_@@_prepending_renderer_prototype_bool || - \g_@@_appending_renderer_prototype_bool - } + % TODO: Use `\regex_if_match` in TeX Live 2025. + \regex_match:NVTF + \c_@@_prepending_or_appending_key_regex + \l_keys_key_str { \tl_set:NV \l_tmpa_tl From 5bc6ab5bee7cd0800b9fe5488bc683a35d89a0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 5 Jan 2026 23:32:09 +0100 Subject: [PATCH 5/5] Fix uses of prepending operator in `keyval-setup.tex` --- tests/support/keyval-setup.tex | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/support/keyval-setup.tex b/tests/support/keyval-setup.tex index c4b1de785..1c2e10888 100644 --- a/tests/support/keyval-setup.tex +++ b/tests/support/keyval-setup.tex @@ -81,10 +81,14 @@ codeSpan = {% \TYPE{#0: #1}}, (link|image) = {% - \TYPE{BEGIN #0}% - \TYPE{- label: #1}% - \TYPE{- URI: #3}% - \TYPE{- title: #4}% + \TYPE{- URI: #3}}, + (link|image) ^= {% + \TYPE{- label: #1}}, + (link|image) ^= {% + \TYPE{BEGIN #0}}, + (link|image) $= {% + \TYPE{- title: #4}}, + (link|image) $= {% \TYPE{END #0}}, contentBlock(|OnlineImage) = {% \TYPE{BEGIN #0}% @@ -188,8 +192,8 @@ \TYPE{END rawBlock}}, replacementCharacter = {% \TYPE{#0}}, - *AttributeContextEnd ^= {\GOBBLE}, - *(Separator|LineBreak) $= {\GOBBLE}, + *AttributeContextEnd += {\GOBBLE}, + *(Separator|LineBreak) += {\GOBBLE}, (ellipsis|nbsp|*Brace|*Sign|ampersand|underscore|hash|circumflex|backslash|tilde|pipe|replacementCharacter) += {\GOBBLE}, (ticked|halfTicked|unticked)Box += {\GOBBLE}, warning|error = {%