diff options
Diffstat (limited to 'Master/texmf-dist/source/generic/markdown/markdown.dtx')
-rw-r--r-- | Master/texmf-dist/source/generic/markdown/markdown.dtx | 6934 |
1 files changed, 4807 insertions, 2127 deletions
diff --git a/Master/texmf-dist/source/generic/markdown/markdown.dtx b/Master/texmf-dist/source/generic/markdown/markdown.dtx index 6ad42a46b26..8fc4867b436 100644 --- a/Master/texmf-dist/source/generic/markdown/markdown.dtx +++ b/Master/texmf-dist/source/generic/markdown/markdown.dtx @@ -78,10 +78,9 @@ \usepackage[ citations, definitionLists, - fencedCode, + experimental, notes, headerAttributes, - html, hybrid, inlineNotes, jekyllData, @@ -122,7 +121,7 @@ --- title: A Markdown Interpreter for \TeX url: https://github.com/witiko/markdown -authors: [Vít Starý Novotný] +authors: [Vít Starý Novotný, Andrej Genčur] email: witiko@mail.muni.cz revision: \markdownVersion date: \markdownLastModified @@ -684,118 +683,138 @@ abbr { %</techdoc-block-diagram> %<*techdoc-bibliography> @online{starynovotny24, - author = {Starý Novotný, Vít and Enrico Gregorio and Max Chernoff and P. Spratte, Jonathan}, - title = {Convert control sequence with a variable number of undelimited parameters into a token list}, - url = {https://tex.stackexchange.com/q/716362/70941}, - urldate = {2024-04-28}, + author = {Starý Novotný, Vít and Enrico Gregorio and Max Chernoff and P. Spratte, Jonathan}, + title = {Convert control sequence with a variable number of undelimited parameters into a token list}, + url = {https://tex.stackexchange.com/q/716362/70941}, + urldate = {2024-04-28}, } @book{tantau21, - author = {Till Tantau and Joseph Wright and Vedran Miletić}, - title = {The Beamer class}, - date = {2021-02-10}, - url = {https://mirrors.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf}, - urldate = {2021-02-11}} + author = {Till Tantau and Joseph Wright and Vedran Miletić}, + title = {The Beamer class}, + date = {2021-02-10}, + url = {https://mirrors.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf}, + urldate = {2021-02-11}} @online{sotkov17, - author = {Sotkov, Anton}, - title = {File transclusion syntax for Markdown}, - date = {2017-01-19}, - url = {https://github.com/iainc/Markdown-Content-Blocks}, - urldate = {2018-01-08}} + author = {Sotkov, Anton}, + title = {File transclusion syntax for Markdown}, + date = {2017-01-19}, + url = {https://github.com/iainc/Markdown-Content-Blocks}, + urldate = {2018-01-08}} @book{luatex21, - author = {{Lua\TeX{} development team}}, - title = {Lua\TeX{} reference manual}, - date = {2021-07-23}, - note = {Version 1.10 (stable)}, - url = {https://www.pragma-ade.com/general/manuals/luatex.pdf}, - urldate = {2022-09-30}} + author = {{Lua\TeX{} development team}}, + title = {Lua\TeX{} reference manual}, + date = {2021-07-23}, + note = {Version 1.10 (stable)}, + url = {https://www.pragma-ade.com/general/manuals/luatex.pdf}, + urldate = {2022-09-30}} @book{latex17, - author = {Braams, Johannes and Carlisle, David and Jeffrey, Alan and + author = {Braams, Johannes and Carlisle, David and Jeffrey, Alan and Lamport, Leslie and Mittelbach, Frank and Rowley, Chris and Schöpf, Rainer}, - title = {The \Hologo{LaTeX2e} Sources}, - date = {2017-04-15}, - url = {https://mirrors.ctan.org/macros/latex/base/source2e.pdf}, - urldate = {2018-01-08}} + title = {The \Hologo{LaTeX2e} Sources}, + date = {2017-04-15}, + url = {https://mirrors.ctan.org/macros/latex/base/source2e.pdf}, + urldate = {2018-01-08}} @book{mittelbach17, - author = {Mittelbach, Frank}, - title = {The \texttt{doc} and \texttt{shortvrb} Packages}, - date = {2017-04-15}, - url = {https://mirrors.ctan.org/macros/latex/base/doc.pdf}, - urldate = {2018-02-19}} + author = {Mittelbach, Frank}, + title = {The \texttt{doc} and \texttt{shortvrb} Packages}, + date = {2017-04-15}, + url = {https://mirrors.ctan.org/macros/latex/base/doc.pdf}, + urldate = {2018-02-19}} +@book{mittelbach24, + author = {Mittelbach, Frank}, + title = {\LaTeX's hook management}, + date = {2024-06-26}, + url = {https://mirrors.ctan.org/macros/latex/base/lthooks-code.pdf}, + urldate = {2024-10-02}} @book{poore17, - author = {Poore, Geoffrey M.}, - title = {The \texttt{minted} Package}, - subtitle = {Highlighted source code in \LaTeX}, - date = {2017-07-19}, - version = {v2.5}, - url = {https://mirrors.ctan.org/macros/latex/contrib/minted/minted.pdf}, - urldate = {2020-09-01}} + author = {Poore, Geoffrey M.}, + title = {The \texttt{minted} Package}, + subtitle = {Highlighted source code in \LaTeX}, + date = {2017-07-19}, + version = {v2.5}, + url = {https://mirrors.ctan.org/macros/latex/contrib/minted/minted.pdf}, + urldate = {2020-09-01}} @online{macfarlane22, - title = {Pandoc}, - subtitle = {a universal document converter}, - author = {John MacFarlane}, - year = {2022}, - url = {https://pandoc.org/}, - urldate = {2022-10-05}} + title = {Pandoc}, + subtitle = {a universal document converter}, + author = {John MacFarlane}, + year = {2022}, + url = {https://pandoc.org/}, + urldate = {2022-10-05}} @online{novotny15, - author = {Novotný, Vít}, - year = {2015}, - title = {TeXový interpret jazyka Markdown (markdown.sty)}, - location = {Brno, Czech Republic}, - publisher = {Masaryk University}, - url = {https://www.muni.cz/en/research/projects/32984}, - urldate = {2018-02-19}} + author = {Novotný, Vít}, + year = {2015}, + title = {TeXový interpret jazyka Markdown (markdown.sty)}, + location = {Brno, Czech Republic}, + publisher = {Masaryk University}, + url = {https://www.muni.cz/en/research/projects/32984}, + urldate = {2018-02-19}} @book{ierusalimschy13, - author = {Ierusalimschy, Roberto}, - year = {2013}, - title = {Programming in Lua}, - edition = {3}, - isbn = {978-85-903798-5-0}, - pagetotal = {xviii, 347}, - location = {Rio de Janeiro}, - publisher = {PUC-Rio}} + author = {Ierusalimschy, Roberto}, + year = {2013}, + title = {Programming in Lua}, + edition = {3}, + isbn = {978-85-903798-5-0}, + pagetotal = {xviii, 347}, + location = {Rio de Janeiro}, + publisher = {PUC-Rio}} @book{knuth86a, - author = {Knuth, Donald Ervin}, - year = {1986}, - title = {The \TeX{}book}, - edition = {3}, - isbn = {0-201-13447-0}, - pagetotal = {ix, 479}, - series = {Computers \& Typesetting}, - volume = {A}, - location = {Reading, MA}, - publisher = {Addison-Wesley}} + author = {Knuth, Donald Ervin}, + year = {1986}, + title = {The \TeX{}book}, + edition = {3}, + isbn = {0-201-13447-0}, + pagetotal = {ix, 479}, + series = {Computers \& Typesetting}, + volume = {A}, + location = {Reading, MA}, + publisher = {Addison-Wesley}} @book{knuth86b, - author = {Knuth, Donald Ervin}, - year = {1986}, - title = {\TeX: The Program}, - isbn = {978-0-201-13437-7}, - pagetotal = {xvi, 594}, - series = {Computers \& Typesetting}, - volume = {B}, - location = {Reading, MA}, - publisher = {Addison-Wesley}} + author = {Knuth, Donald Ervin}, + year = {1986}, + title = {\TeX: The Program}, + isbn = {978-0-201-13437-7}, + pagetotal = {xvi, 594}, + series = {Computers \& Typesetting}, + volume = {B}, + location = {Reading, MA}, + publisher = {Addison-Wesley}} @book{eijkhout92, - author = {Victor Eijkhout}, - title = {\TeX{} by Topic}, - subtitle = {A \TeX nician's Reference}, - isbn = {978-0-201-56882-0}, - pagetotal = {307}, - date = {1992-02-01}, - location = {Wokingham, England}, - publisher = {Addison-Wesley}} + author = {Victor Eijkhout}, + title = {\TeX{} by Topic}, + subtitle = {A \TeX nician's Reference}, + isbn = {978-0-201-56882-0}, + pagetotal = {307}, + date = {1992-02-01}, + location = {Wokingham, England}, + publisher = {Addison-Wesley}} @inproceedings{sharif10, - author = {Sharif, Bonita and Maletic, Jonathan I.}, - booktitle = {2010 IEEE 18th International Conference on Program Comprehension}, - title = {An Eye Tracking Study on camelCase and under\_score Identifier Styles}, - year = {2010}, - pages = {196-205}, - doi = {10.1109/ICPC.2010.41}} + author = {Sharif, Bonita and Maletic, Jonathan I.}, + booktitle = {2010 IEEE 18th International Conference on Program Comprehension}, + title = {An Eye Tracking Study on camelCase and under\_score Identifier Styles}, + year = {2010}, + pages = {196-205}, + doi = {10.1109/ICPC.2010.41}} +@online{novotny24, + author = {Starý Novotný, Vít}, + title = {Versioned Themes}, + titleaddon = {Markdown Enhancement Proposal}, + date = {2024-10-13}, + urldate = {2024-10-21}, + url = {https://github.com/Witiko/markdown/discussions/514}} +@book{latex24, + author = {Frank Mittelbach and Ulrike Fischer and {\LaTeX{} Project}}, + title = {The \texttt{documentmetadata-support} code}, + date = {2024-06-01}, + url = {https://mirrors.ctan.org/macros/latex/required/latex-lab/documentmetadata-support-code.pdf}, + urldate = {2024-10-21}} %</techdoc-bibliography> %<@@=markdown> %<*themes-witiko-markdown-techdoc> \ProvidesPackage{markdownthemewitiko_markdown_techdoc}[2022/12/13] \RequirePackage{etoolbox} +\gdef\ltd@title@author{\@gobble}% \markdownSetup{ renderers = { head*Four = {\paragraph{#1}\leavevmode}, @@ -804,16 +823,20 @@ abbr { codeSpan = {\inline{#1}}, jekyllData(End) = {% \AfterEndPreamble{% + \hypersetup{pdfauthor=\ltd@title@author}% \printtitlepage \tableofcontents {\def\addcontentsline##1##2##3{}\listoffigures}% }% }, }, +} +\yamlSetup{ jekyllDataRenderers = { /authors/* = {% - \gdef\ltd@title@author{#1}% - \hypersetup{pdfauthor={#1}}% + \expandafter\gdef + \expandafter\ltd@title@author + \expandafter{\ltd@title@author, #1}% }, title = {% \gdef\ltd@title@title{#1}% @@ -875,7 +898,7 @@ abbr { --- title: Markdown Package User Manual -author: Vít Starý Novotný +author: Vít Starý Novotný, Andrej Genčur date: \markdownVersion{} \markdownLastModified{} --- @@ -890,7 +913,7 @@ Introduction The [Markdown package][pkg] converts [CommonMark][] markup to \TeX{} commands. The functionality is provided both as a Lua module and as plain \TeX{}, \LaTeX{}, and \Hologo{ConTeXt} macro packages that can be used to directly typeset \TeX{} documents -containing markdown markup. Unlike other convertors, the Markdown package +containing markdown markup. Unlike other converters, the Markdown package does not require any external programs, and makes it easy to redefine how each and every markdown element is rendered. Creative abuse of the markdown syntax is encouraged. 😉 @@ -922,21 +945,23 @@ documentation][techdoc]. (A Markdown Interpreter for TeX) %</manual> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader,lua-unicode-data> % \fi % \begin{macrocode} local metadata = { version = "(((VERSION)))", - comment = "A module for the conversion from markdown to plain TeX", - author = "John MacFarlane, Hans Hagen, Vít Starý Novotný", + comment = "A module for the conversion from markdown " + .. "to plain TeX", + author = "John MacFarlane, Hans Hagen, Vít Starý Novotný, " + .. "Andrej Genčur", copyright = {"2009-2016 John MacFarlane, Hans Hagen", - "2016-2023 Vít Starý Novotný"}, + "2016-2024 Vít Starý Novotný, Andrej Genčur"}, license = "LPPL 1.3c" } % \end{macrocode} % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader,lua-unicode-data> %<*lua> % \fi % \begin{macrocode} @@ -965,22 +990,30 @@ requirements. Installation ------------ -If Markdown is not included in your \TeX{} distribution, you will need to -install it. +If the Markdown package is not included in your \TeX{} distribution, you will +need to install it. + +From [Releases][], download [an archive `markdown.zip` for this version of the +Markdown package (\markdownShortVersion{})][this-release] or a different version +that you wish to install. Then, unzip the archive. If you downloaded an archive +for a different version of the Markdown package, you should now locate a file +named `markdown.html` with the user manual for that version, open it, and +follow the installation steps in it rather than the steps from this manual. -First, download the package from the repository using Git: + [releases]: https://github.com/witiko/markdown/releases (Releases - witiko/markdown) + [this-release]: https://github.com/witiko/markdown/releases/download/\markdownShortVersion{}/markdown.zip (Release \markdownShortVersion{} - witiko/markdown) + +Alternatively, download the package from the repository using Git, enter the +directory named `markdown` and run the `make base` command using GNU Make: ``` sh git clone https://github.com/witiko/markdown -`````` -Next, enter the directory named `markdown` and run the `make base` command using -GNU Make: -``` sh cd markdown make base `````` -This should produce the following files: -* `markdown.lua`: The Lua module +Either of the two abovelisted approaches should produce the following files: + +* `markdown.lua`, `markdown-parser.lua`, and `markdown-unicode-data.lua`: The Lua module * `libraries/markdown-tinyyaml.lua`: An external library for reading \acro{yaml} * `markdown-cli.lua`: The Lua command-line interface * `markdown.tex`: The plain \TeX{} macro package @@ -1001,6 +1034,8 @@ directory structure. This is generally where the individual files should be placed: * `⟨TEXMF⟩/tex/luatex/markdown/markdown.lua` +* `⟨TEXMF⟩/tex/luatex/markdown/markdown-parser.lua` +* `⟨TEXMF⟩/tex/luatex/markdown/markdown-unicode-data.lua` * `⟨TEXMF⟩/tex/luatex/markdown/markdown-tinyyaml.lua` * `⟨TEXMF⟩/scripts/markdown/markdown-cli.lua` * `⟨TEXMF⟩/tex/generic/markdown/markdown.tex` @@ -1027,6 +1062,8 @@ portably typeset on legacy \TeX{} distributions. This is where the individual files should be placed: * `./markdown.lua` +* `./markdown-parser.lua` +* `./markdown-unicode-data.lua` * `./markdown-tinyyaml.lua` * `./markdown-cli.lua` * `./markdown/markdown.tex` @@ -1039,6 +1076,8 @@ This is where the individual files should be placed: * `./markdownthemewitiko_markdown_defaults.sty` * `./t-markdownthemewitiko_markdown_defaults.tex` +The file `markdown.tex` *must* be placed in a directory named `markdown`. + %</manual> %<*lua> % \fi @@ -1065,6 +1104,10 @@ This is where the individual files should be placed: % Live${}\geq{}2013$). % % \end{markdown} +% \iffalse +%</lua> +%<*lua,lua-unicode-data> +% \fi % \begin{macrocode} local lpeg = require("lpeg") % \end{macrocode} @@ -1079,6 +1122,10 @@ local lpeg = require("lpeg") % Lua\TeX{} (\TeX Live${}\geq{}2008$). % % \end{markdown} +% \iffalse +%</lua,lua-unicode-data> +%<*lua,lua-unicode-data-generator> +% \fi % \begin{macrocode} local unicode = require("unicode") % \end{macrocode} @@ -1093,9 +1140,17 @@ local unicode = require("unicode") % Live${}\geq{}2008$). % % \end{markdown} +% \iffalse +%</lua,lua-unicode-data-generator> +%<*lua,lua-loader> +% \fi % \begin{macrocode} -local md5 = require("md5"); +local md5 = require("md5") % \end{macrocode} +% \iffalse +%</lua,lua-loader> +%<*lua,lua-unicode-data-generator> +% \fi % \begin{markdown} % % \pkg{Kpathsea} @@ -1105,7 +1160,7 @@ local md5 = require("md5"); % % \end{markdown} % \begin{macrocode} -(function() +;(function() % \end{macrocode} % \begin{markdown} % @@ -1138,6 +1193,17 @@ end)() %: A package that implements Unicode case-folding in \TeX{} Live${}\geq{}2020$. % % \end{markdown} +% \iffalse +%</lua,lua-unicode-data-generator> +%<*depends> +% \fi +% \begin{macrocode} +hard lua-uni-algos +% \end{macrocode} +% \iffalse +%</depends> +%<*lua> +% \fi % \begin{macrocode} local uni_algos = require("lua-uni-algos") % \end{macrocode} @@ -1156,6 +1222,13 @@ local uni_algos = require("lua-uni-algos") % \end{markdown} % \iffalse %</lua> +%<*depends> +% \fi +% \begin{macrocode} +# hard lua-tinyyaml # TODO: Uncomment after TeX Live 2022 deprecation. +% \end{macrocode} +% \iffalse +%</depends> %<*tex> % \fi % \par @@ -1175,18 +1248,33 @@ local uni_algos = require("lua-uni-algos") % such as options, renderers, and renderer prototypes. % % \end{markdown} -% \begin{macrocode} +% \iffalse %</tex> +%<*depends> +% \fi +% \begin{macrocode} +hard l3kernel +% \end{macrocode} +% \iffalse +%</depends> %<*context> +% \fi +% \begin{macrocode} \unprotect +% \end{macrocode} +% \iffalse %</context> %<*context,tex> +% \fi +% \begin{macrocode} \ifx\ExplSyntaxOn\undefined \input expl3-generic \fi +% \end{macrocode} +% \iffalse %</context,tex> %<*tex> -% \end{macrocode} +% \fi % \begin{markdown} % % \pkg{lt3luabridge} @@ -1195,6 +1283,20 @@ local uni_algos = require("lua-uni-algos") % with other TeX engines that provide the *shell escape* capability, % which allows them to execute code with the system's shell. % +% \end{markdown} +% \iffalse +%</tex> +%<*depends> +% \fi +% \begin{macrocode} +hard lt3luabridge +% \end{macrocode} +% \iffalse +%</depends> +%<*tex> +% \fi +% \begin{markdown} +% % The plain \TeX{} part of the package also requires the following Lua module: % % \pkg{Lua File System} @@ -1233,20 +1335,22 @@ local uni_algos = require("lua-uni-algos") %### \LaTeX{} Requirements {#latex-prerequisites} % % The \LaTeX{} part of the package requires that the \Hologo{LaTeX2e} format is -% loaded, +% loaded, a \TeX{} engine that extends \Hologo{eTeX}, and all the plain \TeX{} +% prerequisites (see Section <#sec:tex-prerequisites>). % \end{markdown} % \iffalse %<*themes-witiko-dot,latex-themes-witiko-graphicx-http> % \fi % \begin{macrocode} -\NeedsTeXFormat{LaTeX2e}% +\NeedsTeXFormat{LaTeX2e} +\RequirePackage{expl3} % \end{macrocode} % \iffalse %</themes-witiko-dot,latex-themes-witiko-graphicx-http> +%</latex> +%<*depends> % \fi % \begin{markdown} -% a \TeX{} engine that extends \Hologo{eTeX}, and all the plain \TeX{} -% prerequisites (see Section <#sec:tex-prerequisites>): % % The following packages are soft prerequisites. They are only used to provide % default token renderer prototypes (see sections @@ -1259,17 +1363,41 @@ local uni_algos = require("lua-uni-algos") % %: A package that provides the `\url` macro for the typesetting of links. % +% \end{markdown} +% \begin{macrocode} +soft url +% \end{macrocode} +% \begin{markdown} +% % \pkg{graphicx} % %: A package that provides the `\includegraphics` macro for the typesetting -% of images. +% of images. Furthermore, it also provides a key-value interface that is +% used in the default renderer prototypes for image attribute contexts. +% +% \end{markdown} +% \begin{macrocode} +soft graphics +% \end{macrocode} +% \begin{markdown} % -% \pkg{paralist} +% \pkg{enumitem} and \pkg{paralist} % -%: A package that provides the `compactitem`, `compactenum`, and -% `compactdesc` macros for the typesetting of tight bulleted lists, -% ordered lists, and definition lists as well as the rendering of -% fancy lists. +%: Packages that provide macros for the default renderer prototypes for +% tight and fancy lists. +% +% The package \pkg{paralist} will be used unless the option +% \Opt{experimental} has been enabled, in which case, the package +% \pkg{enumitem} will be used. Furthermore, enabling any test phase +% [@latex24] will also cause \pkg{enumitem} to be used. In a future +% major version, \pkg{enumitem} will replace \pkg{paralist} altogether. +% +% \end{markdown} +% \begin{macrocode} +soft enumitem +soft paralist +% \end{macrocode} +% \begin{markdown} % % \pkg{ifthen} % @@ -1277,39 +1405,73 @@ local uni_algos = require("lua-uni-algos") % values. It is used in the `witiko/dot` \LaTeX{} theme (see Section % <#sec:latexthemes>). % +% \end{markdown} +% \begin{macrocode} +soft latex +soft epstopdf-pkg # required by `latex` +% \end{macrocode} +% \begin{markdown} +% % \pkg{fancyvrb} % %: A package that provides the `\VerbatimInput` macros for the verbatim % inclusion of files containing code. % +% \end{markdown} +% \begin{macrocode} +soft fancyvrb +% \end{macrocode} +% \begin{markdown} +% % \pkg{csvsimple} % %: A package that provides the `\csvautotabular` macro for typesetting % \acro{csv} files in the default renderer prototypes for iA\\,Writer % content blocks. % +% \end{markdown} +% \begin{macrocode} +soft csvsimple +soft pgf # required by `csvsimple`, which loads `pgfkeys.sty` +soft tools # required by `csvsimple`, which loads `shellesc.sty` +% \end{macrocode} +% \begin{markdown} +% % \pkg{gobble} % %: A package that provides the `\@gobblethree` \TeX{} command that % is used in the default renderer prototype for citations. The package % is included in \TeX Live${}\geq{}2016$. % +% \end{markdown} +% \begin{macrocode} +soft gobble +% \end{macrocode} +% \begin{markdown} +% % \pkg{amsmath} and \pkg{amssymb} % %: Packages that provide symbols used for drawing ticked and unticked % boxes. % +% \end{markdown} +% \begin{macrocode} +soft amsmath +soft amsfonts +% \end{macrocode} +% \begin{markdown} +% % \pkg{catchfile} % %: A package that catches the contents of a file and puts it in a macro. It % is used in the `witiko/graphicx/http` \LaTeX{} theme, see Section % <#sec:latexthemes>. % -% \pkg{graphicx} -% -%: A package that builds upon the \pkg{graphics} package, which is part of -% the \LaTeXe{} kernel. It provides a key-value interface that is used in -% the default renderer prototypes for image attribute contexts. +% \end{markdown} +% \begin{macrocode} +soft catchfile +% \end{macrocode} +% \begin{markdown} % % \pkg{grffile} % @@ -1320,6 +1482,12 @@ local uni_algos = require("lua-uni-algos") % the `witiko/dot` and `witiko/graphicx/http` \LaTeX{} themes, see Section % <#sec:latexthemes>. % +% \end{markdown} +% \begin{macrocode} +soft grffile +% \end{macrocode} +% \begin{markdown} +% % \pkg{etoolbox} % %: A package that is used to polyfill the general hook management system in @@ -1327,10 +1495,36 @@ local uni_algos = require("lua-uni-algos") % <#sec:latex-yaml-metadata>, and also in the default renderer prototype % for identifier attributes. % -% \pkg{soulutf8} +% \end{markdown} +% \begin{macrocode} +soft etoolbox +% \end{macrocode} +% \begin{markdown} +% +% \pkg{soulutf8} and \pkg{xcolor} % -%: A package that is used in the default renderer prototype for -% strike-throughs and marked text. +%: Packages that are used in the default renderer prototypes for +% strike-throughs and marked text in pdf\TeX. +% <!-- TODO: 1,$s/soulutf8/soul/g in TeX Live 2023. --> +% +% \end{markdown} +% \begin{macrocode} +soft soul +soft xcolor +% \end{macrocode} +% \begin{markdown} +% +% \pkg{lua-ul} and \pkg{luacolor} +% +%: Packages that are used in the default renderer prototypes for +% strike-throughs and marked text in Lua\TeX. +% +% \end{markdown} +% \begin{macrocode} +soft lua-ul +soft luacolor +% \end{macrocode} +% \begin{markdown} % % \pkg{ltxcmds} % @@ -1338,6 +1532,12 @@ local uni_algos = require("lua-uni-algos") % \pkg{listings} packages are loaded in the default renderer prototype % for fenced code blocks. % +% \end{markdown} +% \begin{macrocode} +soft ltxcmds +% \end{macrocode} +% \begin{markdown} +% % \pkg{verse} % %: A package that is used in the default renderer prototypes for @@ -1345,10 +1545,13 @@ local uni_algos = require("lua-uni-algos") % % \end{markdown} % \begin{macrocode} -\RequirePackage{expl3} +soft verse % \end{macrocode} +% \begin{markdown} +% +% \end{markdown} % \iffalse -%</latex> +%</depends> %<*context> % \fi % \par @@ -1691,9 +1894,6 @@ In this section, I will describe the individual parts of the Markdown package. Each part will be shown by example, leaving the implementation details to the [technical documentation][techdoc]. - [techdoc]: https://mirrors.ctan.org/macros/generic/markdown/markdown.pdf - (A Markdown Interpreter for \TeX{}) - /markdown-interfaces.md /markdown-options.md /markdown-tokens.md @@ -1732,7 +1932,7 @@ module and a command-line interface (CLI). (Lua library for conversion between markup formats) %</manual-interfaces> -%<*lua> +%<*lua,lua-loader,lua-unicode-data> % \fi % \begin{markdown} % @@ -1747,6 +1947,10 @@ module and a command-line interface (CLI). % \begin{macrocode} local M = {metadata = metadata} % \end{macrocode} +% \iffalse +%</lua,lua-loader,lua-unicode-data> +%<*lua> +% \fi % \par % \begin{markdown} % @@ -2023,7 +2227,7 @@ In this section, I will describe all the options recognized by the Markdown package. %</manual-options> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} local defaultOptions = {} @@ -2032,7 +2236,7 @@ local defaultOptions = {} % \markdownSetup{snippet=lua-options} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> ### Lua @@ -2066,7 +2270,9 @@ interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces. \prop_new:N \g_@@_default_lua_options_prop \seq_new:N \g_@@_option_layers_seq \tl_const:Nn \c_@@_option_layer_lua_tl { lua } -\seq_gput_right:NV \g_@@_option_layers_seq \c_@@_option_layer_lua_tl +\seq_gput_right:NV + \g_@@_option_layers_seq + \c_@@_option_layer_lua_tl \cs_new:Nn \@@_add_lua_option:nnn { @@ -2143,21 +2349,50 @@ interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces. \cs_generate_variant:Nn \msg_error:nnnn { nnnV } -\seq_new:N \g_@@_option_types_seq -\tl_const:Nn \c_@@_option_type_clist_tl { clist } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_clist_tl -\tl_const:Nn \c_@@_option_type_counter_tl { counter } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_counter_tl -\tl_const:Nn \c_@@_option_type_boolean_tl { boolean } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_boolean_tl -\tl_const:Nn \c_@@_option_type_number_tl { number } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_number_tl -\tl_const:Nn \c_@@_option_type_path_tl { path } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_path_tl -\tl_const:Nn \c_@@_option_type_slice_tl { slice } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_slice_tl -\tl_const:Nn \c_@@_option_type_string_tl { string } -\seq_gput_right:NV \g_@@_option_types_seq \c_@@_option_type_string_tl +\seq_new:N + \g_@@_option_types_seq +\tl_const:Nn + \c_@@_option_type_clist_tl + { clist } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_clist_tl +\tl_const:Nn + \c_@@_option_type_counter_tl + { counter } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_counter_tl +\tl_const:Nn + \c_@@_option_type_boolean_tl + { boolean } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_boolean_tl +\tl_const:Nn + \c_@@_option_type_number_tl + { number } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_number_tl +\tl_const:Nn + \c_@@_option_type_path_tl + { path } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_path_tl +\tl_const:Nn + \c_@@_option_type_slice_tl + { slice } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_slice_tl +\tl_const:Nn + \c_@@_option_type_string_tl + { string } +\seq_gput_right:NV + \g_@@_option_types_seq + \c_@@_option_type_string_tl \cs_new:Nn \@@_get_option_type:nN { @@ -2379,20 +2614,23 @@ interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces. #### Option `eagerCache` -`eagerCache` (default value: `false`) +`eagerCache` (default value: `true`) % \fi % \begin{markdown} % -% \Optitem[false]{eagerCache}{\opt{true}, \opt{false}} +% \Optitem[true]{eagerCache}{\opt{true}, \opt{false}} % : true : Converted markdown documents will be cached in \Opt{cacheDir}. This can be useful for post-processing the converted documents and for recovering - historical versions of the documents from the cache. However, it also - produces a large number of auxiliary files on the disk and obscures the - output of the Lua command-line interface when it is used for plumbing. + historical versions of the documents from the cache. Furthermore, it can + also significantly improve the processing speed for documents that require + multiple compilation runs, since each markdown document is only converted once. + However, it also produces a large number of auxiliary files on the disk + and obscures the output of the Lua command-line interface when it is + used for plumbing. This behavior will always be used if the \Opt{finalizeCache} option is enabled. @@ -2401,7 +2639,11 @@ interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces. : Converted markdown documents will not be cached. This decreases the number of auxiliary files that we produce and makes it easier to use the Lua - command-line interface for plumbing. + command-line interface for plumbing. However, it makes it impossible to + post-process the converted documents and recover historical versions of + the documents from the cache. Furthermore, it can significantly reduce + the processing speed for documents that require multiple compilation + runs, since each markdown document is converted multiple times needlessly. This behavior will only be used when the \Opt{finalizeCache} option is disabled. @@ -2463,18 +2705,64 @@ Hello \markdownRendererEmphasis{world}!\relax \@@_add_lua_option:nnn { eagerCache } { boolean } + { true } +% \end{macrocode} +% \iffalse +%</tex> +%<*lua,lua-cli,lua-loader> +% \fi +% \begin{macrocode} +defaultOptions.eagerCache = true +% \end{macrocode} +% \par +% \iffalse +%</lua,lua-cli,lua-loader> +%<*manual-options> + +#### Option `experimental` + +`experimental` (default value: `false`) + +% \fi +% \begin{markdown} +% +% \Optitem[false]{experimental}{\opt{true}, \opt{false}} +% +: true + + : Experimental features that are planned to be the new default in the + next major release of the Markdown package will be enabled. + + At the moment, this just means that the version `experimental` of the + theme `witiko/markdown/defaults` will be loaded and warnings for + hard-deprecated features will become errors. However, the effects may + extend to other areas in the future as well. + +: false + + : Experimental features will be disabled. + +% \end{markdown} +% \iffalse +%</manual-options> +%<*tex> +% \fi +% \begin{macrocode} +\@@_add_lua_option:nnn + { experimental } + { boolean } { false } % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} -defaultOptions.eagerCache = false +defaultOptions.experimental = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `singletonCache` @@ -2502,11 +2790,11 @@ defaultOptions.eagerCache = false : Every call to the function \luamref{new}`(options)` will produce a new conversion function that will not be cached. This is slower than caching conversion functions and may expose bugs related to memory - leaks in the creation of conversion functions, see also issue [#226][1]. + leaks in the creation of conversion functions, see also [#226 (comment)][226-comment]. This was the default behavior until version 3.0.0 of the Markdown package. - [1]: https://github.com/witiko/markdown/pull/226#issuecomment-1599641634 + [226-comment]: https://github.com/witiko/markdown/pull/226#issuecomment-1599641634 % \end{markdown} % \iffalse @@ -2555,13 +2843,13 @@ conversion function. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.singletonCache = true % \end{macrocode} % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*lua> % \fi % \begin{macrocode} @@ -2610,14 +2898,14 @@ local singletonCache = { % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.unicodeNormalization = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `unicodeNormalizationForm` @@ -2666,14 +2954,14 @@ defaultOptions.unicodeNormalization = true % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.unicodeNormalizationForm = "nfc" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> % \fi % \begin{markdown} @@ -2842,14 +3130,14 @@ option. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.cacheDir = "." % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `contentBlocksLanguageMap` @@ -3006,14 +3294,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentBlocksLanguageMap = "markdown-languages.json" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `debugExtensionsFileName` @@ -3055,14 +3343,14 @@ defaultOptions.contentBlocksLanguageMap = "markdown-languages.json" % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.debugExtensionsFileName = "debug-extensions.json" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `frozenCacheFileName` @@ -3297,14 +3585,14 @@ the markdown document from “Hello *world*!” to “Hi *world*!” was not ref % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.frozenCacheFileName = "frozenCache.tex" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> % \fi % \begin{markdown} @@ -3354,14 +3642,14 @@ See also the option \Opt{gfmAutoIdentifiers}. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.autoIdentifiers = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `blankBeforeBlockquote` @@ -3578,14 +3866,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeBlockquote = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `blankBeforeCodeFence` @@ -3835,14 +4123,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeCodeFence = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `blankBeforeDivFence` @@ -3918,14 +4206,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeDivFence = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `blankBeforeHeading` @@ -4158,14 +4446,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeHeading = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `blankBeforeList` @@ -4384,14 +4672,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeList = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `bracketedSpans` @@ -4480,14 +4768,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.bracketedSpans = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `breakableBlockquotes` @@ -4714,14 +5002,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.breakableBlockquotes = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `citationNbsps` @@ -4808,14 +5096,14 @@ following text, where the middot (`·`) denotes a non-breaking space: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.citationNbsps = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `citations` @@ -4911,14 +5199,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.citations = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `codeSpans` @@ -5137,14 +5425,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.codeSpans = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `contentBlocks` @@ -5311,14 +5599,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentBlocks = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `contentLevel` @@ -5448,14 +5736,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentLevel = "block" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `debugExtensions` @@ -5603,14 +5891,14 @@ inserted to the grammar of markdown. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.debugExtensions = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `definitionLists` @@ -5742,14 +6030,60 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.definitionLists = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> +%<*manual-options> + +#### Option `ensureJekyllData` + +`ensureJekyllData` (default value: `false`) + +% \fi +% \begin{markdown} +% +% \Optitem[false]{ensureJekyllData}{\opt{true}, \opt{false}} +% +: false + + : When the \Opt{jekyllData} and \Opt{expectJekyllData} options are + enabled, then a markdown document may begin directly with \acro{yaml} + metadata and may contain nothing but \acro{yaml} metadata. Otherwise, + the markdown document is processed as markdown text. + +: true + + : When the \Opt{jekyllData} and \Opt{expectJekyllData} options are + enabled, then a markdown document must begin directly with \acro{yaml} + metadata and must contain nothing but \acro{yaml} metadata. Otherwise, + an error is produced. + +% \end{markdown} +% \iffalse +%</manual-options> +%<*tex> +% \fi +% \begin{macrocode} +\@@_add_lua_option:nnn + { ensureJekyllData } + { boolean } + { false } +% \end{macrocode} +% \iffalse +%</tex> +%<*lua,lua-cli,lua-loader> +% \fi +% \begin{macrocode} +defaultOptions.ensureJekyllData = false +% \end{macrocode} +% \par +% \iffalse +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `expectJekyllData` @@ -5866,14 +6200,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.expectJekyllData = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `extensions` @@ -6017,14 +6351,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.extensions = {} % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `fancyLists` @@ -6119,14 +6453,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fancyLists = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `fencedCode` @@ -6286,14 +6620,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedCode = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `fencedCodeAttributes` @@ -6386,14 +6720,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedCodeAttributes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `fencedDivs` {#fenced-divs} @@ -6465,14 +6799,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedDivs = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `finalizeCache` @@ -6629,14 +6963,14 @@ the markdown document from “Hello *world*!” to “Hi *world*!” was not ref % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.finalizeCache = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `frozenCacheCounter` @@ -6698,14 +7032,14 @@ requested using the `frozenCacheCounter` option. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.frozenCacheCounter = 0 % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `gfmAutoIdentifiers` @@ -6747,14 +7081,14 @@ See also the option \Opt{autoIdentifiers}. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.gfmAutoIdentifiers = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `hashEnumerators` @@ -6878,14 +7212,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.hashEnumerators = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `headerAttributes` {#header-attributes} @@ -6927,14 +7261,14 @@ defaultOptions.hashEnumerators = false % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.headerAttributes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `html` @@ -7199,14 +7533,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.html = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `hybrid` @@ -7229,10 +7563,62 @@ defaultOptions.html = true : false : Enable the escaping of special plain \TeX{} characters outside verbatim - environments, so that they are not interpretted by \TeX{}. This is + environments, so that they are not interpreted by \TeX{}. This is encouraged when typesetting automatically generated content or markdown documents that were not prepared with this package in mind. +The \Opt{hybrid} option makes it difficult to untangle \TeX{} input from +markdown text, which makes documents written with the \Opt{hybrid} option +less interoperable and more difficult to read for authors. Therefore, the +option has been soft-deprecated in version 3.7.1 of the Markdown package: +It will never be removed but using it prints a warning and is discouraged. + +Consider one of the following better alternatives for mixing \TeX{} and +markdown: + +- With the \Opt{contentBlocks} option, authors can move large blocks of TeX + code to separate files and include them in their markdown documents as + external resources: + + ``` md + Here is a mathematical formula: + + /math-formula.tex + ``` + +- With the \Opt{rawAttribute} option, authors can denote raw text spans and + code blocks that will be interpreted as \TeX{} code: + + `````` md + `$H_2 O$`{=tex} is a liquid. + + Here is a mathematical formula: + ``` {=tex} + \[distance[i] = + \begin{dcases} + a & b \\ + c & d + \end{dcases} + \] + ``` + `````` + +- With options \Opt{texMathDollars}, \Opt{texMathSingleBackslash}, and + \Opt{texMathDoubleBackslash}, authors can freely type \TeX{} commands between + dollar signs or backslash-escaped brackets: + + ``` md + $H_2 O$ is a liquid. + + Here is a mathematical formula: + \[distance[i] = + \begin{dcases} + a & b \\ + c & d + \end{dcases} + \] + ``` + % \end{markdown} % \iffalse @@ -7425,14 +7811,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.hybrid = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `inlineCodeAttributes` @@ -7521,14 +7907,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.inlineCodeAttributes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `inlineNotes` @@ -7622,14 +8008,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.inlineNotes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `jekyllData` @@ -7789,14 +8175,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.jekyllData = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `linkAttributes` @@ -7886,14 +8272,14 @@ image (from [Martin Scharrer's mwe package][mwe]) displayed at size 5cm × 4cm. % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.linkAttributes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `lineBlocks` @@ -8021,14 +8407,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.lineBlocks = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `mark` @@ -8092,14 +8478,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.mark = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `notes` @@ -8182,10 +8568,6 @@ following text: > Here is a note reference,[^1] and another.[^longnote] > -> [^1]: Here is the note. -> -> [^longnote]: Here's one with multiple blocks. -> > Subsequent paragraphs are indented to show that they > belong to the previous note. > @@ -8236,10 +8618,6 @@ following text: > Here is a note reference,[^1] and another.[^longnote] > -> [^1]: Here is the note. -> -> [^longnote]: Here's one with multiple blocks. -> > Subsequent paragraphs are indented to show that they > belong to the previous note. > @@ -8263,14 +8641,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.notes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `pipeTables` {#pipe-tables} @@ -8372,14 +8750,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.pipeTables = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `preserveTabs` @@ -8412,14 +8790,14 @@ defaultOptions.pipeTables = false % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.preserveTabs = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `rawAttribute` @@ -8507,14 +8885,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.rawAttribute = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `relativeReferences` @@ -8528,7 +8906,7 @@ defaultOptions.rawAttribute = false % : true - : Enable [relative references][1] in autolinks: + : Enable [relative references][rfc3986] in autolinks: ``` md I conclude in Section <#conclusion>. @@ -8544,7 +8922,7 @@ defaultOptions.rawAttribute = false : Disable relative references in autolinks. - [1]: https://datatracker.ietf.org/doc/html/rfc3986#section-4.2 + [rfc3986]: https://datatracker.ietf.org/doc/html/rfc3986#section-4.2 % \end{markdown} % \iffalse @@ -8596,14 +8974,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.relativeReferences = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `shiftHeadings` @@ -8736,14 +9114,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.shiftHeadings = 0 % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `slice` @@ -8954,14 +9332,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.slice = "^ $" % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `smartEllipses` @@ -9169,14 +9547,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.smartEllipses = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `startNumber` @@ -9305,14 +9683,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.startNumber = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `strikeThrough` @@ -9427,14 +9805,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.strikeThrough = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `stripIndent` @@ -9540,14 +9918,14 @@ text “Hello *world*!” % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.stripIndent = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `subscripts` @@ -9632,14 +10010,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.subscripts = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `superscripts` @@ -9724,14 +10102,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.superscripts = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `tableAttributes` @@ -9849,14 +10227,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tableAttributes = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `tableCaptions` {#table-captions} @@ -9979,14 +10357,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tableCaptions = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `taskLists` @@ -10092,14 +10470,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.taskLists = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `texComments` @@ -10208,14 +10586,14 @@ text “Hello *world*!” % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texComments = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `texMathDollars` @@ -10419,14 +10797,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathDollars = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `texMathDoubleBackslash` @@ -10486,9 +10864,9 @@ luatex document.tex A PDF document named `document.pdf` should be produced and contain the following text: -> \\(E=mc^2\\) +> \(E=mc^2\) > -> \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] +> \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\] ##### Lua CLI Example {.unnumbered} @@ -10528,13 +10906,13 @@ script file using [Kpathsea][]. A PDF document named `document.pdf` should be produced and contain the following text: -> \\\(E=mc^2\\) -> -> \\\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] -> > \\(E=mc^2\\) > > \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] +> +> \(E=mc^2\) +> +> \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\] ##### Plain \TeX{} Example {.unnumbered} @@ -10559,9 +10937,9 @@ luatex document.tex A PDF document named `document.pdf` should be produced and contain the following text: -> \\(E=mc^2\\) +> \(E=mc^2\) > -> \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] +> \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\] ##### \LaTeX{} Example {.unnumbered} @@ -10587,9 +10965,9 @@ lualatex document.tex A PDF document named `document.pdf` should be produced and contain the following text: -> \\(E=mc^2\\) +> \(E=mc^2\) > -> \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] +> \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\] ##### \Hologo{ConTeXt} Example {.unnumbered} @@ -10615,9 +10993,9 @@ context --luatex document.tex A PDF document named `document.pdf` should be produced and contain the following text: -> \\(E=mc^2\\) +> \(E=mc^2\) > -> \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\] +> \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\] %</manual-options> %<*tex> @@ -10630,14 +11008,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathDoubleBackslash = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `texMathSingleBackslash` @@ -10841,14 +11219,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathSingleBackslash = false % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `tightLists` @@ -10962,14 +11340,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tightLists = true % \end{macrocode} % \par % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*manual-options> #### Option `underscores` @@ -11105,14 +11483,14 @@ following text: % \end{macrocode} % \iffalse %</tex> -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.underscores = true % \end{macrocode} % \endgroup % \iffalse -%</lua,lua-cli> +%</lua,lua-cli,lua-loader> %<*lua-cli> % \fi % \par @@ -11198,7 +11576,8 @@ Copyright (C) ]] .. table.concat(metadata.copyright, License: ]] .. metadata.license local function warn(s) - io.stderr:write("Warning: " .. s .. "\n") end + io.stderr:write("Warning: " .. s .. "\n") +end local function error(s) io.stderr:write("Error: " .. s .. "\n") @@ -11289,8 +11668,8 @@ for i = 1, #arg do if default_type == "nil" then warn('Option "' .. key .. '" not recognized.') else - warn('Option "' .. key .. '" type not recognized, please file ' .. - 'a report to the package maintainer.') + warn('Option "' .. key .. '" type not recognized, ' .. + 'please file a report to the package maintainer.') end warn('Parsing the ' .. 'value "' .. value ..'" of option "' .. key .. '" as a string.') @@ -11322,7 +11701,7 @@ for i = 1, #arg do end % \end{macrocode} % \begin{markdown} -% The first argument that matches none of the above patters is assumed to be +% The first argument that matches none of the above patterns is assumed to be % the input filename. The input filename should correspond to the Markdown % document that is going to be converted to a \TeX{} document. % \end{markdown} @@ -11331,7 +11710,7 @@ for i = 1, #arg do input_filename = arg[i] % \end{macrocode} % \begin{markdown} -% The first argument that matches none of the above patters is assumed to be +% The first argument that matches none of the above patterns is assumed to be % the output filename. The output filename should correspond to the \TeX{} % document that will result from the conversion. % \end{markdown} @@ -11448,10 +11827,13 @@ pdftex --shell-escape document.tex % \noindent It is expected that the special plain \TeX{} characters have the % expected category codes, when `\input`ting the file. % -%### Typesetting Markdown {#tex-typesetting} +%### Typesetting Markdown and YAML {#tex-typesetting} % % The interface exposes the \mdef{markdownBegin}, \mdef{markdownEnd}, -% \mdef{markinline}, \mdef{markdownInput}, and \mdef{markdownEscape} macros. +% \mdef{yamlBegin}, \mref{yamlEnd}, \mdef{markinline}, \mdef{markdownInput}, +% \mdef{yamlInput}, and \mdef{markdownEscape} macros. +% +%#### Typesetting Markdown and YAML directly % % The \mref{markdownBegin} macro marks the beginning of a markdown document % fragment and the \mref{markdownEnd} macro marks its end. @@ -11509,6 +11891,44 @@ pdftex --shell-escape document.tex % \bye % ``````` % +% The \mref{yamlBegin} macro marks the beginning of an \acro{YAML} document +% fragment and the \mref{yamlEnd} macro marks its end. +% +% \end{markdown} +% \begin{macrocode} +\let\yamlBegin\relax +\def\yamlEnd{\markdownEnd\endgroup} +% \end{macrocode} +% \par +% \begin{markdown} +% +% The \mref{yamlBegin} and \mref{yamlEnd} macros are subject to the same +% limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros. +% +% The following example plain \TeX{} code showcases the usage of the +% \mref{markdownBegin} and \mref{markdownEnd} macros: +% +% ``` tex +% \input markdown +% \yamlBegin +% title: _Hello_ **world** ... +% author: John Doe +% \yamlEnd +% \bye +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \input markdown +% \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData} +% \markdownBegin +% title: _Hello_ **world** ... +% author: John Doe +% \markdownEnd +% \bye +% ``````` +% % You can use the \mref{markinline} macro to input inline markdown content. % % \end{markdown} @@ -11541,6 +11961,8 @@ pdftex --shell-escape document.tex % The \mref{markinline} macro is subject to the same limitations as the % \mref{markdownBegin} and \mref{markdownEnd} macros. % +%#### Typesetting Markdown and YAML from external documents +% % You can use the \mref{markdownInput} macro to include markdown documents, % similarly to how you might use the \mref{input} \TeX{} primitive to include % \TeX{} documents. The \mref{markdownInput} macro accepts a single parameter @@ -11554,7 +11976,7 @@ pdftex --shell-escape document.tex % \par % \begin{markdown} % -% This macro is not subject to the limitations of the +% The macro \mref{markdownInput} is not subject to the limitations of the % \mref{markdownBegin} and \mref{markdownEnd} macros. % % The following example plain \TeX{} code showcases the usage of the @@ -11566,6 +11988,47 @@ pdftex --shell-escape document.tex % \bye % ``````` % +% You can use the \mref{yamlInput} macro to include \acro{YAML} documents. +% similarly to how you might use the \mref{input} \TeX{} primitive to include +% \TeX{} documents. The \mref{yamlInput} macro accepts a single parameter with +% the filename of a \acro{YAML} document and expands to the result of the +% conversion of the input \acro{YAML} document to plain \TeX{}. +% +% \end{markdown} +% \begin{macrocode} +\def\yamlInput#1{% + \begingroup + \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}% + \markdownInput{#1}% + \endgroup +}% +% \end{macrocode} +% \par +% \begin{markdown} +% +% The macro \mref{yamlInput} is also not subject to the limitations of the +% \mref{markdownBegin} and \mref{markdownEnd} macros. +% +% The following example plain \TeX{} code showcases the usage of the +% \mref{markdownInput} macro: +% +% ``` tex +% \input markdown +% \yamlInput{hello.yml} +% \bye +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \input markdown +% \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData} +% \markdownInput{hello.yml} +% \bye +% ``````` +% +%#### Typesetting TeX from inside Markdown and YAML documents +% % The \mref{markdownEscape} macro accepts a single parameter with the filename % of a \TeX{} document and executes the \TeX{} document in the middle of a % markdown document fragment. Unlike the `\input` built-in of \TeX, @@ -11625,7 +12088,9 @@ pdftex --shell-escape document.tex % \begin{macrocode} \prop_new:N \g_@@_plain_tex_option_types_prop \prop_new:N \g_@@_default_plain_tex_options_prop -\seq_gput_right:NV \g_@@_option_layers_seq \c_@@_option_layer_plain_tex_tl +\seq_gput_right:NV + \g_@@_option_layers_seq + \c_@@_option_layer_plain_tex_tl \cs_new:Nn \@@_add_plain_tex_option:nnn { @@ -11684,6 +12149,18 @@ following code in your plain \TeX{} document: \markdownSetup \@@_setup:n % \end{macrocode} +% \begin{markdown} +% +% The command \mdef{yamlSetup} is also available as an alias for the command +% \mref{markdownSetup}. +% +% \end{markdown} +% \begin{macrocode} +\cs_gset_eq:NN + \yamlSetup + \markdownSetup +% \end{macrocode} +% % \iffalse %</tex> %<*manual-options> @@ -11856,47 +12333,10 @@ For more information, see the examples for the \Opt{finalizeCache} option. % % \end{markdown} % \begin{macrocode} -\cs_generate_variant:Nn - \@@_add_plain_tex_option:nnn - { nnV } -% \end{macrocode} -% \begin{markdown} -% -% Use the \pkg{lt3luabridge} library to determine the default value of the -% \mref{markdownOptionOutputDir} macro by using the environmental variable -% `TEXMF_OUTPUT_DIRECTORY` that is available since TeX~Live 2024. -% -% \end{markdown} -% \begin{macrocode} -\ExplSyntaxOff -\input lt3luabridge.tex -\ExplSyntaxOn -\bool_if:nTF - { - \cs_if_exist_p:N - \luabridge_tl_set:Nn && - ( - \int_compare_p:nNn - { \g_luabridge_method_int } - = - { \c_luabridge_method_directlua_int } || - \sys_if_shell_unrestricted_p: - ) - } - { - \luabridge_tl_set:Nn - \l_tmpa_tl - { print(os.getenv("TEXMF_OUTPUT_DIRECTORY") or ".") } - } - { - \tl_set:Nn - \l_tmpa_tl - { . } - } -\@@_add_plain_tex_option:nnV +\@@_add_plain_tex_option:nnn { outputDir } { path } - \l_tmpa_tl + { . } % \end{macrocode} % \iffalse %</tex> @@ -12172,22 +12612,95 @@ A PDF document named `document.pdf` should be produced and contain the text % \end{macrocode} % \begin{markdown} % -% Do not override options defined before loading the package. +% Use the \pkg{lt3luabridge} library to determine the default value of the +% \mref{markdownOptionOutputDir} macro by using the environmental variable +% `TEXMF_OUTPUT_DIRECTORY` that is available since TeX~Live 2024. % % \end{markdown} % \begin{macrocode} - \@@_option_tl_to_csname:nN + \str_if_eq:nnTF { #1 } - \l_tmpa_tl - \cs_if_exist:cF - { \l_tmpa_tl } + { outputDir } + { \@@_define_option_command_output_dir: } { - \@@_get_default_option_value:nN - { #1 } - \l_tmpa_tl - \@@_set_option_value:nV +% \end{macrocode} +% \begin{markdown} +% +% Do not override options defined before loading the package. +% +% \end{markdown} +% \begin{macrocode} + \@@_option_tl_to_csname:nN { #1 } \l_tmpa_tl + \cs_if_exist:cF + { \l_tmpa_tl } + { + \@@_get_default_option_value:nN + { #1 } + \l_tmpa_tl + \@@_set_option_value:nV + { #1 } + \l_tmpa_tl + } + } + } +\ExplSyntaxOff +\input lt3luabridge.tex +% \end{macrocode} +% \begin{markdown} +% +% Use the \pkg{lt3luabridge} library to determine the default value of the +% \mref{markdownOptionOutputDir} macro by using the environmental variable +% `TEXMF_OUTPUT_DIRECTORY` that is available since TeX~Live 2024. +% +% \end{markdown} +% \begin{macrocode} +\ExplSyntaxOn +\cs_new:Nn + \@@_define_option_command_output_dir: + { + \cs_if_free:NT + \markdownOptionOutputDir + { + \bool_if:nTF + { + \cs_if_exist_p:N + \luabridge_tl_set:Nn && + ( + \int_compare_p:nNn + { \g_luabridge_method_int } + = + { \c_luabridge_method_directlua_int } || + \sys_if_shell_unrestricted_p: + ) + } + { +% \end{macrocode} +% \begin{markdown} +% +% Set most catcodes to category 12 (other) to ensure that special characters in +% `TEXMF_OUTPUT_DIRECTORY` such as backslashes (`\`) are not interpreted as +% control sequences. +% +% \end{markdown} +% \begin{macrocode} + \group_begin: + \cctab_select:N + \c_str_cctab + \luabridge_tl_set:Nn + \l_tmpa_tl + { print(os.getenv("TEXMF_OUTPUT_DIRECTORY") or ".") } + \tl_gset:NV + \markdownOptionOutputDir + \l_tmpa_tl + \group_end: + } + { + \tl_gset:Nn + \markdownOptionOutputDir + { . } + } } } \cs_new:Nn @@ -12370,7 +12883,7 @@ A PDF document named `document.pdf` should be produced and contain the text \prg_generate_conditional_variant:Nnn \str_if_eq:nn { en } - { F } + { p, F } \msg_new:nnn { markdown } { malformed-name-for-clist-option } @@ -12407,28 +12920,34 @@ User-defined themes for the Markdown package provide a domain-specific interpretation of Markdown tokens. Themes allow the authors to achieve a specific look and other high-level goals without low-level programming. -% The key-values `theme`=\meta{theme name} and `import`=\meta{theme name} load -% a \TeX{} document (further referred to as *a theme*) named -% `markdowntheme`\meta{munged theme name}`.tex`, where the *munged theme name* -% is the *theme name* after the substitution of all forward slashes (`/`) for -% an underscore (`_`). The theme name is *qualified* and contains no -% underscores. A theme name is qualified if and only if it contains at least -% one forward slash. Themes are inspired by the Beamer \LaTeX{} package, which -% provides similar functionality with its `\usetheme` macro [@tantau21, Section -% 15.1]. -% -% Theme names must be qualified to minimize naming conflicts between different -% themes with a similar purpose. The preferred format of a theme name is -% \meta{theme author}`/`\meta{theme purpose}`/`\meta{private naming -% scheme}, where the *private naming scheme* may contain additional forward -% slashes. For example, a theme by a user `witiko` for the MU theme of the -% Beamer document class may have the name `witiko/beamer/MU`. +% The key-values `theme`=\meta{theme name} and `import`=\meta{theme name}, +% optionally followed by `@`\meta{theme version}, load a \TeX{} document +% (further referred to as *a theme*) named `markdowntheme`\meta{munged theme +% name}`.tex`, where the *munged theme name* is the *theme name* after the +% substitution of all forward slashes (`/`) for an underscore (`_`). +% The theme name must be *qualified* and contain no underscores or at signs +% (`@`). Themes are inspired by the Beamer \LaTeX{} package, which provides +% similar functionality with its `\usetheme` macro [@tantau21, Section 15.1]. +% +% A theme name is qualified if and only if it contains at least one forward +% slash. Theme names must be qualified to minimize naming conflicts between +% different themes with a similar purpose. The preferred format of a theme name +% is \meta{theme author}`/`\meta{theme purpose}`/`\meta{private naming scheme}, +% where the *private naming scheme* may contain additional forward slashes. For +% example, a theme by a user `witiko` for the MU theme of the Beamer document +% class may have the name `witiko/beamer/MU`. % % Theme names are munged to allow structure inside theme names without % dictating where the themes should be located inside the \TeX{} directory % structure. For example, loading a theme named `witiko/beamer/MU` would % load a \TeX{} document package named `markdownthemewitiko_beamer_MU.tex`. % +% If `@`\meta{theme version} is specified after \meta{theme name}, then the +% text *theme version* will be available in the macro +% \mdef{markdownThemeVersion} when the theme is loaded. If `@`\meta{theme +% version} is not specified, the macro \mref{markdownThemeVersion} will +% contain the text `latest` [@novotny24]. +% % \end{markdown} % \iffalse %</manual-options> @@ -12471,21 +12990,31 @@ a specific look and other high-level goals without low-level programming. % \begin{markdown} % % To keep track of the current theme when themes are nested, we will -% maintain the \mdef{g_\@\@_themes_seq} stack of theme names. -% For convenience, the name of the current theme is also available in the -% \mdef{g_@@_current_theme_tl} macro. +% maintain the stacks \mdef{g_\@\@_theme_names_seq} and +% \mdef{g_\@\@_theme_versions_seq} stack of theme names and versions, +% respectively. For convenience, the name of the current theme and version is +% also available in the macros \mdef{g_@@_current_theme_tl} and +% \mref{markdownThemeVersion}, respectively. % % \end{markdown} % \begin{macrocode} \seq_new:N - \g_@@_themes_seq + \g_@@_theme_names_seq +\seq_new:N + \g_@@_theme_versions_seq \tl_new:N \g_@@_current_theme_tl \tl_gset:Nn \g_@@_current_theme_tl { } \seq_gput_right:NV - \g_@@_themes_seq + \g_@@_theme_names_seq + \g_@@_current_theme_tl +\cs_new:Npn + \markdownThemeVersion + { } +\seq_gput_right:NV + \g_@@_theme_versions_seq \g_@@_current_theme_tl \cs_new:Nn \@@_set_theme:n @@ -12518,13 +13047,55 @@ a specific look and other high-level goals without low-level programming. % \end{macrocode} % \begin{markdown} % +% Next, we extract the theme version. +% +% \end{markdown} +% \begin{macrocode} + \str_if_in:nnTF + { #1 } + { @ } + { + \regex_extract_once:nnN + { (.*) @ (.*) } + { #1 } + \l_tmpa_seq + \seq_gpop_left:NN + \l_tmpa_seq + \l_tmpa_tl + \seq_gpop_left:NN + \l_tmpa_seq + \l_tmpa_tl + \tl_gset:NV + \g_@@_current_theme_tl + \l_tmpa_tl + \seq_gpop_left:NN + \l_tmpa_seq + \l_tmpa_tl + \cs_gset:Npe + \markdownThemeVersion + { + \tl_use:N + \l_tmpa_tl + } + } + { + \tl_gset:Nn + \g_@@_current_theme_tl + { #1 } + \cs_gset:Npn + \markdownThemeVersion + { latest } + } +% \end{macrocode} +% \begin{markdown} +% % Next, we munge the theme name. % % \end{markdown} % \begin{macrocode} - \str_set:Nn + \str_set:NV \l_tmpa_str - { #1 } + \g_@@_current_theme_tl \str_replace_all:Nnn \l_tmpa_str { / } @@ -12532,28 +13103,56 @@ a specific look and other high-level goals without low-level programming. % \end{macrocode} % \begin{markdown} % -% Finally, we load the theme. +% Finally, we load the theme. Before loading the theme, we push down the +% current name and version of the theme on the stack. % % \end{markdown} % \begin{macrocode} - \tl_gset:Nn + \tl_set:NV + \l_tmpa_tl + \g_@@_current_theme_tl + \tl_put_right:Nn \g_@@_current_theme_tl - { #1 / } + { / } \seq_gput_right:NV - \g_@@_themes_seq + \g_@@_theme_names_seq \g_@@_current_theme_tl - \@@_load_theme:nV - { #1 } + \seq_gput_right:NV + \g_@@_theme_versions_seq + \markdownThemeVersion + \@@_load_theme:VeV + \l_tmpa_tl + { \markdownThemeVersion } \l_tmpa_str +% \end{macrocode} +% \begin{markdown} +% +% After the theme has been loaded, we recover the name and version of the +% previous theme from the stack. +% +% \end{markdown} +% \begin{macrocode} \seq_gpop_right:NN - \g_@@_themes_seq + \g_@@_theme_names_seq \l_tmpa_tl \seq_get_right:NN - \g_@@_themes_seq + \g_@@_theme_names_seq \l_tmpa_tl \tl_gset:NV \g_@@_current_theme_tl \l_tmpa_tl + \seq_gpop_right:NN + \g_@@_theme_versions_seq + \l_tmpa_tl + \seq_get_right:NN + \g_@@_theme_versions_seq + \l_tmpa_tl + \cs_gset:Npe + \markdownThemeVersion + { + \tl_use:N + \l_tmpa_tl + } } \msg_new:nnnn { markdown } @@ -12568,6 +13167,9 @@ a specific look and other high-level goals without low-level programming. \cs_generate_variant:Nn \tl_replace_all:Nnn { NnV } +\cs_generate_variant:Nn + \cs_gset:Npn + { Npe } \ExplSyntaxOff % \end{macrocode} % \iffalse @@ -12682,10 +13284,14 @@ options locally. { redefined-snippet } \l_tmpa_tl } - \prop_gput:NVn + \keys_precompile:nnN + { markdown/options } + { #2 } + \l_tmpb_tl + \prop_gput:NVV \g_@@_snippets_prop \l_tmpa_tl - { #2 } + \l_tmpb_tl } \cs_gset_eq:NN \markdownSetupSnippet @@ -12707,20 +13313,21 @@ options locally. % % \end{markdown} % \begin{macrocode} +\tl_new:N + \l_@@_current_snippet_tl \prg_new_conditional:Nnn \@@_if_snippet_exists:n { TF, T, F } { \tl_set:NV - \l_tmpa_tl + \l_@@_current_snippet_tl \g_@@_current_theme_tl \tl_put_right:Nn - \l_tmpa_tl + \l_@@_current_snippet_tl { #1 } - \prop_get:NVNTF + \prop_if_in:NVTF \g_@@_snippets_prop - \l_tmpa_tl - \l_tmpb_tl + \l_@@_current_snippet_tl { \prg_return_true: } { \prg_return_false: } } @@ -12751,7 +13358,7 @@ options locally. \g_@@_snippets_prop \l_tmpa_tl \l_tmpb_tl - \@@_setup:V + \tl_use:N \l_tmpb_tl } { @@ -12766,9 +13373,6 @@ options locally. { markdown } { undefined-snippet } { Can't~invoke~undefined~snippet~#1 } -\cs_generate_variant:Nn - \@@_setup:n - { V } \ExplSyntaxOff % \end{macrocode} % \iffalse @@ -14039,7 +14643,7 @@ following text: #### Code Block Renderers The \mdef{markdownRendererInputVerbatim} macro represents a code block. The macro receives a single argument that corresponds to the -filename of a file contaning the code block contents. +filename of a file containing the code block contents. % \end{markdown} % @@ -14073,7 +14677,7 @@ filename of a file contaning the code block contents. The \mdef{markdownRendererInputFencedCode} macro represents a fenced code block. This macro will only be produced, when the \Opt{fencedCode} option is enabled. The macro receives three arguments that correspond to the filename of -a file contaning the code block contents, the fully escaped code fence infostring +a file containing the code block contents, the fully escaped code fence infostring that can be directly typeset, and the raw code fence infostring that can be used outside typesetting. @@ -15289,7 +15893,7 @@ following text: % \begin{markdown} #### Ellipsis Renderer -The \mdef{markdownRendererEllipsis} macro replaces any occurance of ASCII +The \mdef{markdownRendererEllipsis} macro replaces any occurrence of ASCII ellipses in the input text. This macro will only be produced, when the \Opt{smartEllipses} option is enabled. The macro receives no arguments. @@ -15399,7 +16003,7 @@ following text: % % \begin{markdown} -#### Emphasis Renderers +#### Emphasis Renderers {#emphasis-renderers} The \mdef{markdownRendererEmphasis} macro represents an emphasized span of text. The macro receives a single argument that corresponds to the emphasized span of text. @@ -15553,8 +16157,8 @@ following text: % \begin{markdown} #### Fenced Code Attribute Context Renderers -The following macros are only produced, when the \Opt{fencedCode} option is -enabled. +The following macros are only produced, when the \Opt{fencedCode} and +\Opt{fencedCodeAttributes} options are enabled. The \mdef{markdownRendererFencedCodeAttributeContextBegin} and \mdef{markdownRendererFencedCodeAttributeContextEnd} macros represent the @@ -18435,7 +19039,7 @@ following text: #### Raw Content Renderers The \mdef{markdownRendererInputRawInline} macro represents an inline raw span. -The macro receives two arguments: the filename of a file contaning the inline +The macro receives two arguments: the filename of a file containing the inline raw span contents and the raw attribute that designates the format of the inline raw span. This macro will only be produced, when the \Opt{rawAttribute} option is enabled. @@ -18470,7 +19074,7 @@ option is enabled. % \begin{markdown} The \mdef{markdownRendererInputRawBlock} macro represents a raw block. The -macro receives two arguments: the filename of a file contaning the raw block +macro receives two arguments: the filename of a file containing the raw block and the raw attribute that designates the format of the raw block. This macro will only be produced, when the \Opt{rawAttribute} and \Opt{fencedCode} options are enabled. @@ -19308,7 +19912,7 @@ following text: % % \begin{markdown} -#### Table Renderer +#### Table Renderer {#table-renderer} The \mdef{markdownRendererTable} macro represents a table. This macro will only be produced, when the \Opt{pipeTables} option is enabled. The macro receives the parameters `{`\meta{caption}`}{`\meta{number of rows}`}{`\meta{number of columns}`}` @@ -19368,7 +19972,7 @@ following content: \markdownSetup{ renderers = { table = {% - This is a table with caption \emph{#1} that is #3 colums wide + This is a table with caption \emph{#1} that is #3 columns wide and #2 rows long. \rowCounter=0% \def\rowTotal{#2}% @@ -19397,7 +20001,7 @@ A PDF document named `document.pdf` should be produced and contain the following text: > This is a table with caption *Demonstration of pipe table syntax* that is 4 -> colums wide and 4 rows long. As for the alignment, column number 1 is +> columns wide and 4 rows long. As for the alignment, column number 1 is > right-aligned, column number 2 is left-aligned, column number 3 has default > alignment, and column number 4 is centered. In row 1, column number 1 says > *Right*, column number 2 says *Left*, column number 3 says *Default*, and @@ -19454,7 +20058,7 @@ following content: \input markdown \def\markdownOptionTexMathDollars{true} \def\markdownRendererInlineMath#1{$#1\dots$} -\def\markdownRendererDisplayMath#1{$$#1\eqno(1)$$} +\def\markdownRendererDisplayMath#1{$$#1\nonumber$$} \markdownBegin $E=mc^2$ @@ -19471,7 +20075,7 @@ following text: > $E=mc^2\dots$ > -> $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\eqno(1)$$ +> $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\nonumber$$ ##### \LaTeX{} Example {.unnumbered} @@ -19810,6 +20414,59 @@ following text: % % \begin{markdown} +#### Warning and Error Renderers + +The \mdef{markdownRendererWarning} and \mdef{markdownRendererError} macros +represent warnings and errors produced by the markdown parser. Both macros +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} +% +% \iffalse +%</manual-tokens> +%<*tex> +% \fi +% +% \begin{macrocode} +\def\markdownRendererWarning{% + \markdownRendererWarningPrototype}% +\def\markdownRendererError{% + \markdownRendererErrorPrototype}% +\ExplSyntaxOn +\seq_gput_right:Nn + \g_@@_renderers_seq + { warning } +\prop_gput:Nnn + \g_@@_renderer_arities_prop + { warning } + { 4 } +\seq_gput_right:Nn + \g_@@_renderers_seq + { error } +\prop_gput:Nnn + \g_@@_renderer_arities_prop + { error } + { 4 } +\ExplSyntaxOff +% \end{macrocode} +% \par +% +% \iffalse +%</tex> +%<*manual-tokens> +% \fi +% +% \begin{markdown} + #### YAML Metadata Renderers {#yamlmetadatarenderers} The \mdef{markdownRendererJekyllDataBegin} macro represents the beginning of a @@ -20084,12 +20741,68 @@ following \acro{yaml} serialization rules. % % \begin{markdown} -The \mdef{markdownRendererJekyllDataString} macro represents a string scalar -value in a \acro{yaml} document. This macro will only be produced when the -\Opt{jekyllData} option is enabled. The macro receives two arguments: the +The \mdef{markdownRendererJekyllDataTypographicString} and +\mdef{markdownRendererJekyllDataProgrammaticString} macros represent string +scalar values in a \acro{yaml} document. This macro will only be produced when +the \Opt{jekyllData} option is enabled. The macro receives two arguments: the scalar key in the parent structure, cast to a string following \acro{yaml} serialization rules, and the scalar value. +For each string scalar value, both macros are produced. Whereas +\mref{markdownRendererJekyllDataTypographicString} receives the scalar value +after all markdown markup and special \TeX{} characters in the string have been +replaced by \TeX{} macros, \mref{markdownRendererJekyllDataProgrammaticString} +receives the raw scalar value. Therefore, whereas the +\mref{markdownRendererJekyllDataTypographicString} macro is more appropriate +for texts that are supposed to be typeset with \TeX{}, such as document titles, +author names, or exam questions, the +\mref{markdownRendererJekyllDataProgrammaticString} macro is more appropriate +for identifiers and other programmatic text that won't be typeset by \TeX{}. + +% \end{markdown} +% +% \iffalse +%</manual-tokens> +%<*tex> +% \fi +% +% \begin{macrocode} +\def\markdownRendererJekyllDataTypographicString{% + \markdownRendererJekyllDataTypographicStringPrototype}% +\def\markdownRendererJekyllDataProgrammaticString{% + \markdownRendererJekyllDataProgrammaticStringPrototype}% +\ExplSyntaxOn +\seq_gput_right:Nn + \g_@@_renderers_seq + { jekyllDataTypographicString } +\prop_gput:Nnn + \g_@@_renderer_arities_prop + { jekyllDataTypographicString } + { 2 } +\seq_gput_right:Nn + \g_@@_renderers_seq + { jekyllDataProgrammaticString } +\prop_gput:Nnn + \g_@@_renderer_arities_prop + { jekyllDataProgrammaticString } + { 2 } +\ExplSyntaxOff +% \end{macrocode} +% \par +% +% \iffalse +%</tex> +%<*manual-tokens> +% \fi +% +% \begin{markdown} + +Before Markdown 3.7.0, the \mref{markdownRendererJekyllDataTypographicString} +macro was named \mref{markdownRendererJekyllDataString} and the +\mref{markdownRendererJekyllDataProgrammaticString} macro was not produced. +The \mref{markdownRendererJekyllDataString} has been deprecated and will be +removed in Markdown 4.0.0. + % \end{markdown} % % \iffalse @@ -20098,9 +20811,60 @@ serialization rules, and the scalar value. % \fi % % \begin{macrocode} -\def\markdownRendererJekyllDataString{% - \markdownRendererJekyllDataStringPrototype}% \ExplSyntaxOn +\cs_gset:Npn + \markdownRendererJekyllDataTypographicString + { + \cs_if_exist:NTF + \markdownRendererJekyllDataString + { + \@@_if_option:nTF + { experimental } + { + \markdownError + { + The~jekyllDataString~renderer~has~been~deprecated,~ + to~be~removed~in~Markdown~4.0.0 + } + } + { + \markdownWarning + { + The~jekyllDataString~renderer~has~been~deprecated,~ + to~be~removed~in~Markdown~4.0.0 + } + \markdownRendererJekyllDataString + } + } + { + \cs_if_exist:NTF + \markdownRendererJekyllDataStringPrototype + { + \@@_if_option:nTF + { experimental } + { + \markdownError + { + The~jekyllDataString~renderer~prototype~ + has~been~deprecated,~ + to~be~removed~in~Markdown~4.0.0 + } + } + { + \markdownWarning + { + The~jekyllDataString~renderer~prototype~ + has~been~deprecated,~ + to~be~removed~in~Markdown~4.0.0 + } + \markdownRendererJekyllDataStringPrototype + } + } + { + \markdownRendererJekyllDataTypographicStringPrototype + } + } + } \seq_gput_right:Nn \g_@@_renderers_seq { jekyllDataString } @@ -20162,7 +20926,7 @@ following content: ``` tex \input markdown \def\markdownOptionJekyllData{true} -\def\markdownRendererJekyllDataString#1#2{\gdef\name{#2}} +\def\markdownRendererJekyllDataTypographicString#1#2{\gdef\name{#2}} \def\markdownRendererJekyllDataNumber#1#2{\gdef\age{#2}} \def\markdownRendererJekyllDataEnd{% \name{} is \age{} years old.} @@ -20192,7 +20956,7 @@ following content: \usepackage[jekyllData]{markdown} \markdownSetup{ renderers = { - jekyllDataString = {\gdef\name{#2}}, + jekyllDataTypographicString = {\gdef\name{#2}}, jekyllDataNumber = {\gdef\age{#2}}, jekyllDataEnd = {\name{} is \age{} years old.}, } @@ -20224,7 +20988,7 @@ following content: ``` tex \usemodule[t][markdown] \setupmarkdown[jekyllData = yes] -\def\markdownRendererJekyllDataString#1#2{\gdef\name{#2}} +\def\markdownRendererJekyllDataTypographicString#1#2{\gdef\name{#2}} \def\markdownRendererJekyllDataNumber#1#2{\gdef\age{#2}} \def\markdownRendererJekyllDataEnd{% \name{} is \age{} years old.} @@ -20256,7 +21020,7 @@ following text: %#### Generating Plain \TeX{} Token Renderer Macros and Key-Values {#plain-tex-renderers} % % We define the command \mdef{@@_define_renderers:} that defines plain \TeX{} -% macros for token renderers. Futhermore, the `\markdownSetup` macro also accepts +% macros for token renderers. Furthermore, the `\markdownSetup` macro also accepts % the `renderers` key, whose value must be a list of key-values, where the keys % correspond to the markdown token renderer macros and the values are new % definitions of these token renderers. @@ -20266,9 +21030,12 @@ following text: \ExplSyntaxOn \cs_new:Nn \@@_define_renderers: { - \seq_map_function:NN + \seq_map_inline:Nn \g_@@_renderers_seq - \@@_define_renderer:n + { + \@@_define_renderer:n + { ##1 } + } } \cs_new:Nn \@@_define_renderer:n { @@ -20332,6 +21099,24 @@ following text: \l_@@_renderer_definition_tl }, } +% \end{macrocode} +% \par +% \begin{markdown} +% +% If the token renderer macro has been deprecated, we undefine it. +% +% The \mref{markdownRendererJekyllDataString} macro has been deprecated and +% will be removed in Markdown 4.0.0. +% +% \end{markdown} +% \begin{macrocode} + \str_if_eq:nnT + { #1 } + { jekyllDataString } + { + \cs_undefine:N + #2 + } } % \end{macrocode} % \par @@ -20974,7 +21759,7 @@ following text: %#### Generating Plain \TeX{} Token Renderer Prototype Macros and Key-Values {#plain-tex-renderer-prototypes} % % We define the command \mdef{@@_define_renderer_prototypes:} that defines plain \TeX{} -% macros for token renderer prototypes. Futhermore, the `\markdownSetup` macro also accepts +% macros for token renderer prototypes. Furthermore, the `\markdownSetup` macro also accepts % the `rendererPrototype` key, whose value must be a list of key-values, where the keys % correspond to the markdown token renderer prototype macros and the values are new % definitions of these token renderer prototypes. @@ -20984,9 +21769,12 @@ following text: \ExplSyntaxOn \cs_new:Nn \@@_define_renderer_prototypes: { - \seq_map_function:NN + \seq_map_inline:Nn \g_@@_renderers_seq - \@@_define_renderer_prototype:n + { + \@@_define_renderer_prototype:n + { ##1 } + } } \cs_new:Nn \@@_define_renderer_prototype:n { @@ -21052,21 +21840,30 @@ following text: }, } % \end{macrocode} +% \par % \begin{markdown} % -% Unless the token renderer prototype macro has already been defined, -% we provide an empty definition. +% Unless the token renderer prototype macro has already been defined or unless, +% it has been deprecated, we provide an empty definition. +% +% The \mref{markdownRendererJekyllDataStringPrototype} macro has been +% deprecated and will be removed in Markdown 4.0.0. % % \end{markdown} % \begin{macrocode} - \cs_if_free:NT - #2 + \str_if_eq:nnF + { #1 } + { jekyllDataString } { - \cs_generate_from_arg_count:NNnn + \cs_if_free:NT #2 - \cs_set:Npn - { #3 } - { } + { + \cs_generate_from_arg_count:NNnn + #2 + \cs_set:Npn + { #3 } + { } + } } } \cs_generate_variant:Nn @@ -21296,12 +22093,12 @@ following text: % \begin{markdown} % % The \mdef{markdownReadAndConvert} macro implements the \mref{markdownBegin} -% macro. The first argument specifies the token sequence that will terminate -% the markdown input (\mref{markdownEnd} in the instance of the \mref{markdownBegin} -% macro) when the plain \TeX{} special characters have had their category -% changed to *other*. The second argument specifies the token sequence -% that will actually be inserted into the document, when the ending token -% sequence has been found. +% and \mref{yamlBegin} macros. The first argument specifies the token sequence +% that will terminate the markdown input when the plain \TeX{} special +% characters have had their category changed to *other*: \mref{markdownEnd} for +% the \mref{markdownBegin} macro and \mref{yamlEnd} for the \mref{yamlBegin} +% macro. The second argument specifies the token sequence that will actually be +% inserted into the document, when the ending token sequence has been found. % % \end{markdown} % \begin{macrocode} @@ -21320,6 +22117,11 @@ following text: |gdef|markdownBegin{% |markdownReadAndConvert{\markdownEnd}% {|markdownEnd}}% + |gdef|yamlBegin{% + |begingroup + |yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}% + |markdownReadAndConvert{\yamlEnd}% + {|yamlEnd}}% |endgroup % \end{macrocode} % \begin{markdown} @@ -21462,15 +22264,16 @@ pdflatex --shell-escape document.tex % \begin{markdown} % %### Typesetting Markdown -% The interface exposes the \envmdef{markdown} and \envmdef{markdown*} -% \LaTeX{} environments, and redefines the \mref{markinline} and -% \mref{markdownInput} commands. % -% The \envmref{markdown} and \envmref{markdown*} \LaTeX{} environments are used -% to typeset markdown document fragments. Both \LaTeX{} environments accept -% \LaTeX{} interface options (see ection <#sec:latex-options>) as the only -% argument. This argument is optional for the \envmref{markdown} environment -% and mandatory for the \envmref{markdown*} environment. +% The interface exposes the \envmdef{markdown}, \envmdef{markdown*}, and +% \envmdef{yaml} \LaTeX{} environments, and redefines the \mref{markinline}, +% \mref{markdownInput}, and \mref{yamlInput} commands. +% +%#### Typesetting Markdown and YAML directly +% +% The \envmref{markdown} and \envmref{markdown*} \LaTeX{} environments are +% aliases for the macros \mref{markdownBegin} and \mref{markdownEnd} exposed +% by the plain \TeX{} interface. % % The \envmref{markdown*} environment has been deprecated and will be removed % in the next major version of the Markdown package. @@ -21482,56 +22285,255 @@ pdflatex --shell-escape document.tex % \end{macrocode} % \markdownBegin % -% You may prepend your own code to the \mdef{markdown} macro and append your own -% code to the \mref{markdownEnd} macro to produce special effects before and after -% the \envmref{markdown} \LaTeX{} environment (and likewise for the starred -% version). +% Furthermore, both environments accept \LaTeX{} interface options (see Section +% <#sec:latex-options>) as the only argument. This argument is optional for the +% \envmref{markdown} environment and mandatory for the \envmref{markdown*} +% environment. % -% Note that the \envmref{markdown} and \envmref{markdown*} \LaTeX{} environments are -% subject to the same limitations as the \mref{markdownBegin} and \mref{markdownEnd} -% macros exposed by the plain \TeX{} interface. +% The \envmref{markdown} and \envmref{markdown*} environments are +% subject to the same limitations as the \mref{markdownBegin} and +% \mref{markdownEnd} macros. % % The following example \LaTeX{} code showcases the usage of the % \envmref{markdown} and \envmref{markdown*} environments: +% % ``` tex % \documentclass{article} \documentclass{article} % \usepackage{markdown} \usepackage{markdown} % \begin{document} \begin{document} -% \% ... \% ... % \begin{markdown}[smartEllipses] \begin{markdown*}{smartEllipses} % _Hello_ **world** ... _Hello_ **world** ... % \end{markdown} \end{markdown*} -% \% ... \% ... % \end{document} \end{document} % ``````` % +% You can't directly extend the \envmref{markdown} \LaTeX{} environment by +% using it in other environments as follows: +% +% ``` tex +% \newenvironment{foo}\% +% {code before \begin{markdown}[some, options]}\% +% {\end{markdown} code after} +% ``` +% +% This is because the implementation looks for the literal string +% `\end{markdown}` to stop scanning the markdown text. However, you can work +% around this limitation by using the \mref{markdown} and \mref{markdownEnd} +% macros directly in the definition as follows: +% +% \markdownEnd +% \begin{markdown} +% +% ``` tex +% \newenvironment{foo}\% +% {code before \markdown[some, options]}\% +% {\markdownEnd code after} +% ``` +% +% Specifically, the \mref{markdown} macro must appear at the end of the +% replacement before-text and must be followed by text that has not yet been +% ingested by \TeX's input processor. +% +% Furthermore, using the \mref{markdownEnd} macro in of after the replacement +% after-text is optional and only makes a difference if you redefined it to +% produce special effects before and after the \envmref{markdown} \LaTeX{} +% environment. +% +% Lastly, you can't nest the other environments. For example, the following +% definition would be incorrect: +% +% ``` tex +% \newenvironment{bar}{\begin{foo}}{\end{foo}} +% ``` +% +% In this example, you should use the \mref{markdown} macro directly in the +% definition of the environment `bar`: +% +% ``` tex +% \newenvironment{bar}{\markdown[some, options]}{\markdownEnd} +% ``` +% +% The \envmref{yaml} \LaTeX{} environment is an alias for the macros +% \mref{yamlBegin} and \mref{yamlEnd} exposed by the plain \TeX{} interface. +% +% \end{markdown} +% \begin{macrocode} +\newenvironment{yaml}\relax\relax +% \end{macrocode} +% \begin{markdown} +% +% Furthermore, the environment accepts \LaTeX{} interface options (see Section +% <#sec:latex-options>) as the only optional argument. +% +% The \envmref{yaml} environment is subject to the same limitations as +% the \mref{markdownBegin} and \mref{markdownEnd} macros. +% +% The following example \LaTeX{} code showcases the usage of the +% \envmref{yaml} environment: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \begin{document} +% \begin{yaml}[smartEllipses] +% title: _Hello_ **world** ... +% author: John Doe +% \end{yaml} +% \end{document} +% ``````` +% +% \end{markdown} +% \markdownBegin +% +% The above code has the same effect as the below code: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \begin{document} +% \begin{markdown}[ +% jekyllData, +% expectJekyllData, +% ensureJekyllData, +% smartEllipses, +% ] +% title: _Hello_ **world** ... +% author: John Doe +% \end{markdown} +% \end{document} +% ``````` +% +% You can't directly extend the \envmref{yaml} \LaTeX{} environment by using it +% in other environments. However, you can work around this limitation by using +% the \mref{yaml} and \mref{yamlEnd} macros directly in the definition, +% similarly to the \mref{markdown} and \mref{markdownEnd} macros described +% previously. Unlike with the \mref{markdown} and \mref{markdownEnd} macros, +% The \mref{yamlEnd} macro _must_ be used in or after the replacement after-text. +% % The \mref{markinline} macro accepts a single mandatory parameter containing % inline markdown content and expands to the result of the conversion of the % input markdown document to plain \TeX{}. Unlike the \mref{markinline} macro % provided by the plain \TeX{} interface, this macro also accepts \LaTeX{} % interface options (see Section <#sec:latex-options>) as its optional -% argument. These options will only influnce this markdown content. +% argument. These options will only influence this markdown content. +% +%#### Typesetting Markdown and YAML from external documents % % The \mref{markdownInput} macro accepts a single mandatory parameter containing % the filename of a markdown document and expands to the result of the % conversion of the input markdown document to plain \TeX{}. Unlike the % \mref{markdownInput} macro provided by the plain \TeX{} interface, this macro % also accepts \LaTeX{} interface options (see Section <#sec:latex-options>) -% as its optional argument. These options will only influnce this markdown +% as its optional argument. These options will only influence this markdown % document. % % The following example \LaTeX{} code showcases the usage of the % \mref{markdownInput} macro: +% % ``` tex % \documentclass{article} % \usepackage{markdown} % \begin{document} -% % ... % \markdownInput[smartEllipses]{hello.md} -% % ... % \end{document} % ``````` % +% The \mref{yamlInput} macro accepts a single mandatory parameter containing +% the filename of a \acro{YAML} document and expands to the result of the +% conversion of the input \acro{YAML} document to plain \TeX{}. Unlike the +% \mref{yamlInput} macro provided by the plain \TeX{} interface, this macro +% also accepts \LaTeX{} interface options (see Section <#sec:latex-options>) +% as its optional argument. These options will only influence this \acro{YAML} +% document. +% +% The following example \LaTeX{} code showcases the usage of the +% \mref{yamlInput} macro: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \begin{document} +% \yamlInput[smartEllipses]{hello.yml} +% \end{document} +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \begin{document} +% \markdownInput[ +% jekyllData, +% expectJekyllData, +% ensureJekyllData, +% smartEllipses, +% ]{hello.yml} +% \end{document} +% ``````` +% +%### Using \LaTeX{} hooks with the Markdown package +% +% \LaTeX{} provides an intricate hook management system that allows users to +% insert extra material before and after certain \TeX{} macros and \LaTeX{} +% environments, among other things. [@mittelbach24, Section 3.1.2] +% +% The Markdown package is compatible with hooks and allows the use of hooks +% to insert extra material before \TeX{} commands and before/after \LaTeX{} +% environments without restriction: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \begin{document} +% \AddToHook{cmd/markdownRendererEmphasis/before}{emphasis: } +% \AddToHook{env/markdown/before}{<markdown>} +% \AddToHook{env/markdown/after}{</markdown>} +% \begin{markdown} +% foo _bar_ baz! +% \end{markdown} +% \end{document} +% ``` +% +% Processing the above example with \LaTeX{} will produce the text +% “<markdown>foo emphasis: _bar_ baz!</markdown>”, as expected. +% +% However, using hooks to insert extra material after \TeX{} commands only works +% for commands with a fixed number of parameters that don't use currying. +% +% If, in the above example, you explicitly defined the renderer for emphasis +% using \mref{markdownSetup} or another method that does not use currying, then +% you would be able to insert extra material even after the renderer: +% +% ``` tex +% \documentclass{article} +% \usepackage{markdown} +% \markdownSetup{renderers={emphasis={\emph{#1}}}} +% \begin{document} +% \AddToHook{cmd/markdownRendererEmphasis/before}{<emphasis>} +% \AddToHook{cmd/markdownRendererEmphasis/after}{</emphasis>} +% \AddToHook{env/markdown/before}{<markdown>} +% \AddToHook{env/markdown/after}{</markdown>} +% \begin{markdown} +% foo _bar_ baz! +% \end{markdown} +% \end{document} +% ``` +% +% Processing the above example with \LaTeX{} will produce the text +% “<markdown>foo <emphasis>_bar_</emphasis> baz!</markdown>”, as expected. +% +% However, the default renderer for emphasis uses currying and calls the +% renderer prototype in a way that prevents the use of hooks to insert extra +% material after the renderer, see Section~<#sec:emphasis-renderers>. In such +% a case, you would need to redefine the renderer in a way that does not use +% currying before you would be able to use hooks to insert extra material +% after it. +% +% Hooks also cannot be used to insert extra material after renderers with a +% variable number of parameters such as the renderer for tables, see +% Section~<#sec:table-renderer>. +% %### Options {#latex-options} % % The \LaTeX{} options are represented by a comma-delimited list of @@ -21600,7 +22602,7 @@ following code in our \LaTeX{} document: We can also set all plain \TeX{} options directly from \LaTeX{}. For example, to set the `\markdownOptionInputTempFileName` plain \TeX{} option to -`helper-script.lua`, we would inclde the following code in our \LaTeX{} +`helper-script.lua`, we would include the following code in our \LaTeX{} document: ``` tex @@ -21947,6 +22949,7 @@ following image: % \begin{macrocode} \AtEndOfPackage{ \markdownLaTeXLoadedtrue +} % \end{macrocode} % \begin{markdown} % @@ -21957,17 +22960,39 @@ following image: % % \end{markdown} % \begin{macrocode} - \markdownIfOption{noDefaults}{}{ - \markdownSetup{theme=witiko/markdown/defaults} +\ExplSyntaxOn +\str_if_eq:VVT + \c_@@_top_layer_tl + \c_@@_option_layer_latex_tl + { + \ExplSyntaxOff + \AtEndOfPackage + { + \@@_if_option:nF + { noDefaults } + { + \@@_if_option:nTF + { experimental } + { + \@@_setup:n + { theme = witiko/markdown/defaults@experimental } + } + { + \@@_setup:n + { theme = witiko/markdown/defaults } + } + } + } + \ExplSyntaxOn } -} +\ExplSyntaxOff % \end{macrocode} % \iffalse %</latex> %<*themes-witiko-markdown-defaults-latex> % \fi % \begin{macrocode} -\ProvidesPackage{markdownthemewitiko_markdown_defaults}[2024/01/03]% +\ProvidesPackage{markdownthemewitiko_markdown_defaults}[2024/10/29]% % \end{macrocode} % \iffalse %</themes-witiko-markdown-defaults-latex> @@ -22080,16 +23105,22 @@ following text: % \noindent It is expected that the special plain \TeX{} characters have the % expected category codes, when `\input`ting the file. % -%### Typesetting Markdown -% The interface exposes the \mdef{startmarkdown} and \mdef{stopmarkdown} macro -% pair for the typesetting of a markdown document fragment, and defines the -% \mdef{inputmarkdown} macro. +%### Typesetting Markdown and YAML +% +% The interface exposes the \mdef{startmarkdown}, \mdef{stopmarkdown}, +% \mdef{startyaml}, \mdef{stopyaml}, \mdef{inputmarkdown}, and \mdef{inputyaml} +% macros. +% +%#### Typesetting Markdown and YAML directly +% +% The \mref{startmarkdown} and \mref{stopmarkdown} macros are aliases for the +% macros \mref{markdownBegin} and \mref{markdownEnd} exposed by the plain +% \TeX{} interface. % % \end{markdown} % \begin{macrocode} \let\startmarkdown\relax \let\stopmarkdown\relax -\let\inputmarkdown\relax % \end{macrocode} % \par % \begin{markdown} @@ -22098,12 +23129,12 @@ following text: % \mref{stopmarkdown} macro to produce special effects before and after the % markdown block. % -% Note that the \mref{startmarkdown} and \mref{stopmarkdown} macros -% are subject to the same limitations as the \mref{markdownBegin} and -% \mref{markdownEnd} macros exposed by the plain \TeX{} interface. +% The macros \mref{startmarkdown} and \mref{stopmarkdown} are subject to the +% same limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros. % % The following example \Hologo{ConTeXt} code showcases the usage of the % \mref{startmarkdown} and \mref{stopmarkdown} macros: +% % ``` tex % \usemodule[t][markdown] % \starttext @@ -22113,22 +23144,117 @@ following text: % \stoptext % ``````` % -% The \mref{inputmarkdown} macro accepts a single mandatory parameter -% containing the filename of a markdown document and expands to the result of -% the conversion of the input markdown document to plain \TeX{}. Unlike the -% \mref{markdownInput} macro provided by the plain \TeX{} interface, this macro -% also accepts \Hologo{ConTeXt} interface options (see Section -% <#sec:context-options>) as its optional argument. These options will only -% influnce this markdown document. +% The \mref{startyaml} and \mref{stopyaml} macros are aliases for the macros +% \mref{yamlBegin} and \mref{yamlEnd} exposed by the plain \TeX{} interface. +% +% \end{markdown} +% \begin{macrocode} +\let\startyaml\relax +\let\stopyaml\relax +% \end{macrocode} +% \par +% \begin{markdown} +% +% You may prepend your own code to the \mref{startyaml} macro and append your +% own code to the \mref{stopyaml} macro to produce special effects before and +% after the \acro{YAML} document. +% +% The macros \mref{startyaml} and \mref{stopyaml} are subject to the same +% limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros. +% +% The following example \Hologo{ConTeXt} code showcases the usage of the +% \mref{startyaml} and \mref{stopyaml} macros: +% +% ``` tex +% \usemodule[t][markdown] +% \starttext +% \startyaml +% title: _Hello_ **world** ... +% author: John Doe +% \stopyaml +% \stoptext +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \usemodule[t][markdown] +% \starttext +% \setupyaml[jekyllData, expectJekyllData, ensureJekyllData] +% \startyaml +% title: _Hello_ **world** ... +% author: John Doe +% \stopyaml +% \stoptext +% ``````` +% +%#### Typesetting Markdown and YAML from external documents +% +% The \mref{inputmarkdown} macro aliases the macro \mref{markdownInput} exposed +% by the plain \TeX{} interface. +% +% \end{markdown} +% \begin{macrocode} +\let\inputmarkdown\relax +% \end{macrocode} +% \par +% \begin{markdown} +% +% Furthermore, the \mref{inputmarkdown} macro also accepts \Hologo{ConTeXt} +% interface options (see Section <#sec:context-options>) as its optional +% argument. These options will only influence this markdown document. +% +% The following example \Hologo{ConTeXt} code showcases the usage of the +% \mref{inputmarkdown} macro: % -% The following example \LaTeX{} code showcases the usage of the -% \mref{markdownInput} macro: % ``` tex % \usemodule[t][markdown] % \starttext -% % ... % \inputmarkdown[smartEllipses]{hello.md} -% % ... +% \stoptext +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \usemodule[t][markdown] +% \starttext +% \setupmarkdown[smartEllipses] +% \inputmarkdown{hello.md} +% \stoptext +% ``````` +% +% The \mref{inputyaml} macro aliases the macro \mref{yamlInput} exposed by the +% plain \TeX{} interface. +% +% \end{markdown} +% \begin{macrocode} +\let\inputyaml\relax +% \end{macrocode} +% \par +% \begin{markdown} +% +% Furthermore, the \mref{inputyaml} macro also accepts \Hologo{ConTeXt} +% interface options (see Section <#sec:context-options>) as its optional +% argument. These options will only influence this \acro{YAML} document. +% +% The following example \Hologo{ConTeXt} code showcases the usage of the +% \mref{inputyaml} macro: +% +% ``` tex +% \usemodule[t][markdown] +% \starttext +% \inputyaml[smartEllipses]{hello.yml} +% \stoptext +% ``````` +% +% The above code has the same effect as the below code: +% +% ``` tex +% \usemodule[t][markdown] +% \starttext +% \setupyaml[smartEllipses] +% \inputyaml{hello.yml} % \stoptext % ``````` % @@ -22158,7 +23284,17 @@ following text: \@@_setup:n { #1 } } -\ExplSyntaxOff +% \end{macrocode} +% \begin{markdown} +% +% The command \mdef{setupyaml} is also available as an alias for +% the command \mref{setupmarkdown}. +% +% \end{markdown} +% \begin{macrocode} +\cs_gset_eq:NN + \setupyaml + \setupmarkdown % \end{macrocode} % \begin{markdown} % @@ -22169,7 +23305,6 @@ following text: % % \end{markdown} % \begin{macrocode} -\ExplSyntaxOn \cs_new:Nn \@@_caseless:N { \regex_replace_all:nnN @@ -22249,14 +23384,14 @@ Built-in \Hologo{ConTeXt} themes provided with the Markdown package include: % \end{markdown} % \iffalse %</manual-options> -%<*themes-witiko-markdown-defaults-context> +%<*themes-witiko-markdown-defaults-ctx> % \fi % \begin{macrocode} \startmodule[markdownthemewitiko_markdown_defaults] \unprotect % \end{macrocode} % \iffalse -%</themes-witiko-markdown-defaults-context> +%</themes-witiko-markdown-defaults-ctx> %<*manual-options> % \fi % \begin{markdown} @@ -22317,9 +23452,17 @@ local P, R, S, V, C, Cg, Cb, Cmt, Cc, Ct, B, Cs, Cp, any = % `lunamark/util.lua` file in the Lunamark Lua module. % % \end{markdown} +% \iffalse +%</lua> +%<*lua,lua-loader> +% \fi % \begin{macrocode} local util = {} % \end{macrocode} +% \iffalse +%</lua,lua-loader> +%<*lua> +% \fi % \par % \begin{markdown} % @@ -22334,13 +23477,17 @@ function util.err(msg, exit_code) os.exit(exit_code or 1) end % \end{macrocode} +% \iffalse +%</lua> +%<*lua,lua-loader> +% \fi % \par % \begin{markdown} % -% The \luamdef{util.cache} method computes the digest of `string` and -% `salt`, adds the `suffix` and looks into the directory `dir`, whether a -% file with such a name exists. If it does not, it gets created with -% `transform(string)` as its content. The filename is then returned. +% The \luamdef{util.cache} method used `dir`, `string`, `salt`, and `suffix` +% to determine a pathname. If a file with such a pathname does not exists, +% it gets created with `transform(string)` as its content. Regardless, the +% pathname is then returned. % % \end{markdown} % \begin{macrocode} @@ -22348,7 +23495,7 @@ function util.cache(dir, string, salt, transform, suffix) local digest = md5.sumhexa(string .. (salt or "")) local name = util.pathname(dir, digest .. suffix) local file = io.open(name, "r") - if file == nil then -- If no cache entry exists, then create a new one. + if file == nil then -- If no cache entry exists, create a new one. file = assert(io.open(name, "w"), [[Could not open file "]] .. name .. [[" for writing]]) local result = string @@ -22361,6 +23508,10 @@ function util.cache(dir, string, salt, transform, suffix) return name end % \end{macrocode} +% \iffalse +%</lua,lua-loader> +%<*lua> +% \fi % \par % \begin{markdown} % @@ -22559,7 +23710,7 @@ end % Given a table `char_escapes` mapping escapable characters to escaped % strings and optionally a table `string_escapes` mapping escapable strings % to escaped strings, the \luamdef{util.escaper} method returns an escaper -% function that escapes all occurances of escapable strings and characters (in +% function that escapes all occurrences of escapable strings and characters (in % this order). % % The method uses \pkg{LPeg}, which is faster than the Lua `string.gsub` @@ -22588,7 +23739,7 @@ function util.escaper(char_escapes, string_escapes) % \begin{markdown} % If `string_escapes` is provided, turn `escapable` into the % $$\sum^^B{(`k`, `v`)\in`string_escapes`}`P(k) / v` + `escapable`$$ -% capture that replaces any occurance of the string `k` with the string +% capture that replaces any occurrence of the string `k` with the string % `v` for each $(`k`, `v`)\in`string_escapes`$. Note that the pattern % summation is not commutative and its operands are inspected in the % summation order during the matching. As a corrolary, the strings always @@ -22619,6 +23770,10 @@ function util.escaper(char_escapes, string_escapes) end end % \end{macrocode} +% \iffalse +%</lua> +%<*lua,lua-loader> +% \fi % \par % \begin{markdown} % @@ -22638,6 +23793,56 @@ end % \par % \begin{markdown} % +% The \luamdef{util.salt} method produces cryptographic salt out of a table of +% options `options`. +% +% \end{markdown} +% \begin{macrocode} +function util.salt(options) + local opt_string = {} + for k, _ in pairs(defaultOptions) do + local v = options[k] + if type(v) == "table" then + for _, i in ipairs(v) do + opt_string[#opt_string+1] = k .. "=" .. tostring(i) + end +% \end{macrocode} +% \begin{markdown} +% +% The \Opt{cacheDir} option is disregarded. +% +% \end{markdown} +% \begin{macrocode} + elseif k ~= "cacheDir" then + opt_string[#opt_string+1] = k .. "=" .. tostring(v) + end + end + table.sort(opt_string) + local salt = table.concat(opt_string, ",") + .. "," .. metadata.version + return salt +end +% \end{macrocode} +% \par +% \begin{markdown} +% +% The \luamdef{util.warning} method produces a warning `s` that is unrelated to +% any specific markdown text being processed. For warnings that are specific to +% a markdown text, use \luamref{writer->warning} function. +% +% \end{markdown} +% \begin{macrocode} +function util.warning(s) + io.stderr:write("Warning: " .. s .. "\n") +end +% \end{macrocode} +% \iffalse +%</lua,lua-loader> +%<*lua> +% \fi +% \par +% \begin{markdown} +% %### HTML Entities % This section documents the \acro{HTML} entities recognized by the % markdown reader. These functions are encapsulated in the `entities` @@ -24954,15 +26159,6 @@ function M.writer.new(options) % \par % \begin{markdown} % -% Define \luamdef{writer->suffix} as the suffix of the produced cache files. -% -% \end{markdown} -% \begin{macrocode} - self.suffix = ".tex" -% \end{macrocode} -% \par -% \begin{markdown} -% % Define \luamdef{writer->space} as the output format of a space character. % % \end{markdown} @@ -25007,19 +26203,6 @@ function M.writer.new(options) % \par % \begin{markdown} % -% Define \luamdef{writer->pack} as a function that will take the filename -% `name` of the output file prepared by the reader and transform it to the -% output format. -% -% \end{markdown} -% \begin{macrocode} - function self.pack(name) - return [[\input{]] .. name .. [[}\relax]] - end -% \end{macrocode} -% \par -% \begin{markdown} -% % Define \luamdef{writer->interblocksep} as the output format of a block % element separator. % @@ -25123,13 +26306,17 @@ function M.writer.new(options) ["{"] = "\\markdownRendererLeftBrace{}", ["}"] = "\\markdownRendererRightBrace{}", ["\\"] = "\\markdownRendererBackslash{}", + ["\r"] = " ", + ["\n"] = " ", } self.escaped_minimal_strings = { - ["^^"] = "\\markdownRendererCircumflex\\markdownRendererCircumflex ", + ["^^"] = "\\markdownRendererCircumflex" + .. "\\markdownRendererCircumflex ", ["☒"] = "\\markdownRendererTickedBox{}", ["⌛"] = "\\markdownRendererHalfTickedBox{}", ["☐"] = "\\markdownRendererUntickedBox{}", - [entities.hex_entity('FFFD')] = "\\markdownRendererReplacementCharacter{}", + [entities.hex_entity('FFFD')] + = "\\markdownRendererReplacementCharacter{}", } % \end{macrocode} % \par @@ -25164,7 +26351,8 @@ function M.writer.new(options) ["^"] = "\\markdownRendererCircumflex{}", ["~"] = "\\markdownRendererTilde{}", ["|"] = "\\markdownRendererPipe{}", - [entities.hex_entity('0000')] = "\\markdownRendererReplacementCharacter{}", + [entities.hex_entity('0000')] + = "\\markdownRendererReplacementCharacter{}", } % \end{macrocode} % \par @@ -25172,9 +26360,9 @@ function M.writer.new(options) % % Use the \luamref{writer->escaped_chars}, \luamref{writer->escaped_uri_chars}, % and \luamref{writer->escaped_minimal_strings} tables to create the -% \luamdef{writer->escape_typographic_text}, -% \luamdef{writer->escape_programmatic_text}, and -% \luamdef{writer->escape_minimal} escaper functions. +% \luamdef{escape_typographic_text}, +% \luamdef{escape_programmatic_text}, and +% \luamdef{escape_minimal} local escaper functions. % % \end{markdown} % \begin{macrocode} @@ -25226,6 +26414,34 @@ function M.writer.new(options) % \par % \begin{markdown} % +% Define \luamdef{writer->warning} as a function that will transform an input +% warning `t` with optional more warning text `m` to the output format. +% +% \end{markdown} +% \begin{macrocode} + 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 text `t` with optional more error text `m` to the output format. +% +% \end{markdown} +% \begin{macrocode} + 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 +% \begin{markdown} +% % Define \luamdef{writer->code} as a function that will transform an input % inline code span `s` with optional attributes `attributes` to the output % format. @@ -25425,7 +26641,8 @@ function M.writer.new(options) % \begin{macrocode} function self.inline_html_tag(contents) if self.flatten_inlines then return contents end - return {"\\markdownRendererInlineHtmlTag{",self.string(contents),"}"} + return {"\\markdownRendererInlineHtmlTag{", + self.string(contents),"}"} end % \end{macrocode} % \par @@ -25525,7 +26742,23 @@ function M.writer.new(options) % \end{markdown} % \begin{macrocode} function self.document(d) - local buf = {"\\markdownRendererDocumentBegin\n", d} + local buf = {"\\markdownRendererDocumentBegin\n"} + + -- warn against the `hybrid` option + if options.hybrid then + local text = "The `hybrid` option has been soft-deprecated." + local more = "Consider using one of the following better options " + .. "for mixing TeX and markdown: `contentBlocks`, " + .. "`rawAttribute`, `texComments`, `texMathDollars`, " + .. "`texMathSingleBackslash`, and " + .. "`texMathDoubleBackslash`. " + .. "For more information, see the user manual at " + .. "<https://witiko.github.io/markdown/>." + table.insert(buf, self.warning(text, more)) + end + + -- insert the text of the document + table.insert(buf, d) -- pop all attributes table.insert(buf, self.pop_attributes()) @@ -25716,8 +26949,10 @@ function M.writer.new(options) % \begin{macrocode} function self.push_attributes(attribute_type, attributes, start_output, end_output) - local attribute_type_level = self.attribute_type_levels[attribute_type] - self.attribute_type_levels[attribute_type] = attribute_type_level + 1 + local attribute_type_level + = self.attribute_type_levels[attribute_type] + self.attribute_type_levels[attribute_type] + = attribute_type_level + 1 -- index attributes in a hash table for easy lookup attributes = attributes or {} @@ -25772,8 +27007,10 @@ function M.writer.new(options) local attributes, _, end_output current_attribute_type, attributes, _, end_output = table.unpack( self.active_attributes[#self.active_attributes]) - local attribute_type_level = self.attribute_type_levels[current_attribute_type] - self.attribute_type_levels[current_attribute_type] = attribute_type_level - 1 + local attribute_type_level + = self.attribute_type_levels[current_attribute_type] + self.attribute_type_levels[current_attribute_type] + = attribute_type_level - 1 if self.is_writing and end_output ~= nil then table.insert(buf, end_output) end @@ -25807,7 +27044,8 @@ function M.writer.new(options) local prev_space = false local letter_found = false local normalized_s = s - if not options.unicodeNormalization or options.unicodeNormalizationForm ~= "nfc" then + if not options.unicodeNormalization + or options.unicodeNormalizationForm ~= "nfc" then normalized_s = uni_algos.normalize.NFC(normalized_s) end @@ -25824,7 +27062,8 @@ function M.writer.new(options) end end - -- Remove all non-alphanumeric characters, except underscores, hyphens, and periods. + -- Remove all non-alphanumeric characters, except underscores, + -- hyphens, and periods. if not unicode.utf8.match(char, "[%w_%-%.%s]") then goto continue end @@ -25852,7 +27091,8 @@ function M.writer.new(options) table.remove(buffer) end - local identifier = #buffer == 0 and "section" or table.concat(buffer, "") + local identifier = #buffer == 0 and "section" + or table.concat(buffer, "") return identifier end % \end{macrocode} @@ -25867,7 +27107,8 @@ function M.writer.new(options) local prev_space = false local letter_found = false local normalized_s = s - if not options.unicodeNormalization or options.unicodeNormalizationForm ~= "nfc" then + if not options.unicodeNormalization + or options.unicodeNormalizationForm ~= "nfc" then normalized_s = uni_algos.normalize.NFC(normalized_s) end @@ -25884,7 +27125,8 @@ function M.writer.new(options) end end - -- Remove all non-alphanumeric characters, except underscores and hyphens. + -- Remove all non-alphanumeric characters, except underscores + -- and hyphens. if not unicode.utf8.match(char, "[%w_%-%s]") then prev_space = false goto continue @@ -25913,7 +27155,8 @@ function M.writer.new(options) table.remove(buffer) end - local identifier = #buffer == 0 and "section" or table.concat(buffer, "") + local identifier = #buffer == 0 and "section" + or table.concat(buffer, "") return identifier end % \end{macrocode} @@ -25952,9 +27195,11 @@ function M.writer.new(options) table.insert(auto_identifiers, create_auto_identifier(flat_text)) end if self.options.gfmAutoIdentifiers then - table.insert(auto_identifiers, create_gfm_auto_identifier(flat_text)) + table.insert(auto_identifiers, + create_gfm_auto_identifier(flat_text)) end - local normalized_attributes = normalize_attributes(attributes, auto_identifiers) + local normalized_attributes = normalize_attributes(attributes, + auto_identifiers) -- push attributes for the new section local start_output = {} @@ -25970,7 +27215,8 @@ function M.writer.new(options) -- render the heading and its attributes if self.is_writing and #normalized_attributes > 0 then - table.insert(buf, "\\markdownRendererHeaderAttributeContextBegin\n") + table.insert(buf, + "\\markdownRendererHeaderAttributeContextBegin\n") table.insert(buf, self.attributes(normalized_attributes, false)) end @@ -26128,8 +27374,13 @@ parsers.fail = P(false) parsers.internal_punctuation = S(":;,.?") parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") + % \end{macrocode} % \par +% \iffalse +%</lua> +%<*lua-unicode-data-generator> +% \fi % \begin{markdown} % %### Unicode punctuation @@ -26141,36 +27392,143 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") % [unicode-punctuation]: https://spec.commonmark.org/0.31.2/#unicode-punctuation-character % (CommonMark Spec, Version 0.31.2 (2024-01-28)) % +% All code from this section will be executed during the compilation of +% the Markdown package and the standard output will be stored in a file +% named `markdown-unicode-data.lua` with the precompiled parser of Unicode +% punctuation. +% % \end{markdown} % \begin{macrocode} -parsers.punctuation = {} -(function() - local pathname = kpse.lookup("UnicodeData.txt") +;(function() + local pathname = assert(kpse.find_file("UnicodeData.txt"), + [[Could not locate file "UnicodeData.txt"]]) local file = assert(io.open(pathname, "r"), [[Could not open file "UnicodeData.txt"]]) +% \end{macrocode} +% \par +% \begin{markdown} +% +% In order to minimize the size and speed of the parser, we will first +% construct a prefix tree of UTF-8 encodings for all codepoints of a +% given code length. +% +% \end{markdown} +% \begin{macrocode} + local prefix_trees = {} for line in file:lines() do local codepoint, major_category = line:match("^(%x+);[^;]*;(%a)") if major_category == "P" or major_category == "S" then local code = unicode.utf8.char(tonumber(codepoint, 16)) - if parsers.punctuation[#code] == nil then - parsers.punctuation[#code] = parsers.fail + if prefix_trees[#code] == nil then + prefix_trees[#code] = {} end - local code_parser = parsers.succeed + local node = prefix_trees[#code] for i = 1, #code do local byte = code:sub(i, i) - local byte_parser = S(byte) - code_parser = code_parser - * byte_parser + if i < #code then + if node[byte] == nil then + node[byte] = {} + end + node = node[byte] + else + table.insert(node, byte) + end end - parsers.punctuation[#code] = parsers.punctuation[#code] - + code_parser end end assert(file:close()) + +% \end{macrocode} +% \par +% \begin{markdown} +% +% Next, we will construct a parser out of the prefix tree. +% +% \end{markdown} +% \begin{macrocode} + local function depth_first_search(node, path, visit, leave) + visit(node, path) + for label, child in pairs(node) do + if type(child) == "table" then + depth_first_search(child, path .. label, visit, leave) + else + visit(child, path) + end + end + leave(node, path) + end + + print("M.punctuation = {}") + print("local S = lpeg.S") + print("-- luacheck: push no max line length") + for length, prefix_tree in pairs(prefix_trees) do + local subparsers = {} + depth_first_search(prefix_tree, "", function(node, path) + if type(node) == "string" then + local suffix + if node == "]" then + suffix = "S('" .. node .. "')" + else + suffix = "S([[" .. node .. "]])" + end + if subparsers[path] ~= nil then + subparsers[path] = subparsers[path] .. " + " .. suffix + else + subparsers[path] = suffix + end + end + end, function(_, path) + if #path > 0 then + local byte = path:sub(#path, #path) + local parent_path = path:sub(1, #path-1) + if subparsers[path] ~= nil then + local suffix + if byte == "]" then + suffix = "S('" .. byte .. "')" + else + suffix = "S([[" .. byte .. "]])" + end + suffix = suffix .. " * (" .. subparsers[path] .. ")" + if subparsers[parent_path] ~= nil then + subparsers[parent_path] = subparsers[parent_path] + .. " + " .. suffix + else + subparsers[parent_path] = suffix + end + end + else + print("M.punctuation[" .. length .. "] = " .. subparsers[path]) + end + end) + end + print("-- luacheck: pop") end)() +print("return M") +% \end{macrocode} +% \par +% \iffalse +%</lua-unicode-data-generator> +%<*lua> +% \fi +% \begin{markdown} +% +% Back in the Markdown package, we will load the precompiled parser of +% Unicode punctuation. +% +% \end{markdown} +% \begin{macrocode} +local unicode_data = require("markdown-unicode-data") +if metadata.version ~= unicode_data.metadata.version then + util.warning( + "markdown.lua " .. metadata.version .. " used with " .. + "markdown-unicode-data.lua " .. unicode_data.metadata.version .. "." + ) +end +parsers.punctuation = unicode_data.punctuation parsers.escapable = parsers.ascii_punctuation -parsers.anyescaped = parsers.backslash / "" * parsers.escapable +parsers.anyescaped = parsers.backslash / "" + * parsers.escapable + parsers.any parsers.spacechar = S("\t ") @@ -26189,14 +27547,18 @@ parsers.linechar = P(1 - parsers.newline) parsers.blankline = parsers.optionalspace * parsers.newline / "\n" parsers.blanklines = parsers.blankline^0 -parsers.skipblanklines = (parsers.optionalspace * parsers.newline)^0 +parsers.skipblanklines = ( parsers.optionalspace + * parsers.newline)^0 parsers.indentedline = parsers.indent /"" - * C(parsers.linechar^1 * parsers.newline^-1) + * C( parsers.linechar^1 + * parsers.newline^-1) parsers.optionallyindentedline = parsers.indent^-1 /"" - * C(parsers.linechar^1 * parsers.newline^-1) + * C( parsers.linechar^1 + * parsers.newline^-1) parsers.sp = parsers.spacing^0 parsers.spnl = parsers.optionalspace - * (parsers.newline * parsers.optionalspace)^-1 + * ( parsers.newline + * parsers.optionalspace)^-1 parsers.line = parsers.linechar^0 * parsers.newline parsers.nonemptyline = parsers.line - parsers.blankline % \end{macrocode} @@ -26279,7 +27641,8 @@ local function update_indent_table(indent_table, new_indent, add) if add then indent_table.indents[#indent_table.indents + 1] = new_indent else - if indent_table.indents[#indent_table.indents].name == new_indent.name then + if indent_table.indents[#indent_table.indents].name + == new_indent.name then indent_table.indents[#indent_table.indents] = nil end end @@ -26295,10 +27658,12 @@ end % \end{markdown} % \begin{macrocode} local function remove_indent(name) - local function remove_indent_level(s, i, indent_table) -- luacheck: ignore s i - indent_table = update_indent_table(indent_table, {name=name}, false) - return true, indent_table - end + local remove_indent_level = + function(s, i, indent_table) -- luacheck: ignore s i + indent_table = update_indent_table(indent_table, {name=name}, + false) + return true, indent_table + end return Cg(Cmt(Cb("indent_info"), remove_indent_level), "indent_info") end @@ -26314,7 +27679,8 @@ end % % \end{markdown} % \begin{macrocode} -local function process_starter_spacing(indent, spacing, minimum, left_strip_length) +local function process_starter_spacing(indent, spacing, + minimum, left_strip_length) left_strip_length = left_strip_length or 0 local count = 0 @@ -26351,14 +27717,16 @@ local function process_starter_spacing(indent, spacing, minimum, left_strip_leng minimum_remainder = minimum_remainder .. character elseif (count >= minimum) then minimum_found = true - minimum_remainder = minimum_remainder .. string.rep(" ", count - minimum) + minimum_remainder = minimum_remainder + .. string.rep(" ", count - minimum) end if (code_started) then code_start = code_start .. character elseif (count >= minimum + 4) then code_started = true - code_start = code_start .. string.rep(" ", count - (minimum + 4)) + code_start = code_start + .. string.rep(" ", count - (minimum + 4)) end end end @@ -26425,7 +27793,8 @@ end % % \end{markdown} % \begin{macrocode} -local function process_starter_indent(_, _, indent_table, starter, is_blank, indent_type, breakable) +local function process_starter_indent(_, _, indent_table, starter, + is_blank, indent_type, breakable) local last_trail = starter[1] local delimiter = starter[2] local raw_new_trail = starter[3] @@ -26453,11 +27822,13 @@ local function process_starter_indent(_, _, indent_table, starter, is_blank, ind local last_trail_length = #last_trail local delimiter_length = total_delimiter_length(delimiter) - local total_indent_level = preceding_indentation + last_trail_length + delimiter_length + local total_indent_level = preceding_indentation + last_trail_length + + delimiter_length local sp = {} if not is_blank then - sp = process_starter_spacing(total_indent_level, raw_new_trail, 0, 1) + sp = process_starter_spacing(total_indent_level, raw_new_trail, + 0, 1) end local del_trail_length = sp.left_total_stripped @@ -26467,12 +27838,17 @@ local function process_starter_indent(_, _, indent_table, starter, is_blank, ind del_trail_length = del_trail_length + #sp.remainder end - local indent_length = last_trail_length + delimiter_length + del_trail_length + local indent_length = last_trail_length + delimiter_length + + del_trail_length local new_indent_info = {name=indent_type, length=indent_length} - indent_table = update_indent_table(indent_table, new_indent_info, true) - indent_table = add_trail(indent_table, {is_code=sp.is_code, remainder=sp.remainder, total_length=sp.total_length, - full_remainder=sp.full_remainder}) + indent_table = update_indent_table(indent_table, new_indent_info, + true) + indent_table = add_trail(indent_table, + {is_code=sp.is_code, + remainder=sp.remainder, + total_length=sp.total_length, + full_remainder=sp.full_remainder}) return true, indent_table end @@ -26490,7 +27866,8 @@ local function decode_pattern(name) delimeter = parsers.more end - return C(parsers.optionalspace) * C(delimeter) * C(parsers.optionalspace) * Cp() + return C(parsers.optionalspace) * C(delimeter) + * C(parsers.optionalspace) * Cp() end % \end{macrocode} @@ -26531,7 +27908,8 @@ end % % \end{markdown} % \begin{macrocode} -local function traverse_indent(s, i, indent_table, is_optional, is_blank, current_line_indents) +local function traverse_indent(s, i, indent_table, is_optional, + is_blank, current_line_indents) local new_index = i local preceding_indentation = 0 @@ -26550,12 +27928,17 @@ local function traverse_indent(s, i, indent_table, is_optional, is_blank, curren -- match decoded pattern local new_indent_info = lpeg.match(Ct(pattern), s, new_index) if new_indent_info == nil then - local blankline_end = lpeg.match(Ct(parsers.blankline * Cg(Cp(), "pos")), s, new_index) - if is_optional or not indent_table.ignore_blockquote_blank or not blankline_end then - return is_optional, new_index, current_trail, current_line_indents + local blankline_end = lpeg.match( + Ct(parsers.blankline * Cg(Cp(), "pos")), s, new_index) + if is_optional or not indent_table.ignore_blockquote_blank + or not blankline_end then + return is_optional, new_index, current_trail, + current_line_indents end - return traverse_indent(s, tonumber(blankline_end.pos), indent_table, is_optional, is_blank, current_line_indents) + return traverse_indent(s, tonumber(blankline_end.pos), + indent_table, is_optional, is_blank, + current_line_indents) end local raw_last_trail = new_indent_info[1] @@ -26568,13 +27951,15 @@ local function traverse_indent(s, i, indent_table, is_optional, is_blank, curren -- check previous trail if not space_only and next(current_trail) == nil then local sp = process_starter_spacing(0, raw_last_trail, 0, 0) - current_trail = {is_code=sp.is_code, remainder=sp.remainder, total_length=sp.total_length, + current_trail = {is_code=sp.is_code, remainder=sp.remainder, + total_length=sp.total_length, full_remainder=sp.full_remainder} end if next(current_trail) ~= nil then if not space_only and current_trail.is_code then - return is_optional, new_index, current_trail, current_line_indents + return is_optional, new_index, current_trail, + current_line_indents end if current_trail.internal_remainder ~= nil then raw_last_trail = current_trail.internal_remainder @@ -26589,7 +27974,8 @@ local function traverse_indent(s, i, indent_table, is_optional, is_blank, curren raw_last_trail_length = #raw_last_trail end - local total_indent_level = preceding_indentation + raw_last_trail_length + delimiter_length + local total_indent_level = preceding_indentation + + raw_last_trail_length + delimiter_length local spacing_to_process local minimum = 0 @@ -26603,13 +27989,17 @@ local function traverse_indent(s, i, indent_table, is_optional, is_blank, curren minimum = value.length end - local sp = process_starter_spacing(total_indent_level, spacing_to_process, minimum, left_strip_length) + local sp = process_starter_spacing(total_indent_level, + spacing_to_process, minimum, + left_strip_length) if space_only and not sp.is_minimum then - return is_optional or (is_blank and blank_starter <= index), new_index, current_trail, current_line_indents + return is_optional or (is_blank and blank_starter <= index), + new_index, current_trail, current_line_indents end - local indent_length = raw_last_trail_length + delimiter_length + sp.left_total_stripped + local indent_length = raw_last_trail_length + delimiter_length + + sp.left_total_stripped -- update info for the next pattern if not space_only then @@ -26618,8 +28008,10 @@ local function traverse_indent(s, i, indent_table, is_optional, is_blank, curren preceding_indentation = preceding_indentation + value.length end - current_trail = {is_code=sp.is_code, remainder=sp.remainder, internal_remainder=sp.minimum_remainder, - total_length=sp.total_length, full_remainder=sp.full_remainder} + current_trail = {is_code=sp.is_code, remainder=sp.remainder, + internal_remainder=sp.minimum_remainder, + total_length=sp.total_length, + full_remainder=sp.full_remainder} current_line_indents[#current_line_indents + 1] = new_indent_info new_index = next_index @@ -26647,34 +28039,36 @@ end % % \end{markdown} % \begin{macrocode} -local function check_trail_joined(s, i, indent_table, spacing, expect_code, omit_remainder) -- luacheck: ignore s i - local is_code - local remainder +local check_trail_joined = + function(s, i, indent_table, -- luacheck: ignore s i + spacing, expect_code, omit_remainder) + local is_code + local remainder - if has_trail(indent_table) then - local trail = indent_table.trail - is_code = trail.is_code - if is_code then - remainder = trail.remainder - else - remainder = trail.full_remainder - end - else - local sp = process_starter_spacing(0, spacing, 0, 0) - is_code = sp.is_code - if is_code then - remainder = sp.remainder + if has_trail(indent_table) then + local trail = indent_table.trail + is_code = trail.is_code + if is_code then + remainder = trail.remainder + else + remainder = trail.full_remainder + end else - remainder = sp.full_remainder + local sp = process_starter_spacing(0, spacing, 0, 0) + is_code = sp.is_code + if is_code then + remainder = sp.remainder + else + remainder = sp.full_remainder + end end - end - local result = check_trail(expect_code, is_code) - if omit_remainder then - return result + local result = check_trail(expect_code, is_code) + if omit_remainder then + return result + end + return result, remainder end - return result, remainder -end % \end{macrocode} % \begin{markdown} @@ -26683,22 +28077,24 @@ end % % \end{markdown} % \begin{macrocode} -local function check_trail_length(s, i, indent_table, spacing, min, max) -- luacheck: ignore s i - local trail +local check_trail_length = + function(s, i, indent_table, -- luacheck: ignore s i + spacing, min, max) + local trail - if has_trail(indent_table) then - trail = indent_table.trail - else - trail = process_starter_spacing(0, spacing, 0, 0) - end + if has_trail(indent_table) then + trail = indent_table.trail + else + trail = process_starter_spacing(0, spacing, 0, 0) + end - local total_length = trail.total_length - if total_length == nil then - return false - end + local total_length = trail.total_length + if total_length == nil then + return false + end - return min <= total_length and total_length <= max -end + return min <= total_length and total_length <= max + end % \end{macrocode} % \begin{markdown} @@ -26708,7 +28104,8 @@ end % % \end{markdown} % \begin{macrocode} -local function check_continuation_indentation(s, i, indent_table, is_optional, is_blank) +local function check_continuation_indentation(s, i, indent_table, + is_optional, is_blank) if not has_indents(indent_table) then return true end @@ -26761,27 +28158,29 @@ end % % \end{markdown} % \begin{macrocode} -local function check_trail_type(s, i, trail, spacing, trail_type) -- luacheck: ignore s i - if trail == nil then - trail = process_starter_spacing(0, spacing, 0, 0) - end +local check_trail_type = + function(s, i, -- luacheck: ignore s i + trail, spacing, trail_type) + if trail == nil then + trail = process_starter_spacing(0, spacing, 0, 0) + end - if trail_type == "non-code" then - return check_trail(false, trail.is_code) - end - if trail_type == "code" then - return check_trail(true, trail.is_code) - end - if trail_type == "full-code" then - if (trail.is_code) then - return i, trail.remainder + if trail_type == "non-code" then + return check_trail(false, trail.is_code) + end + if trail_type == "code" then + return check_trail(true, trail.is_code) + end + if trail_type == "full-code" then + if (trail.is_code) then + return i, trail.remainder + end + return i, "" + end + if trail_type == "full-any" then + return i, trail.internal_remainder end - return i, "" - end - if trail_type == "full-any" then - return i, trail.internal_remainder end -end % \end{macrocode} % \begin{markdown} @@ -26790,20 +28189,22 @@ end % % \end{markdown} % \begin{macrocode} -local function trail_freezing(s, i, indent_table, is_freezing) -- luacheck: ignore s i - if is_freezing then - if indent_table.is_trail_frozen then - indent_table.trail = indent_table.frozen_trail +local trail_freezing = + function(s, i, -- luacheck: ignore s i + indent_table, is_freezing) + if is_freezing then + if indent_table.is_trail_frozen then + indent_table.trail = indent_table.frozen_trail + else + indent_table.frozen_trail = indent_table.trail + indent_table.is_trail_frozen = true + end else - indent_table.frozen_trail = indent_table.trail - indent_table.is_trail_frozen = true + indent_table.frozen_trail = nil + indent_table.is_trail_frozen = false end - else - indent_table.frozen_trail = nil - indent_table.is_trail_frozen = false + return true, indent_table end - return true, indent_table -end % \end{macrocode} % \begin{markdown} @@ -26814,53 +28215,59 @@ end % % \end{markdown} % \begin{macrocode} -local function check_continuation_indentation_and_trail(s, i, indent_table, is_optional, is_blank, trail_type, - reset_rem, omit_remainder) - if not has_indents(indent_table) then - local spacing, new_index = lpeg.match(C(parsers.spacechar^0) * Cp(), s, i) - local result, remainder = check_trail_type(s, i, indent_table.trail, spacing, trail_type) - if remainder == nil then +local check_continuation_indentation_and_trail = + function (s, i, indent_table, is_optional, is_blank, trail_type, + reset_rem, omit_remainder) + if not has_indents(indent_table) then + local spacing, new_index = lpeg.match( C(parsers.spacechar^0) + * Cp(), s, i) + local result, remainder = check_trail_type(s, i, + indent_table.trail, spacing, trail_type) + if remainder == nil then + if result then + return new_index + end + return false + end if result then - return new_index + return new_index, remainder end return false end - if result then - return new_index, remainder - end - return false - end - local passes, new_index, current_trail = traverse_indent(s, i, indent_table, is_optional, is_blank) + local passes, new_index, current_trail = traverse_indent(s, i, + indent_table, is_optional, is_blank) + + if passes then + local spacing + if current_trail == nil then + local newer_spacing, newer_index = lpeg.match( + C(parsers.spacechar^0) * Cp(), s, i) + current_trail = process_starter_spacing(0, newer_spacing, 0, 0) + new_index = newer_index + spacing = newer_spacing + else + spacing = current_trail.remainder + end + local result, remainder = check_trail_type(s, new_index, + current_trail, spacing, trail_type) + if remainder == nil or omit_remainder then + if result then + return new_index + end + return false + end - if passes then - local spacing - if current_trail == nil then - local newer_spacing, newer_index = lpeg.match(C(parsers.spacechar^0) * Cp(), s, i) - current_trail = process_starter_spacing(0, newer_spacing, 0, 0) - new_index = newer_index - spacing = newer_spacing - else - spacing = current_trail.remainder - end - local result, remainder = check_trail_type(s, new_index, current_trail, spacing, trail_type) - if remainder == nil or omit_remainder then + if is_blank and reset_rem then + remainder = remove_remainder_if_blank(indent_table, remainder) + end if result then - return new_index + return new_index, remainder end return false end - - if is_blank and reset_rem then - remainder = remove_remainder_if_blank(indent_table, remainder) - end - if result then - return new_index, remainder - end return false end - return false -end % \end{macrocode} % \begin{markdown} @@ -26869,14 +28276,20 @@ end % % \end{markdown} % \begin{macrocode} -parsers.check_trail = Cmt(Cb("indent_info") * C(parsers.spacechar^0) * Cc(false), check_trail_joined) +parsers.check_trail = Cmt( Cb("indent_info") * C(parsers.spacechar^0) + * Cc(false), check_trail_joined) -parsers.check_trail_no_rem = Cmt(Cb("indent_info") * C(parsers.spacechar^0) * Cc(false) * Cc(true), check_trail_joined) +parsers.check_trail_no_rem = Cmt( Cb("indent_info") + * C(parsers.spacechar^0) * Cc(false) + * Cc(true), check_trail_joined) -parsers.check_code_trail = Cmt(Cb("indent_info") * C(parsers.spacechar^0) * Cc(true), check_trail_joined) +parsers.check_code_trail = Cmt( Cb("indent_info") + * C(parsers.spacechar^0) + * Cc(true), check_trail_joined) parsers.check_trail_length_range = function(min, max) - return Cmt(Cb("indent_info") * C(parsers.spacechar^0) * Cc(min) * Cc(max), check_trail_length) + return Cmt( Cb("indent_info") * C(parsers.spacechar^0) * Cc(min) + * Cc(max), check_trail_length) end parsers.check_trail_length = function(n) @@ -26891,9 +28304,11 @@ end % % \end{markdown} % \begin{macrocode} -parsers.freeze_trail = Cg(Cmt(Cb("indent_info") * Cc(true), trail_freezing), "indent_info") +parsers.freeze_trail = Cg( Cmt(Cb("indent_info") + * Cc(true), trail_freezing), "indent_info") -parsers.unfreeze_trail = Cg(Cmt(Cb("indent_info") * Cc(false), trail_freezing), "indent_info") +parsers.unfreeze_trail = Cg(Cmt(Cb("indent_info") * Cc(false), + trail_freezing), "indent_info") % \end{macrocode} % \begin{markdown} @@ -26902,11 +28317,16 @@ parsers.unfreeze_trail = Cg(Cmt(Cb("indent_info") * Cc(false), trail_freezing), % % \end{markdown} % \begin{macrocode} -parsers.check_minimal_indent = Cmt(Cb("indent_info") * Cc(false), check_continuation_indentation) +parsers.check_minimal_indent = Cmt(Cb("indent_info") * Cc(false), + check_continuation_indentation) -parsers.check_optional_indent = Cmt(Cb("indent_info") * Cc(true), check_continuation_indentation) +parsers.check_optional_indent = Cmt(Cb("indent_info") * Cc(true), + check_continuation_indentation) -parsers.check_minimal_blank_indent = Cmt(Cb("indent_info") * Cc(false) * Cc(true), check_continuation_indentation) +parsers.check_minimal_blank_indent + = Cmt( Cb("indent_info") * Cc(false) + * Cc(true) + , check_continuation_indentation) % \end{macrocode} % \begin{markdown} @@ -26917,37 +28337,45 @@ parsers.check_minimal_blank_indent = Cmt(Cb("indent_info") * Cc(false) * Cc(true % \end{markdown} % \begin{macrocode} -parsers.check_minimal_indent_and_trail = Cmt( Cb("indent_info") - * Cc(false) * Cc(false) * Cc("non-code") * Cc(true), - check_continuation_indentation_and_trail) +parsers.check_minimal_indent_and_trail = + Cmt( Cb("indent_info") + * Cc(false) * Cc(false) * Cc("non-code") * Cc(true) + , check_continuation_indentation_and_trail) -parsers.check_minimal_indent_and_code_trail = Cmt( Cb("indent_info") - * Cc(false) * Cc(false) * Cc("code") * Cc(false), - check_continuation_indentation_and_trail) +parsers.check_minimal_indent_and_code_trail = + Cmt( Cb("indent_info") + * Cc(false) * Cc(false) * Cc("code") * Cc(false) + , check_continuation_indentation_and_trail) -parsers.check_minimal_blank_indent_and_full_code_trail = Cmt( Cb("indent_info") - * Cc(false) * Cc(true) * Cc("full-code") * Cc(true), - check_continuation_indentation_and_trail) +parsers.check_minimal_blank_indent_and_full_code_trail = + Cmt( Cb("indent_info") + * Cc(false) * Cc(true) * Cc("full-code") * Cc(true) + , check_continuation_indentation_and_trail) -parsers.check_minimal_indent_and_any_trail = Cmt( Cb("indent_info") - * Cc(false) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false), - check_continuation_indentation_and_trail) +parsers.check_minimal_indent_and_any_trail = + Cmt( Cb("indent_info") + * Cc(false) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false) + , check_continuation_indentation_and_trail) -parsers.check_minimal_blank_indent_and_any_trail = Cmt( Cb("indent_info") - * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false), - check_continuation_indentation_and_trail) +parsers.check_minimal_blank_indent_and_any_trail = + Cmt( Cb("indent_info") + * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false) + , check_continuation_indentation_and_trail) -parsers.check_minimal_blank_indent_and_any_trail_no_rem = Cmt( Cb("indent_info") - * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(true), - check_continuation_indentation_and_trail) +parsers.check_minimal_blank_indent_and_any_trail_no_rem = + Cmt( Cb("indent_info") + * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(true) + , check_continuation_indentation_and_trail) -parsers.check_optional_indent_and_any_trail = Cmt( Cb("indent_info") - * Cc(true) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false), - check_continuation_indentation_and_trail) +parsers.check_optional_indent_and_any_trail = + Cmt( Cb("indent_info") + * Cc(true) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false) + , check_continuation_indentation_and_trail) -parsers.check_optional_blank_indent_and_any_trail = Cmt( Cb("indent_info") - * Cc(true) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false), - check_continuation_indentation_and_trail) +parsers.check_optional_blank_indent_and_any_trail = + Cmt( Cb("indent_info") + * Cc(true) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false) + , check_continuation_indentation_and_trail) % \end{macrocode} % \begin{markdown} @@ -26958,7 +28386,8 @@ parsers.check_optional_blank_indent_and_any_trail = Cmt( Cb("indent_info") % \begin{macrocode} parsers.spnlc_noexc = parsers.optionalspace - * (parsers.newline * parsers.check_minimal_indent_and_any_trail)^-1 + * ( parsers.newline + * parsers.check_minimal_indent_and_any_trail)^-1 parsers.spnlc = parsers.optionalspace * (V("EndlineNoSub"))^-1 @@ -26966,7 +28395,8 @@ parsers.spnlc = parsers.optionalspace parsers.spnlc_sep = parsers.optionalspace * V("EndlineNoSub") + parsers.spacechar^1 -parsers.only_blank = parsers.spacechar^0 * (parsers.newline + parsers.eof) +parsers.only_blank = parsers.spacechar^0 + * (parsers.newline + parsers.eof) % \end{macrocode} % \begin{figure} @@ -27013,64 +28443,68 @@ parsers.commented_line_letter = parsers.linechar + parsers.newline - parsers.backslash - parsers.percent -parsers.commented_line = Cg(Cc(""), "backslashes") - * ((#(parsers.commented_line_letter - - parsers.newline) - * Cb("backslashes") - * Cs(parsers.commented_line_letter - - parsers.newline)^1 -- initial - * Cg(Cc(""), "backslashes")) - + #(parsers.backslash * parsers.backslash) - * Cg((parsers.backslash -- even backslash - * parsers.backslash)^1, "backslashes") - + (parsers.backslash - * (#parsers.percent - * Cb("backslashes") - / function(backslashes) - return string.rep("\\", #backslashes / 2) - end - * C(parsers.percent) - + #parsers.commented_line_letter - * Cb("backslashes") - * Cc("\\") - * C(parsers.commented_line_letter)) - * Cg(Cc(""), "backslashes")))^0 - * (#parsers.percent - * Cb("backslashes") - / function(backslashes) - return string.rep("\\", #backslashes / 2) - end - * ((parsers.percent -- comment - * parsers.line - * #parsers.blankline) -- blank line - / "\n" - + parsers.percent -- comment - * parsers.line - * parsers.optionalspace) -- leading tabs and spaces - + #(parsers.newline) - * Cb("backslashes") - * C(parsers.newline)) - -parsers.chunk = parsers.line * (parsers.optionallyindentedline - - parsers.blankline)^0 - -parsers.attribute_key_char = parsers.alphanumeric + S("-_:.") -parsers.attribute_raw_char = parsers.alphanumeric + S("-_") -parsers.attribute_key = (parsers.attribute_key_char - - parsers.dash - parsers.digit) - * parsers.attribute_key_char^0 -parsers.attribute_value = ( (parsers.dquote / "") - * (parsers.anyescaped - parsers.dquote)^0 - * (parsers.dquote / "")) - + ( (parsers.squote / "") - * (parsers.anyescaped - parsers.squote)^0 - * (parsers.squote / "")) - + ( parsers.anyescaped - parsers.dquote - parsers.rbrace - - parsers.space)^0 -parsers.attribute_identifier = parsers.attribute_key_char^1 -parsers.attribute_classname = parsers.letter - * parsers.attribute_key_char^0 -parsers.attribute_raw = parsers.attribute_raw_char^1 +parsers.commented_line = Cg(Cc(""), "backslashes") + * ((#(parsers.commented_line_letter + - parsers.newline) + * Cb("backslashes") + * Cs(parsers.commented_line_letter + - parsers.newline)^1 -- initial + * Cg(Cc(""), "backslashes")) + + #( parsers.backslash + * (parsers.backslash + parsers.newline)) + * Cg((parsers.backslash -- even backslash + * ( parsers.backslash + + #parsers.newline))^1, "backslashes") + + (parsers.backslash + * (#parsers.percent + * Cb("backslashes") + / function(backslashes) + return string.rep("\\", #backslashes / 2) + end + * C(parsers.percent) + + #parsers.commented_line_letter + * Cb("backslashes") + * Cc("\\") + * C(parsers.commented_line_letter)) + * Cg(Cc(""), "backslashes")))^0 + * (#parsers.percent + * Cb("backslashes") + / function(backslashes) + return string.rep("\\", #backslashes / 2) + end + * ((parsers.percent -- comment + * parsers.line + * #parsers.blankline) -- blank line + / "\n" + + parsers.percent -- comment + * parsers.line + * parsers.optionalspace) -- leading spaces + + #(parsers.newline) + * Cb("backslashes") + * C(parsers.newline)) + +parsers.chunk = parsers.line * (parsers.optionallyindentedline + - parsers.blankline)^0 + +parsers.attribute_key_char = parsers.alphanumeric + S("-_:.") +parsers.attribute_raw_char = parsers.alphanumeric + S("-_") +parsers.attribute_key = (parsers.attribute_key_char + - parsers.dash - parsers.digit) + * parsers.attribute_key_char^0 +parsers.attribute_value = ( (parsers.dquote / "") + * (parsers.anyescaped - parsers.dquote)^0 + * (parsers.dquote / "")) + + ( (parsers.squote / "") + * (parsers.anyescaped - parsers.squote)^0 + * (parsers.squote / "")) + + ( parsers.anyescaped + - parsers.dquote + - parsers.rbrace + - parsers.space)^0 +parsers.attribute_identifier = parsers.attribute_key_char^1 +parsers.attribute_classname = parsers.letter + * parsers.attribute_key_char^0 +parsers.attribute_raw = parsers.attribute_raw_char^1 parsers.attribute = (parsers.dash * Cc(".unnumbered")) + C( parsers.hash @@ -27078,7 +28512,9 @@ parsers.attribute = (parsers.dash * Cc(".unnumbered")) + C( parsers.period * parsers.attribute_classname) + Cs( parsers.attribute_key - * parsers.optionalspace * parsers.equal * parsers.optionalspace + * parsers.optionalspace + * parsers.equal + * parsers.optionalspace * parsers.attribute_value) parsers.attributes = parsers.lbrace * parsers.optionalspace @@ -27088,7 +28524,6 @@ parsers.attributes = parsers.lbrace * parsers.optionalspace * parsers.rbrace - parsers.raw_attribute = parsers.lbrace * parsers.optionalspace * parsers.equal @@ -27100,7 +28535,10 @@ parsers.raw_attribute = parsers.lbrace -- indented blocks with first line indented. parsers.indented_blocks = function(bl) return Cs( bl - * (parsers.blankline^1 * parsers.indent * -parsers.blankline * bl)^0 + * ( parsers.blankline^1 + * parsers.indent + * -parsers.blankline + * bl)^0 * (parsers.blankline^1 + parsers.eof) ) end % \end{macrocode} @@ -27116,15 +28554,18 @@ local function repeat_between(pattern, min, max) end parsers.hexentity = parsers.ampersand * parsers.hash * C(S("Xx")) - * C(repeat_between(parsers.hexdigit, 1, 6)) * parsers.semicolon + * C(repeat_between(parsers.hexdigit, 1, 6)) + * parsers.semicolon parsers.decentity = parsers.ampersand * parsers.hash - * C(repeat_between(parsers.digit, 1, 7)) * parsers.semicolon + * C(repeat_between(parsers.digit, 1, 7)) + * parsers.semicolon parsers.tagentity = parsers.ampersand * C(parsers.alphanumeric^1) * parsers.semicolon -parsers.html_entities = parsers.hexentity / entities.hex_entity_with_x_char - + parsers.decentity / entities.dec_entity - + parsers.tagentity / entities.char_entity +parsers.html_entities + = parsers.hexentity / entities.hex_entity_with_x_char + + parsers.decentity / entities.dec_entity + + parsers.tagentity / entities.char_entity % \end{macrocode} % \par % \begin{markdown} @@ -27138,7 +28579,8 @@ parsers.bullet = function(bullet_char, interrupting) if interrupting then allowed_end = C(parsers.spacechar^1) * #parsers.linechar else - allowed_end = C(parsers.spacechar^1) + #(parsers.newline + parsers.eof) + allowed_end = C(parsers.spacechar^1) + + #(parsers.newline + parsers.eof) end return parsers.check_trail * Ct(C(bullet_char) * Cc("")) @@ -27196,7 +28638,8 @@ parsers.inticks = parsers.openticks % % \end{markdown} % \begin{macrocode} --- case-insensitive match (we assume s is lowercase). must be single byte encoding +-- case-insensitive match (we assume s is lowercase) +-- must be single byte encoding parsers.keyword_exact = function(s) local parser = P(0) for i=1,#s do @@ -27278,13 +28721,14 @@ parsers.block_keyword = parsers.keyword_exact("ul") -- end conditions -parsers.html_blankline_end_condition = parsers.linechar^0 - * ( parsers.newline - * (parsers.check_minimal_blank_indent_and_any_trail - * #parsers.blankline - + parsers.check_minimal_indent_and_any_trail) - * parsers.linechar^1)^0 - * (parsers.newline^-1 / "") +parsers.html_blankline_end_condition + = parsers.linechar^0 + * ( parsers.newline + * (parsers.check_minimal_blank_indent_and_any_trail + * #parsers.blankline + + parsers.check_minimal_indent_and_any_trail) + * parsers.linechar^1)^0 + * (parsers.newline^-1 / "") local function remove_trailing_blank_lines(s) return s:gsub("[\n\r]+%s*$", "") @@ -27306,9 +28750,14 @@ parsers.html_attribute_spacing = parsers.optionalspace * parsers.optionalspace + parsers.spacechar^1 -parsers.html_attribute_name = (parsers.letter + parsers.colon + parsers.underscore) - * (parsers.alphanumeric + parsers.colon + parsers.underscore - + parsers.period + parsers.dash)^0 +parsers.html_attribute_name = ( parsers.letter + + parsers.colon + + parsers.underscore) + * ( parsers.alphanumeric + + parsers.colon + + parsers.underscore + + parsers.period + + parsers.dash)^0 parsers.html_attribute_value = parsers.squote * (parsers.linechar - parsers.squote)^0 @@ -27316,9 +28765,15 @@ parsers.html_attribute_value = parsers.squote + parsers.dquote * (parsers.linechar - parsers.dquote)^0 * parsers.dquote - + ( parsers.any - parsers.spacechar - parsers.newline - - parsers.dquote - parsers.squote - parsers.backtick - - parsers.equal - parsers.less - parsers.more)^1 + + ( parsers.any + - parsers.spacechar + - parsers.newline + - parsers.dquote + - parsers.squote + - parsers.backtick + - parsers.equal + - parsers.less + - parsers.more)^1 parsers.html_inline_attribute_value = parsers.squote * (V("NoSoftLineBreakEndline") @@ -27332,30 +28787,41 @@ parsers.html_inline_attribute_value = parsers.squote - parsers.blankline^2 - parsers.dquote)^0 * parsers.dquote - + (parsers.any - parsers.spacechar - parsers.newline - - parsers.dquote - parsers.squote - parsers.backtick - - parsers.equal - parsers.less - parsers.more)^1 - -parsers.html_attribute_value_specification = parsers.optionalspace - * parsers.equal - * parsers.optionalspace - * parsers.html_attribute_value + + (parsers.any + - parsers.spacechar + - parsers.newline + - parsers.dquote + - parsers.squote + - parsers.backtick + - parsers.equal + - parsers.less + - parsers.more)^1 + +parsers.html_attribute_value_specification + = parsers.optionalspace + * parsers.equal + * parsers.optionalspace + * parsers.html_attribute_value parsers.html_spnl = parsers.optionalspace - * (V("NoSoftLineBreakEndline") * parsers.optionalspace)^-1 + * (V("NoSoftLineBreakEndline") + * parsers.optionalspace)^-1 -parsers.html_inline_attribute_value_specification = parsers.html_spnl - * parsers.equal - * parsers.html_spnl - * parsers.html_inline_attribute_value +parsers.html_inline_attribute_value_specification + = parsers.html_spnl + * parsers.equal + * parsers.html_spnl + * parsers.html_inline_attribute_value -parsers.html_attribute = parsers.html_attribute_spacing - * parsers.html_attribute_name - * parsers.html_inline_attribute_value_specification^-1 +parsers.html_attribute + = parsers.html_attribute_spacing + * parsers.html_attribute_name + * parsers.html_inline_attribute_value_specification^-1 -parsers.html_non_newline_attribute = parsers.spacechar^1 - * parsers.html_attribute_name - * parsers.html_attribute_value_specification^-1 +parsers.html_non_newline_attribute + = parsers.spacechar^1 + * parsers.html_attribute_name + * parsers.html_attribute_value_specification^-1 parsers.nested_breaking_blank = parsers.newline * parsers.check_minimal_blank_indent @@ -27365,49 +28831,59 @@ parsers.html_comment_start = P("<!--") parsers.html_comment_end = P("-->") -parsers.html_comment = Cs( parsers.html_comment_start - * parsers.html_until_end(parsers.html_comment_end)) +parsers.html_comment + = Cs( parsers.html_comment_start + * parsers.html_until_end(parsers.html_comment_end)) parsers.html_inline_comment = (parsers.html_comment_start / "") * -P(">") * -P("->") - * Cs((V("NoSoftLineBreakEndline") + parsers.any - - parsers.nested_breaking_blank - parsers.html_comment_end)^0) + * Cs(( V("NoSoftLineBreakEndline") + + parsers.any + - parsers.nested_breaking_blank + - parsers.html_comment_end)^0) * (parsers.html_comment_end / "") parsers.html_cdatasection_start = P("<![CDATA[") parsers.html_cdatasection_end = P("]]>") -parsers.html_cdatasection = Cs( parsers.html_cdatasection_start - * parsers.html_until_end(parsers.html_cdatasection_end)) +parsers.html_cdatasection + = Cs( parsers.html_cdatasection_start + * parsers.html_until_end(parsers.html_cdatasection_end)) -parsers.html_inline_cdatasection = parsers.html_cdatasection_start - * Cs(V("NoSoftLineBreakEndline") + parsers.any - - parsers.nested_breaking_blank - parsers.html_cdatasection_end)^0 - * parsers.html_cdatasection_end +parsers.html_inline_cdatasection + = parsers.html_cdatasection_start + * Cs(V("NoSoftLineBreakEndline") + parsers.any + - parsers.nested_breaking_blank - parsers.html_cdatasection_end)^0 + * parsers.html_cdatasection_end parsers.html_declaration_start = P("<!") * parsers.letter parsers.html_declaration_end = P(">") -parsers.html_declaration = Cs( parsers.html_declaration_start - * parsers.html_until_end(parsers.html_declaration_end)) +parsers.html_declaration + = Cs( parsers.html_declaration_start + * parsers.html_until_end(parsers.html_declaration_end)) -parsers.html_inline_declaration = parsers.html_declaration_start - * Cs(V("NoSoftLineBreakEndline") + parsers.any - - parsers.nested_breaking_blank - parsers.html_declaration_end)^0 - * parsers.html_declaration_end +parsers.html_inline_declaration + = parsers.html_declaration_start + * Cs(V("NoSoftLineBreakEndline") + parsers.any + - parsers.nested_breaking_blank - parsers.html_declaration_end)^0 + * parsers.html_declaration_end parsers.html_instruction_start = P("<?") parsers.html_instruction_end = P("?>") -parsers.html_instruction = Cs( parsers.html_instruction_start - * parsers.html_until_end(parsers.html_instruction_end)) +parsers.html_instruction + = Cs( parsers.html_instruction_start + * parsers.html_until_end(parsers.html_instruction_end)) parsers.html_inline_instruction = parsers.html_instruction_start - * Cs(V("NoSoftLineBreakEndline") + parsers.any - - parsers.nested_breaking_blank - parsers.html_instruction_end)^0 + * Cs( V("NoSoftLineBreakEndline") + + parsers.any + - parsers.nested_breaking_blank + - parsers.html_instruction_end)^0 * parsers.html_instruction_end parsers.html_blankline = parsers.newline @@ -27453,25 +28929,28 @@ parsers.incomplete_tag_following = parsers.spacechar + parsers.slash * parsers.more + #(parsers.newline + parsers.eof) -parsers.incomplete_special_tag_following = parsers.spacechar - + parsers.more - + #(parsers.newline + parsers.eof) +parsers.incomplete_special_tag_following = parsers.spacechar + + parsers.more + + #( parsers.newline + + parsers.eof) parsers.html_incomplete_open_tag = parsers.html_tag_start * parsers.block_keyword * parsers.incomplete_tag_following -parsers.html_incomplete_open_special_tag = parsers.html_tag_start - * parsers.special_block_keyword - * parsers.incomplete_special_tag_following +parsers.html_incomplete_open_special_tag + = parsers.html_tag_start + * parsers.special_block_keyword + * parsers.incomplete_special_tag_following parsers.html_incomplete_close_tag = parsers.html_tag_closing_start * parsers.block_keyword * parsers.incomplete_tag_following -parsers.html_incomplete_close_special_tag = parsers.html_tag_closing_start - * parsers.special_block_keyword - * parsers.incomplete_tag_following +parsers.html_incomplete_close_special_tag + = parsers.html_tag_closing_start + * parsers.special_block_keyword + * parsers.incomplete_tag_following -- closing tags parsers.html_close_tag = parsers.html_tag_closing_start @@ -27509,27 +28988,33 @@ parsers.html_empty_special_tag = parsers.html_tag_start * parsers.html_attribute^0 * parsers.html_empty_tag_end -parsers.html_incomplete_blocks = parsers.html_incomplete_open_tag - + parsers.html_incomplete_open_special_tag - + parsers.html_incomplete_close_tag +parsers.html_incomplete_blocks + = parsers.html_incomplete_open_tag + + parsers.html_incomplete_open_special_tag + + parsers.html_incomplete_close_tag -- parse special html blocks -parsers.html_blankline_ending_special_block_opening = (parsers.html_close_special_tag - + parsers.html_empty_special_tag) - * #(parsers.optionalspace - * (parsers.newline + parsers.eof)) +parsers.html_blankline_ending_special_block_opening + = ( parsers.html_close_special_tag + + parsers.html_empty_special_tag) + * #( parsers.optionalspace + * (parsers.newline + parsers.eof)) -parsers.html_blankline_ending_special_block = parsers.html_blankline_ending_special_block_opening - * parsers.html_blankline_end_condition +parsers.html_blankline_ending_special_block + = parsers.html_blankline_ending_special_block_opening + * parsers.html_blankline_end_condition -parsers.html_special_block_opening = parsers.html_incomplete_open_special_tag - - parsers.html_empty_special_tag +parsers.html_special_block_opening + = parsers.html_incomplete_open_special_tag + - parsers.html_empty_special_tag -parsers.html_closing_special_block = parsers.html_special_block_opening - * parsers.html_until_end(parsers.html_close_special_tag) +parsers.html_closing_special_block + = parsers.html_special_block_opening + * parsers.html_until_end(parsers.html_close_special_tag) -parsers.html_special_block = parsers.html_blankline_ending_special_block - + parsers.html_closing_special_block +parsers.html_special_block + = parsers.html_blankline_ending_special_block + + parsers.html_closing_special_block -- parse html blocks parsers.html_block_opening = parsers.html_incomplete_open_tag @@ -27539,18 +29024,21 @@ parsers.html_block = parsers.html_block_opening * parsers.html_blankline_end_condition -- parse any html blocks -parsers.html_any_block_opening = (parsers.html_any_open_tag - + parsers.html_any_close_tag - + parsers.html_any_empty_tag) - * #(parsers.optionalspace * (parsers.newline + parsers.eof)) +parsers.html_any_block_opening + = ( parsers.html_any_open_tag + + parsers.html_any_close_tag + + parsers.html_any_empty_tag) + * #(parsers.optionalspace * (parsers.newline + parsers.eof)) parsers.html_any_block = parsers.html_any_block_opening * parsers.html_blankline_end_condition parsers.html_inline_comment_full = parsers.html_comment_start * -P(">") * -P("->") - * Cs((V("NoSoftLineBreakEndline") + parsers.any - P("--") - - parsers.nested_breaking_blank - parsers.html_comment_end)^0) + * Cs(( V("NoSoftLineBreakEndline") + + parsers.any - P("--") + - parsers.nested_breaking_blank + - parsers.html_comment_end)^0) * parsers.html_comment_end parsers.html_inline_tags = parsers.html_inline_comment_full @@ -27583,21 +29071,25 @@ parsers.auto_link_scheme = parsers.letter * parsers.auto_link_scheme_part^-30 parsers.absolute_uri = parsers.auto_link_scheme * parsers.colon - * (parsers.any - parsers.spacing - parsers.less - parsers.more)^0 + * ( parsers.any - parsers.spacing + - parsers.less - parsers.more)^0 parsers.printable_characters = S(".!#$%&'*+/=?^_`{|}~-") parsers.email_address_local_part_char = parsers.alphanumeric + parsers.printable_characters -parsers.email_address_local_part = parsers.email_address_local_part_char^1 +parsers.email_address_local_part + = parsers.email_address_local_part_char^1 parsers.email_address_dns_label = parsers.alphanumeric - * (parsers.alphanumeric + parsers.dash)^-62 + * ( parsers.alphanumeric + + parsers.dash)^-62 * B(parsers.alphanumeric) parsers.email_address_domain = parsers.email_address_dns_label - * (parsers.period * parsers.email_address_dns_label)^0 + * ( parsers.period + * parsers.email_address_dns_label)^0 parsers.email_address = parsers.email_address_local_part * parsers.at @@ -27653,26 +29145,40 @@ parsers.link_text = parsers.lbracket + parsers.autolink + V("InlineHtml") + ( parsers.backslash * parsers.backslash) - + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) + + ( parsers.backslash + * ( parsers.lbracket + + parsers.rbracket) + V("NoSoftLineBreakSpace") + V("NoSoftLineBreakEndline") + (parsers.any - - (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^0) + - ( parsers.newline + + parsers.lbracket + + parsers.rbracket + + parsers.blankline^2))))^0) * parsers.rbracket +parsers.link_label_body = -#(parsers.sp * parsers.rbracket) + * #( ( parsers.any + - parsers.rbracket)^-999 + * parsers.rbracket) + * Cs((parsers.alphanumeric^1 + + parsers.inticks + + parsers.autolink + + V("InlineHtml") + + ( parsers.backslash * parsers.backslash) + + ( parsers.backslash + * ( parsers.lbracket + + parsers.rbracket) + + V("NoSoftLineBreakSpace") + + V("NoSoftLineBreakEndline") + + (parsers.any + - ( parsers.newline + + parsers.lbracket + + parsers.rbracket + + parsers.blankline^2))))^1) + parsers.link_label = parsers.lbracket - * -#(parsers.sp * parsers.rbracket) - * #((parsers.any - parsers.rbracket)^-999 * parsers.rbracket) - * Cs((parsers.alphanumeric^1 - + parsers.inticks - + parsers.autolink - + V("InlineHtml") - + ( parsers.backslash * parsers.backslash) - + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) - + V("NoSoftLineBreakSpace") - + V("NoSoftLineBreakEndline") - + (parsers.any - - (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^1) + * parsers.link_label_body * parsers.rbracket parsers.inparens_url = P{ parsers.lparent @@ -27699,29 +29205,38 @@ parsers.title_s = parsers.squote * Cs((parsers.html_entities + V("NoSoftLineBreakSpace") + V("NoSoftLineBreakEndline") - + (parsers.anyescaped - parsers.newline - parsers.squote - parsers.blankline^2))^0) + + ( parsers.anyescaped + - parsers.newline + - parsers.squote + - parsers.blankline^2))^0) * parsers.squote parsers.title_d = parsers.dquote * Cs((parsers.html_entities + V("NoSoftLineBreakSpace") + V("NoSoftLineBreakEndline") - + (parsers.anyescaped - parsers.newline - parsers.dquote - parsers.blankline^2))^0) + + ( parsers.anyescaped + - parsers.newline + - parsers.dquote + - parsers.blankline^2))^0) * parsers.dquote parsers.title_p = parsers.lparent * Cs((parsers.html_entities + V("NoSoftLineBreakSpace") + V("NoSoftLineBreakEndline") - + (parsers.anyescaped - parsers.newline - parsers.lparent - parsers.rparent + + ( parsers.anyescaped + - parsers.newline + - parsers.lparent + - parsers.rparent - parsers.blankline^2))^0) * parsers.rparent -parsers.title = parsers.title_d + parsers.title_s + parsers.title_p +parsers.title + = parsers.title_d + parsers.title_s + parsers.title_p parsers.optionaltitle - = parsers.spnlc * parsers.title * parsers.spacechar^0 - + Cc("") + = parsers.spnlc * parsers.title * parsers.spacechar^0 + Cc("") % \end{macrocode} % \par @@ -27732,9 +29247,11 @@ parsers.optionaltitle % \end{markdown} % \begin{macrocode} -- parse a reference definition: [foo]: /bar "title" -parsers.define_reference_parser = (parsers.check_trail / "") * parsers.link_label * parsers.colon +parsers.define_reference_parser = (parsers.check_trail / "") + * parsers.link_label * parsers.colon * parsers.spnlc * parsers.url - * ( parsers.spnlc_sep * parsers.title * parsers.only_blank + * ( parsers.spnlc_sep * parsers.title + * parsers.only_blank + Cc("") * parsers.only_blank) % \end{macrocode} % \par @@ -27749,7 +29266,10 @@ parsers.Inline = V("Inline") -- parse many p between starter and ender parsers.between = function(p, starter, ender) local ender2 = B(parsers.nonspacechar) * ender - return (starter * #parsers.nonspacechar * Ct(p * (p - ender2)^0) * ender2) + return ( starter + * #parsers.nonspacechar + * Ct(p * (p - ender2)^0) + * ender2) end % \end{macrocode} @@ -27761,7 +29281,8 @@ end % \end{markdown} % \begin{macrocode} parsers.lineof = function(c) - return (parsers.check_trail_no_rem * (P(c) * parsers.optionalspace)^3 + return ( parsers.check_trail_no_rem + * (P(c) * parsers.optionalspace)^3 * (parsers.newline + parsers.eof)) end @@ -27781,8 +29302,11 @@ parsers.heading_start = #parsers.hash * C(parsers.hash^-6) * -parsers.hash / length -- parse setext header ending and return level -parsers.heading_level = parsers.nonindentspace * parsers.equal^1 * parsers.optionalspace * #parsers.newline * Cc(1) - + parsers.nonindentspace * parsers.dash^1 * parsers.optionalspace * #parsers.newline * Cc(2) +parsers.heading_level + = parsers.nonindentspace * parsers.equal^1 + * parsers.optionalspace * #parsers.newline * Cc(1) + + parsers.nonindentspace * parsers.dash^1 + * parsers.optionalspace * #parsers.newline * Cc(2) local function strip_atx_end(s) return s:gsub("%s+#*%s*\n$","") @@ -27954,9 +29478,11 @@ function M.reader.new(writer, options) local prefix = lpeg.match(C(parsers.optionalspace), line) local prefix_length = #prefix local is_shorter = min_prefix_length == nil - is_shorter = is_shorter or prefix_length < min_prefix_length + if not is_shorter then + is_shorter = prefix_length < min_prefix_length + end if is_shorter then - min_prefix_length, min_prefix = prefix_length, prefix + min_prefix_length, min_prefix = prefix_length, prefix end return line end) @@ -27978,7 +29504,11 @@ function M.reader.new(writer, options) end local res = lpeg.match(grammar(), str) if res == nil then - 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 @@ -28028,35 +29558,47 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - parsers.minimally_indented_blankline = parsers.check_minimal_indent * (parsers.blankline / "") + parsers.minimally_indented_blankline + = parsers.check_minimal_indent * (parsers.blankline / "") - parsers.minimally_indented_block = parsers.check_minimal_indent * V("Block") + parsers.minimally_indented_block + = parsers.check_minimal_indent * V("Block") - parsers.minimally_indented_block_or_paragraph = parsers.check_minimal_indent * V("BlockOrParagraph") + parsers.minimally_indented_block_or_paragraph + = parsers.check_minimal_indent * V("BlockOrParagraph") - parsers.minimally_indented_paragraph = parsers.check_minimal_indent * V("Paragraph") + parsers.minimally_indented_paragraph + = parsers.check_minimal_indent * V("Paragraph") - parsers.minimally_indented_plain = parsers.check_minimal_indent * V("Plain") + parsers.minimally_indented_plain + = parsers.check_minimal_indent * V("Plain") - parsers.minimally_indented_par_or_plain = parsers.minimally_indented_paragraph - + parsers.minimally_indented_plain + parsers.minimally_indented_par_or_plain + = parsers.minimally_indented_paragraph + + parsers.minimally_indented_plain - parsers.minimally_indented_par_or_plain_no_blank = parsers.minimally_indented_par_or_plain - - parsers.minimally_indented_blankline + parsers.minimally_indented_par_or_plain_no_blank + = parsers.minimally_indented_par_or_plain + - parsers.minimally_indented_blankline - parsers.minimally_indented_ref = parsers.check_minimal_indent * V("Reference") + parsers.minimally_indented_ref + = parsers.check_minimal_indent * V("Reference") - parsers.minimally_indented_blank = parsers.check_minimal_indent * V("Blank") + parsers.minimally_indented_blank + = parsers.check_minimal_indent * V("Blank") - parsers.conditionally_indented_blankline = parsers.check_minimal_blank_indent * (parsers.blankline / "") + parsers.conditionally_indented_blankline + = parsers.check_minimal_blank_indent * (parsers.blankline / "") - parsers.minimally_indented_ref_or_block = parsers.minimally_indented_ref - + parsers.minimally_indented_block - - parsers.minimally_indented_blankline + parsers.minimally_indented_ref_or_block + = parsers.minimally_indented_ref + + parsers.minimally_indented_block + - parsers.minimally_indented_blankline - parsers.minimally_indented_ref_or_block_or_par = parsers.minimally_indented_ref - + parsers.minimally_indented_block_or_paragraph - - parsers.minimally_indented_blankline + parsers.minimally_indented_ref_or_block_or_par + = parsers.minimally_indented_ref + + parsers.minimally_indented_block_or_paragraph + - parsers.minimally_indented_blankline % \end{macrocode} % \begin{markdown} @@ -28066,7 +29608,8 @@ function M.reader.new(writer, options) % \end{markdown} % \begin{macrocode} - parsers.separator_loop = function(separated_block, paragraph, block_separator, paragraph_separator) + function parsers.separator_loop(separated_block, paragraph, + block_separator, paragraph_separator) return separated_block + block_separator * paragraph @@ -28075,10 +29618,14 @@ function M.reader.new(writer, options) * paragraph end - parsers.create_loop_body_pair = function(separated_block, paragraph, block_separator, paragraph_separator) + function parsers.create_loop_body_pair(separated_block, paragraph, + block_separator, + paragraph_separator) return { - block = parsers.separator_loop(separated_block, paragraph, block_separator, block_separator), - par = parsers.separator_loop(separated_block, paragraph, block_separator, paragraph_separator) + block = parsers.separator_loop(separated_block, paragraph, + block_separator, block_separator), + par = parsers.separator_loop(separated_block, paragraph, + block_separator, paragraph_separator) } end @@ -28101,18 +29648,20 @@ function M.reader.new(writer, options) parsers.content_blank = parsers.minimally_indented_blankline - parsers.ref_or_block_separated = parsers.sep_group_no_output(parsers.content_blank) - * ( parsers.minimally_indented_ref - - parsers.content_blank) - + parsers.block_sep_group(parsers.content_blank) - * ( parsers.minimally_indented_block - - parsers.content_blank) + parsers.ref_or_block_separated + = parsers.sep_group_no_output(parsers.content_blank) + * ( parsers.minimally_indented_ref + - parsers.content_blank) + + parsers.block_sep_group(parsers.content_blank) + * ( parsers.minimally_indented_block + - parsers.content_blank) parsers.loop_body_pair = - parsers.create_loop_body_pair(parsers.ref_or_block_separated, - parsers.minimally_indented_par_or_plain_no_blank, - parsers.block_sep_group(parsers.content_blank), - parsers.par_sep_group(parsers.content_blank)) + parsers.create_loop_body_pair( + parsers.ref_or_block_separated, + parsers.minimally_indented_par_or_plain_no_blank, + parsers.block_sep_group(parsers.content_blank), + parsers.par_sep_group(parsers.content_blank)) parsers.content_loop = ( V("Block") * parsers.loop_body_pair.block^0 @@ -28136,7 +29685,8 @@ function M.reader.new(writer, options) parsers.add_indent = function(pattern, name, breakable) return Cg(Cmt( Cb("indent_info") * Ct(pattern) - * (#parsers.linechar * Cc(false) + Cc(true)) -- check if starter is blank + * ( #parsers.linechar -- check if starter is blank + * Cc(false) + Cc(true)) * Cc(name) * Cc(breakable), process_starter_indent), "indent_info") @@ -28164,7 +29714,8 @@ function M.reader.new(writer, options) allowed_end = C(parsers.spacechar^1) * #parsers.linechar else delimiter_range = parsers.dig * parsers.dig^-8 - allowed_end = C(parsers.spacechar^1) + #(parsers.newline + parsers.eof) + allowed_end = C(parsers.spacechar^1) + + #(parsers.newline + parsers.eof) end return parsers.check_trail @@ -28186,16 +29737,21 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - parsers.blockquote_start = parsers.check_trail * C(parsers.more) * C(parsers.spacechar^0) + parsers.blockquote_start + = parsers.check_trail + * C(parsers.more) + * C(parsers.spacechar^0) - parsers.blockquote_body = parsers.add_indent(parsers.blockquote_start, "bq", true) - * parsers.indented_content() - * remove_indent("bq") + parsers.blockquote_body + = parsers.add_indent(parsers.blockquote_start, "bq", true) + * parsers.indented_content() + * remove_indent("bq") if not options.breakableBlockquotes then - parsers.blockquote_body = parsers.add_indent(parsers.blockquote_start, "bq", false) - * parsers.indented_content() - * remove_indent("bq") + parsers.blockquote_body + = parsers.add_indent(parsers.blockquote_start, "bq", false) + * parsers.indented_content() + * remove_indent("bq") end % \end{macrocode} % \par @@ -28209,7 +29765,8 @@ function M.reader.new(writer, options) % \begin{macrocode} local function parse_content_part(content_part) local rope = util.rope_to_string(content_part) - local parsed = self.parser_functions.parse_inlines_no_link_or_emphasis(rope) + local parsed + = self.parser_functions.parse_inlines_no_link_or_emphasis(rope) parsed.indent_info = nil return parsed end @@ -28221,37 +29778,40 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - local function collect_emphasis_content(t, opening_index, closing_index) - local content = {} + local collect_emphasis_content = + function(t, opening_index, closing_index) + local content = {} - local content_part = {} - for i = opening_index, closing_index do - local value = t[i] + local content_part = {} + for i = opening_index, closing_index do + local value = t[i] - if value.rendered ~= nil then - content[#content + 1] = parse_content_part(content_part) - content_part = {} - content[#content + 1] = value.rendered - value.rendered = nil - else - if value.type == "delimiter" and value.element == "emphasis" then - if value.is_active then - content_part[#content_part + 1] = string.rep(value.character, value.current_count) - end + if value.rendered ~= nil then + content[#content + 1] = parse_content_part(content_part) + content_part = {} + content[#content + 1] = value.rendered + value.rendered = nil else - content_part[#content_part + 1] = value.content + if value.type == "delimiter" + and value.element == "emphasis" then + if value.is_active then + content_part[#content_part + 1] + = string.rep(value.character, value.current_count) + end + else + content_part[#content_part + 1] = value.content + end + value.content = '' + value.is_active = false end - value.content = '' - value.is_active = false end - end - if next(content_part) ~= nil then - content[#content + 1] = parse_content_part(content_part) - end + if next(content_part) ~= nil then + content[#content + 1] = parse_content_part(content_part) + end - return content - end + return content + end % \end{macrocode} % \begin{markdown} @@ -28262,7 +29822,9 @@ function M.reader.new(writer, options) % \end{markdown} % \begin{macrocode} local function fill_emph(t, opening_index, closing_index) - local content = collect_emphasis_content(t, opening_index + 1, closing_index - 1) + local content + = collect_emphasis_content(t, opening_index + 1, + closing_index - 1) t[opening_index + 1].is_active = true t[opening_index + 1].rendered = writer.emphasis(content) end @@ -28276,7 +29838,9 @@ function M.reader.new(writer, options) % \end{markdown} % \begin{macrocode} local function fill_strong(t, opening_index, closing_index) - local content = collect_emphasis_content(t, opening_index + 1, closing_index - 1) + local content + = collect_emphasis_content(t, opening_index + 1, + closing_index - 1) t[opening_index + 1].is_active = true t[opening_index + 1].rendered = writer.strong(content) end @@ -28290,9 +29854,12 @@ function M.reader.new(writer, options) % \end{markdown} % \begin{macrocode} local function breaks_three_rule(opening_delimiter, closing_delimiter) - return (opening_delimiter.is_closing or closing_delimiter.is_opening) and - ((opening_delimiter.original_count + closing_delimiter.original_count) % 3 == 0) and - (opening_delimiter.original_count % 3 ~= 0 or closing_delimiter.original_count % 3 ~= 0) + return ( opening_delimiter.is_closing + or closing_delimiter.is_opening) + and (( opening_delimiter.original_count + + closing_delimiter.original_count) % 3 == 0) + and ( opening_delimiter.original_count % 3 ~= 0 + or closing_delimiter.original_count % 3 ~= 0) end % \end{macrocode} @@ -28304,7 +29871,8 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - local function find_emphasis_opener(t, bottom_index, latest_index, character, closing_delimiter) + local find_emphasis_opener = function(t, bottom_index, latest_index, + character, closing_delimiter) for i = latest_index, bottom_index, -1 do local value = t[i] if value.is_active and @@ -28368,12 +29936,18 @@ function M.reader.new(writer, options) local is_opening = value.is_opening local closing_length_modulo_three = value.original_count % 3 - local current_openers_bottom = openers_bottom[character][is_opening][closing_length_modulo_three + 1] + local current_openers_bottom + = openers_bottom[character][is_opening] + [closing_length_modulo_three + 1] - local opener_position = find_emphasis_opener(t, current_openers_bottom, current_position - 1, character, value) + local opener_position + = find_emphasis_opener(t, current_openers_bottom, + current_position - 1, character, value) if (opener_position == nil) then - openers_bottom[character][is_opening][closing_length_modulo_three + 1] = current_position + openers_bottom[character][is_opening] + [closing_length_modulo_three + 1] + = current_position current_position = current_position + 1 goto continue end @@ -28383,7 +29957,8 @@ function M.reader.new(writer, options) local current_opening_count = opening_delimiter.current_count local current_closing_count = t[current_position].current_count - if (current_opening_count >= 2) and (current_closing_count >= 2) then + if (current_opening_count >= 2) + and (current_closing_count >= 2) then opening_delimiter.current_count = current_opening_count - 2 t[current_position].current_count = current_closing_count - 2 fill_strong(t, opener_position, current_position) @@ -28467,15 +30042,19 @@ function M.reader.new(writer, options) return check_unicode_type(s, i, 0, 3, "%s") end - parsers.unicode_preceding_punctuation = B(parsers.escapable) - + Cmt(parsers.succeed, check_preceding_unicode_punctuation) + parsers.unicode_preceding_punctuation + = B(parsers.escapable) + + Cmt(parsers.succeed, check_preceding_unicode_punctuation) - parsers.unicode_preceding_whitespace = Cmt(parsers.succeed, check_preceding_unicode_whitespace) + parsers.unicode_preceding_whitespace + = Cmt(parsers.succeed, check_preceding_unicode_whitespace) - parsers.unicode_following_punctuation = #parsers.escapable - + Cmt(parsers.succeed, check_following_unicode_punctuation) + parsers.unicode_following_punctuation + = #parsers.escapable + + Cmt(parsers.succeed, check_following_unicode_punctuation) - parsers.unicode_following_whitespace = Cmt(parsers.succeed, check_following_unicode_whitespace) + parsers.unicode_following_whitespace + = Cmt(parsers.succeed, check_following_unicode_whitespace) parsers.delimiter_run = function(character) return (B(parsers.backslash * character) + -B(character)) @@ -28485,49 +30064,58 @@ function M.reader.new(writer, options) parsers.left_flanking_delimiter_run = function(character) return (B( parsers.any) - * (parsers.unicode_preceding_punctuation + parsers.unicode_preceding_whitespace) + * ( parsers.unicode_preceding_punctuation + + parsers.unicode_preceding_whitespace) + -B(parsers.any)) * parsers.delimiter_run(character) * parsers.unicode_following_punctuation + parsers.delimiter_run(character) - * -#(parsers.unicode_following_punctuation + parsers.unicode_following_whitespace + * -#( parsers.unicode_following_punctuation + + parsers.unicode_following_whitespace + parsers.eof) end parsers.right_flanking_delimiter_run = function(character) return parsers.unicode_preceding_punctuation * parsers.delimiter_run(character) - * (parsers.unicode_following_punctuation + parsers.unicode_following_whitespace + * ( parsers.unicode_following_punctuation + + parsers.unicode_following_whitespace + parsers.eof) + (B(parsers.any) - * -(parsers.unicode_preceding_punctuation + parsers.unicode_preceding_whitespace)) + * -( parsers.unicode_preceding_punctuation + + parsers.unicode_preceding_whitespace)) * parsers.delimiter_run(character) end if options.underscores then - parsers.emph_start = parsers.left_flanking_delimiter_run(parsers.asterisk) - + (-#parsers.right_flanking_delimiter_run(parsers.underscore) - + (parsers.unicode_preceding_punctuation - * #parsers.right_flanking_delimiter_run(parsers.underscore))) - * parsers.left_flanking_delimiter_run(parsers.underscore) - - parsers.emph_end = parsers.right_flanking_delimiter_run(parsers.asterisk) - + (-#parsers.left_flanking_delimiter_run(parsers.underscore) - + #(parsers.left_flanking_delimiter_run(parsers.underscore) - * parsers.unicode_following_punctuation)) - * parsers.right_flanking_delimiter_run(parsers.underscore) + parsers.emph_start + = parsers.left_flanking_delimiter_run(parsers.asterisk) + + ( -#parsers.right_flanking_delimiter_run(parsers.underscore) + + ( parsers.unicode_preceding_punctuation + * #parsers.right_flanking_delimiter_run(parsers.underscore))) + * parsers.left_flanking_delimiter_run(parsers.underscore) + + parsers.emph_end + = parsers.right_flanking_delimiter_run(parsers.asterisk) + + ( -#parsers.left_flanking_delimiter_run(parsers.underscore) + + #( parsers.left_flanking_delimiter_run(parsers.underscore) + * parsers.unicode_following_punctuation)) + * parsers.right_flanking_delimiter_run(parsers.underscore) else - parsers.emph_start = parsers.left_flanking_delimiter_run(parsers.asterisk) + parsers.emph_start + = parsers.left_flanking_delimiter_run(parsers.asterisk) - parsers.emph_end = parsers.right_flanking_delimiter_run(parsers.asterisk) + parsers.emph_end + = parsers.right_flanking_delimiter_run(parsers.asterisk) end - parsers.emph_capturing_open_and_close = #parsers.emph_start * #parsers.emph_end - * Ct( Cg(Cc("delimiter"), "type") - * Cg(Cc("emphasis"), "element") - * Cg(C(parsers.emph_start), "content") - * Cg(Cc(true), "is_opening") - * Cg(Cc(true), "is_closing")) + parsers.emph_capturing_open_and_close + = #parsers.emph_start * #parsers.emph_end + * Ct( Cg(Cc("delimiter"), "type") + * Cg(Cc("emphasis"), "element") + * Cg(C(parsers.emph_start), "content") + * Cg(Cc(true), "is_opening") + * Cg(Cc(true), "is_closing")) parsers.emph_capturing_open = Ct( Cg(Cc("delimiter"), "type") * Cg(Cc("emphasis"), "element") @@ -28562,6 +30150,9 @@ function M.reader.new(writer, options) -- List of references defined in the document local references + -- List of note references defined in the document + parsers.rawnotes = {} + % \end{macrocode} % \par % \begin{markdown} @@ -28599,19 +30190,39 @@ function M.reader.new(writer, options) return references[self.normalize_tag(tag)] end +% \end{macrocode} +% \par +% \begin{markdown} +% +% The \luamdef{reader->lookup_note_reference} method looks up a +% note reference with label `tag`. +% +% \end{markdown} +% \begin{macrocode} + function self.lookup_note_reference(tag) + return parsers.rawnotes[self.normalize_tag(tag)] + end + parsers.title_s_direct_ref = parsers.squote * Cs((parsers.html_entities - + (parsers.anyescaped - parsers.squote - parsers.blankline^2))^0) + + ( parsers.anyescaped + - parsers.squote + - parsers.blankline^2))^0) * parsers.squote parsers.title_d_direct_ref = parsers.dquote * Cs((parsers.html_entities - + (parsers.anyescaped - parsers.dquote - parsers.blankline^2))^0) + + ( parsers.anyescaped + - parsers.dquote + - parsers.blankline^2))^0) * parsers.dquote parsers.title_p_direct_ref = parsers.lparent * Cs((parsers.html_entities - + (parsers.anyescaped - parsers.lparent - parsers.rparent - parsers.blankline^2))^0) + + ( parsers.anyescaped + - parsers.lparent + - parsers.rparent + - parsers.blankline^2))^0) * parsers.rparent parsers.title_direct_ref = parsers.title_s_direct_ref @@ -28621,7 +30232,8 @@ function M.reader.new(writer, options) parsers.inline_direct_ref_inside = parsers.lparent * parsers.spnl * Cg(parsers.url + Cc(""), "url") * parsers.spnl - * Cg(parsers.title_direct_ref + Cc(""), "title") + * Cg( parsers.title_direct_ref + + Cc(""), "title") * parsers.spnl * parsers.rparent parsers.inline_direct_ref = parsers.lparent * parsers.spnlc @@ -28649,7 +30261,8 @@ function M.reader.new(writer, options) * Cg(Cc("inline"), "link_type") + #(parsers.exclamation * parsers.full_link) * Cg(Cc("full"), "link_type") - + #(parsers.exclamation * parsers.collapsed_link) + + #( parsers.exclamation + * parsers.collapsed_link) * Cg(Cc("collapsed"), "link_type") + #(parsers.exclamation * parsers.shortcut_link) * Cg(Cc("shortcut"), "link_type") @@ -28669,22 +30282,61 @@ function M.reader.new(writer, options) + #parsers.link_text * Cg(Cc("link_text"), "link_type") + parsers.note_opening = #(parsers.circumflex * parsers.link_text) + * Cg(Cc("note_inline"), "link_type") + + parsers.raw_note_opening = #( parsers.lbracket + * parsers.circumflex + * parsers.link_label_body + * parsers.rbracket) + * Cg(Cc("raw_note"), "link_type") + + local inline_note_element = Cg(Cc("note"), "element") + * parsers.note_opening + * Cg( parsers.circumflex + * parsers.lbracket, "content") + + local image_element = Cg(Cc("image"), "element") + * parsers.image_opening + * Cg( parsers.exclamation + * parsers.lbracket, "content") + + local note_element = Cg(Cc("note"), "element") + * parsers.raw_note_opening + * Cg( parsers.lbracket + * parsers.circumflex, "content") + + local link_element = Cg(Cc("link"), "element") + * parsers.link_opening + * Cg(parsers.lbracket, "content") + + local opening_elements = parsers.fail + + if options.inlineNotes then + opening_elements = opening_elements + inline_note_element + end + + opening_elements = opening_elements + image_element + + if options.notes then + opening_elements = opening_elements + note_element + end + + opening_elements = opening_elements + link_element + parsers.link_image_opening = Ct( Cg(Cc("delimiter"), "type") * Cg(Cc(true), "is_opening") * Cg(Cc(false), "is_closing") - * ( Cg(Cc("image"), "element") - * parsers.image_opening - * Cg(parsers.exclamation * parsers.lbracket, "content") - + Cg(Cc("link"), "element") - * parsers.link_opening - * Cg(parsers.lbracket, "content"))) + * opening_elements) parsers.link_image_closing = Ct( Cg(Cc("delimiter"), "type") * Cg(Cc("link"), "element") * Cg(Cc(false), "is_opening") * Cg(Cc(true), "is_closing") * ( Cg(Cc(true), "is_direct") - * Cg(parsers.rbracket * #parsers.inline_direct_ref, "content") + * Cg( parsers.rbracket + * #parsers.inline_direct_ref, + "content") + Cg(Cc(false), "is_direct") * Cg(parsers.rbracket, "content"))) @@ -28705,22 +30357,24 @@ function M.reader.new(writer, options) * -V("EndlineExceptions") + parsers.check_optional_indent * -V("EndlineExceptions") - * -parsers.starter) / "") + * -V("ListStarter")) / "") * parsers.spacechar^0 / "\n" - parsers.link_and_emph_content = Ct( Cg(Cc("content"), "type") - * Cg(Cs(( parsers.link_emph_precedence - + parsers.backslash * parsers.any - + parsers.link_and_emph_endline - + (parsers.linechar - - parsers.blankline^2 - - parsers.link_image_open_or_close - - parsers.emph_open_or_close))^0), "content")) + parsers.link_and_emph_content + = Ct( Cg(Cc("content"), "type") + * Cg(Cs(( parsers.link_emph_precedence + + parsers.backslash * parsers.linechar + + parsers.link_and_emph_endline + + (parsers.linechar + - parsers.blankline^2 + - parsers.link_image_open_or_close + - parsers.emph_open_or_close))^0), "content")) - parsers.link_and_emph_table = (parsers.link_image_opening + parsers.emph_open) - * parsers.link_and_emph_content - * ((parsers.link_image_open_or_close + parsers.emph_open_or_close) - * parsers.link_and_emph_content)^1 + parsers.link_and_emph_table + = (parsers.link_image_opening + parsers.emph_open) + * parsers.link_and_emph_content + * ((parsers.link_image_open_or_close + parsers.emph_open_or_close) + * parsers.link_and_emph_content)^1 % \end{macrocode} % \begin{markdown} @@ -28750,7 +30404,9 @@ function M.reader.new(writer, options) local value = t[i] if value.type == "delimiter" and value.is_opening and - (value.element == "link" or value.element == "image") + ( value.element == "link" + or value.element == "image" + or value.element == "note") and not value.removed then if value.is_active then return i @@ -28831,11 +30487,12 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - local function delete_parsed_content_in_range(t, opening_index, closing_index) - for i = opening_index, closing_index do - t[i].rendered = nil + local delete_parsed_content_in_range = + function(t, opening_index, closing_index) + for i = opening_index, closing_index do + t[i].rendered = nil + end end - end % \end{macrocode} % \begin{markdown} @@ -28880,25 +30537,40 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - local function render_link_or_image(t, opening_index, closing_index, content_end_index, reference) - process_emphasis(t, opening_index, content_end_index) - local mapped = collect_emphasis_content(t, opening_index + 1, content_end_index - 1) + local render_link_or_image = + function(t, opening_index, closing_index, content_end_index, + reference) + process_emphasis(t, opening_index, content_end_index) + local mapped = collect_emphasis_content(t, opening_index + 1, + content_end_index - 1) - local rendered = {} - if (t[opening_index].element == "link") then - rendered = writer.link(mapped, reference.url, reference.title, reference.attributes) - end + local rendered = {} + if (t[opening_index].element == "link") then + rendered = writer.link(mapped, reference.url, + reference.title, reference.attributes) + end - if (t[opening_index].element == "image") then - rendered = writer.image(mapped, reference.url, reference.title, reference.attributes) - end + if (t[opening_index].element == "image") then + rendered = writer.image(mapped, reference.url, reference.title, + reference.attributes) + end - t[opening_index].rendered = rendered - delete_parsed_content_in_range(t, opening_index + 1, closing_index) - empty_content_in_range(t, opening_index, closing_index) - disable_previous_link_openers(t, opening_index) - disable_range(t, opening_index, closing_index) - end + if (t[opening_index].element == "note") then + if (t[opening_index].link_type == "note_inline") then + rendered = writer.note(mapped) + end + if (t[opening_index].link_type == "raw_note") then + rendered = writer.note(reference) + end + end + + t[opening_index].rendered = rendered + delete_parsed_content_in_range(t, opening_index + 1, + closing_index) + empty_content_in_range(t, opening_index, closing_index) + disable_previous_link_openers(t, opening_index) + disable_range(t, opening_index, closing_index) + end % \end{macrocode} % \begin{markdown} @@ -28909,123 +30581,185 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - local function resolve_inline_following_content(t, closing_index, match_reference, match_link_attributes) - local content = "" - for i = closing_index + 1, #t do - content = content .. t[i].content - end + local resolve_inline_following_content = + function(t, closing_index, match_reference, match_link_attributes) + local content = "" + for i = closing_index + 1, #t do + content = content .. t[i].content + end - local matching_content = parsers.succeed + local matching_content = parsers.succeed - if match_reference then - matching_content = matching_content * parsers.inline_direct_ref_inside - end + if match_reference then + matching_content = matching_content + * parsers.inline_direct_ref_inside + end - if match_link_attributes then - matching_content = matching_content * Cg(Ct(parsers.attributes^-1), "attributes") - end + if match_link_attributes then + matching_content = matching_content + * Cg(Ct(parsers.attributes^-1), "attributes") + end - local matched = lpeg.match(Ct(matching_content * Cg(Cp(), "end_position")), content) + local matched = lpeg.match(Ct( matching_content + * Cg(Cp(), "end_position")), content) - local matched_count = matched.end_position - 1 - for i = closing_index + 1, #t do - local value = t[i] + local matched_count = matched.end_position - 1 + for i = closing_index + 1, #t do + local value = t[i] - local chars_left = matched_count - matched_count = matched_count - #value.content + local chars_left = matched_count + matched_count = matched_count - #value.content + + if matched_count <= 0 then + value.content = value.content:sub(chars_left + 1) + break + end - if matched_count <= 0 then - value.content = value.content:sub(chars_left + 1) - break + value.content = '' + value.is_active = false end - value.content = '' - value.is_active = false - end + local attributes = matched.attributes + if attributes == nil or next(attributes) == nil then + attributes = nil + end - local attributes = matched.attributes - if attributes == nil or next(attributes) == nil then - attributes = nil + return { + url = matched.url or "", + title = matched.title or "", + attributes = attributes + } end - return { - url = matched.url or "", - title = matched.title or "", - attributes = attributes - } - end - % \end{macrocode} % \begin{markdown} % -% Resolve an inline link [a](b "c") from the delimiters at `opening_index` and `closing_index` +% Resolve an inline link `[a](b "c")` from the delimiters at `opening_index` and `closing_index` % within a delimiter table `t`. Here, compared to other types of links, no reference definition is needed. % % \end{markdown} % \begin{macrocode} local function resolve_inline_link(t, opening_index, closing_index) - local inline_content = resolve_inline_following_content(t, closing_index, true, t.match_link_attributes) - render_link_or_image(t, opening_index, closing_index, closing_index, inline_content) + local inline_content + = resolve_inline_following_content(t, closing_index, true, + t.match_link_attributes) + render_link_or_image(t, opening_index, closing_index, + closing_index, inline_content) end % \end{macrocode} % \begin{markdown} % -% Resolve a shortcut link [a] from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`. +% Resolve an inline note `^[a]` from the delimiters at `opening_index` and `closing_index` +% within a delimiter table `t`. +% +% \end{markdown} +% \begin{macrocode} + local resolve_note_inline_link = + function(t, opening_index, closing_index) + local inline_content + = resolve_inline_following_content(t, closing_index, + false, false) + render_link_or_image(t, opening_index, closing_index, + closing_index, inline_content) + end + +% \end{macrocode} +% \begin{markdown} +% +% Resolve a shortcut link `[a]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`. % Continue if a tag `a` is not found in the references. % % \end{markdown} % \begin{macrocode} local function resolve_shortcut_link(t, opening_index, closing_index) - local content = collect_link_content(t, opening_index + 1, closing_index - 1) + local content + = collect_link_content(t, opening_index + 1, closing_index - 1) local r = self.lookup_reference(content) if r then - local inline_content = resolve_inline_following_content(t, closing_index, false, t.match_link_attributes) - r.attributes = join_attributes(r.attributes, inline_content.attributes) - render_link_or_image(t, opening_index, closing_index, closing_index, r) + local inline_content + = resolve_inline_following_content(t, closing_index, false, + t.match_link_attributes) + r.attributes + = join_attributes(r.attributes, inline_content.attributes) + render_link_or_image(t, opening_index, closing_index, + closing_index, r) + end + end + +% \end{macrocode} +% \begin{markdown} +% +% Resolve a note `[^a]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`. +% Continue if a tag `a` is not found in the rawnotes. +% +% \end{markdown} +% \begin{macrocode} + local function resolve_raw_note_link(t, opening_index, closing_index) + local content + = collect_link_content(t, opening_index + 1, closing_index - 1) + local r = self.lookup_note_reference(content) + + if r then + local parsed_ref = self.parser_functions.parse_blocks_nested(r) + render_link_or_image(t, opening_index, closing_index, + closing_index, parsed_ref) end end % \end{macrocode} % \begin{markdown} % -% Resolve a full link [a][b] from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`. +% Resolve a full link `[a][b]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`. % Continue if a tag `b` is not found in the references. % % \end{markdown} % \begin{macrocode} local function resolve_full_link(t, opening_index, closing_index) - local next_link_closing_index = find_next_link_closing_index(t, closing_index + 4) - local next_link_content = collect_link_content(t, closing_index + 3, next_link_closing_index - 1) + local next_link_closing_index + = find_next_link_closing_index(t, closing_index + 4) + local next_link_content + = collect_link_content(t, closing_index + 3, + next_link_closing_index - 1) local r = self.lookup_reference(next_link_content) if r then - local inline_content = resolve_inline_following_content(t, next_link_closing_index, false, - t.match_link_attributes) - r.attributes = join_attributes(r.attributes, inline_content.attributes) - render_link_or_image(t, opening_index, next_link_closing_index, closing_index, r) + local inline_content + = resolve_inline_following_content(t, next_link_closing_index, + false, + t.match_link_attributes) + r.attributes + = join_attributes(r.attributes, inline_content.attributes) + render_link_or_image(t, opening_index, next_link_closing_index, + closing_index, r) end end % \end{macrocode} % \begin{markdown} % -% Resolve a collapsed link [a][] from the delimiters at `opening_index` and `closing_index` +% Resolve a collapsed link `[a][]` from the delimiters at `opening_index` and `closing_index` % within a delimiter table `t`. % Continue if a tag `a` is not found in the references. % % \end{markdown} % \begin{macrocode} local function resolve_collapsed_link(t, opening_index, closing_index) - local next_link_closing_index = find_next_link_closing_index(t, closing_index + 4) - local content = collect_link_content(t, opening_index + 1, closing_index - 1) + local next_link_closing_index + = find_next_link_closing_index(t, closing_index + 4) + local content + = collect_link_content(t, opening_index + 1, closing_index - 1) local r = self.lookup_reference(content) if r then - local inline_content = resolve_inline_following_content(t, closing_index, false, t.match_link_attributes) - r.attributes = join_attributes(r.attributes, inline_content.attributes) - render_link_or_image(t, opening_index, next_link_closing_index, closing_index, r) + local inline_content + = resolve_inline_following_content(t, closing_index, false, + t.match_link_attributes) + r.attributes + = join_attributes(r.attributes, inline_content.attributes) + render_link_or_image(t, opening_index, next_link_closing_index, + closing_index, r) end end @@ -29045,9 +30779,12 @@ function M.reader.new(writer, options) end for i,value in ipairs(t) do - if not value.is_closing or - value.type ~= "delimiter" or - not (value.element == "link" or value.element == "image") then + if not value.is_closing + or value.type ~= "delimiter" + or not ( value.element == "link" + or value.element == "image" + or value.element == "note") + or value.removed then goto continue end @@ -29073,6 +30810,12 @@ function M.reader.new(writer, options) if (link_type == "collapsed") then resolve_collapsed_link(t, opener_position, i) end + if (link_type == "note_inline") then + resolve_note_inline_link(t, opener_position, i) + end + if (link_type == "raw_note") then + resolve_raw_note_link(t, opener_position, i) + end ::continue:: end @@ -29098,7 +30841,8 @@ function M.reader.new(writer, options) % % \end{markdown} % \begin{macrocode} - parsers.Str = (parsers.normalchar * (parsers.normalchar + parsers.at)^0) + parsers.Str = ( parsers.normalchar + * (parsers.normalchar + parsers.at)^0) / writer.string parsers.Symbol = (parsers.backtick^1 + V("SpecialChar")) @@ -29126,29 +30870,34 @@ function M.reader.new(writer, options) parsers.interrupting_bullets = parsers.fail parsers.interrupting_enumerators = parsers.fail else - parsers.interrupting_bullets = parsers.bullet(parsers.dash, true) - + parsers.bullet(parsers.asterisk, true) - + parsers.bullet(parsers.plus, true) - - parsers.interrupting_enumerators = parsers.enumerator(parsers.period, true) - + parsers.enumerator(parsers.rparent, true) + parsers.interrupting_bullets + = parsers.bullet(parsers.dash, true) + + parsers.bullet(parsers.asterisk, true) + + parsers.bullet(parsers.plus, true) + + parsers.interrupting_enumerators + = parsers.enumerator(parsers.period, true) + + parsers.enumerator(parsers.rparent, true) end if options.html then - parsers.html_interrupting = parsers.check_trail - * ( parsers.html_incomplete_open_tag - + parsers.html_incomplete_close_tag - + parsers.html_incomplete_open_special_tag - + parsers.html_comment_start - + parsers.html_cdatasection_start - + parsers.html_declaration_start - + parsers.html_instruction_start - - parsers.html_close_special_tag - - parsers.html_empty_special_tag) + parsers.html_interrupting + = parsers.check_trail + * ( parsers.html_incomplete_open_tag + + parsers.html_incomplete_close_tag + + parsers.html_incomplete_open_special_tag + + parsers.html_comment_start + + parsers.html_cdatasection_start + + parsers.html_declaration_start + + parsers.html_instruction_start + - parsers.html_close_special_tag + - parsers.html_empty_special_tag) else parsers.html_interrupting = parsers.fail end + parsers.ListStarter = parsers.starter + parsers.EndlineExceptions = parsers.blankline -- paragraph break + parsers.eof -- end of document @@ -29166,7 +30915,7 @@ function M.reader.new(writer, options) * -V("EndlineExceptions") + parsers.check_optional_indent * -V("EndlineExceptions") - * -parsers.starter) + * -V("ListStarter")) / function(_) return end * parsers.spacechar^0 parsers.Endline = parsers.endline @@ -29180,42 +30929,51 @@ function M.reader.new(writer, options) * -V("NoSoftLineBreakEndlineExceptions") + parsers.check_optional_indent * -V("NoSoftLineBreakEndlineExceptions") - * -parsers.starter) + * -V("ListStarter")) * parsers.spacechar^0 / writer.space - parsers.EndlineBreak = parsers.backslash * parsers.Endline + parsers.EndlineBreak = parsers.backslash * parsers.endline / writer.hard_line_break parsers.OptionalIndent = parsers.spacechar^1 / writer.space - parsers.Space = parsers.spacechar^2 * parsers.Endline + parsers.Space = parsers.spacechar^2 * parsers.endline / writer.hard_line_break - + parsers.spacechar^1 * parsers.Endline^-1 * parsers.eof / self.expandtabs - + parsers.spacechar^1 * parsers.Endline + + parsers.spacechar^1 + * parsers.endline^-1 + * parsers.eof / self.expandtabs + + parsers.spacechar^1 * parsers.endline / writer.soft_line_break - + parsers.spacechar^1 * -parsers.newline / self.expandtabs + + parsers.spacechar^1 + * -parsers.newline / self.expandtabs + + parsers.spacechar^1 parsers.NoSoftLineBreakSpace - = parsers.spacechar^2 * parsers.Endline + = parsers.spacechar^2 * parsers.endline / writer.hard_line_break - + parsers.spacechar^1 * parsers.Endline^-1 * parsers.eof / self.expandtabs - + parsers.spacechar^1 * parsers.Endline + + parsers.spacechar^1 + * parsers.endline^-1 + * parsers.eof / self.expandtabs + + parsers.spacechar^1 * parsers.endline / writer.soft_line_break - + parsers.spacechar^1 * -parsers.newline / self.expandtabs + + parsers.spacechar^1 + * -parsers.newline / self.expandtabs + + parsers.spacechar^1 parsers.NonbreakingEndline = parsers.endline - / writer.soft_line_break + / writer.nbsp parsers.NonbreakingSpace - = parsers.spacechar^2 * parsers.Endline - / writer.hard_line_break - + parsers.spacechar^1 * parsers.Endline^-1 * parsers.eof / "" - + parsers.spacechar^1 * parsers.Endline + = parsers.spacechar^2 * parsers.endline + / writer.nbsp + + parsers.spacechar^1 + * parsers.endline^-1 * parsers.eof / "" + + parsers.spacechar^1 * parsers.endline * parsers.optionalspace - / writer.soft_line_break + / writer.nbsp + parsers.spacechar^1 * parsers.optionalspace / writer.nbsp @@ -29264,18 +31022,20 @@ end parsers.LinkAndEmph = Ct(parsers.link_and_emph_table) / self.defer_link_and_emphasis_processing - parsers.EscapedChar = parsers.backslash * C(parsers.escapable) / writer.string + parsers.EscapedChar = parsers.backslash + * C(parsers.escapable) / writer.string - parsers.InlineHtml = Cs(parsers.html_inline_comment) / writer.inline_html_comment - + Cs(parsers.html_any_empty_inline_tag - + parsers.html_inline_instruction - + parsers.html_inline_cdatasection - + parsers.html_inline_declaration - + parsers.html_any_open_inline_tag - + parsers.html_any_close_tag) - / writer.inline_html_tag + parsers.InlineHtml = Cs(parsers.html_inline_comment) + / writer.inline_html_comment + + Cs(parsers.html_any_empty_inline_tag + + parsers.html_inline_instruction + + parsers.html_inline_cdatasection + + parsers.html_inline_declaration + + parsers.html_any_open_inline_tag + + parsers.html_any_close_tag) + / writer.inline_html_tag - parsers.HtmlEntity = parsers.html_entities / writer.string + parsers.HtmlEntity = parsers.html_entities / writer.string % \end{macrocode} % \par % \begin{markdown} @@ -29294,15 +31054,18 @@ end + parsers.html_declaration)) / writer.block_html_element - parsers.indented_non_blank_line = parsers.indentedline - parsers.blankline + parsers.indented_non_blank_line = parsers.indentedline + - parsers.blankline - parsers.Verbatim = Cs( - parsers.check_code_trail - * (parsers.line - parsers.blankline) - * ((parsers.check_minimal_blank_indent_and_full_code_trail * parsers.blankline)^0 - * ((parsers.check_minimal_indent / "") * parsers.check_code_trail - * (parsers.line - parsers.blankline))^1)^0 - ) / self.expandtabs / writer.verbatim + parsers.Verbatim + = Cs( parsers.check_code_trail + * (parsers.line - parsers.blankline) + * (( parsers.check_minimal_blank_indent_and_full_code_trail + * parsers.blankline)^0 + * ( (parsers.check_minimal_indent / "") + * parsers.check_code_trail + * (parsers.line - parsers.blankline))^1)^0) + / self.expandtabs / writer.verbatim parsers.Blockquote = parsers.blockquote_body / writer.blockquote @@ -29341,73 +31104,79 @@ end parsers.list_blank = parsers.conditionally_indented_blankline - parsers.ref_or_block_list_separated = parsers.sep_group_no_output(parsers.list_blank) - * parsers.minimally_indented_ref - + parsers.block_sep_group(parsers.list_blank) - * parsers.minimally_indented_block - - parsers.ref_or_block_non_separated = parsers.minimally_indented_ref - + (parsers.succeed / writer.interblocksep) - * parsers.minimally_indented_block - - parsers.minimally_indented_blankline - - parsers.tight_list_loop_body_pair = - parsers.create_loop_body_pair(parsers.ref_or_block_non_separated, - parsers.minimally_indented_par_or_plain_no_blank, - (parsers.succeed / writer.interblocksep), - (parsers.succeed / writer.paragraphsep)) - - parsers.loose_list_loop_body_pair = - parsers.create_loop_body_pair(parsers.ref_or_block_list_separated, - parsers.minimally_indented_par_or_plain, - parsers.block_sep_group(parsers.list_blank), - parsers.par_sep_group(parsers.list_blank)) - - parsers.tight_list_content_loop = V("Block") - * parsers.tight_list_loop_body_pair.block^0 - + (V("Paragraph") + V("Plain")) - * parsers.ref_or_block_non_separated - * parsers.tight_list_loop_body_pair.block^0 - + (V("Paragraph") + V("Plain")) - * parsers.tight_list_loop_body_pair.par^0 - - parsers.loose_list_content_loop = V("Block") - * parsers.loose_list_loop_body_pair.block^0 - + (V("Paragraph") + V("Plain")) - * parsers.ref_or_block_list_separated - * parsers.loose_list_loop_body_pair.block^0 - + (V("Paragraph") + V("Plain")) - * parsers.loose_list_loop_body_pair.par^0 - - parsers.list_item_tightness_condition = -#( parsers.list_blank^0 - * parsers.minimally_indented_ref_or_block_or_par) - * remove_indent("li") - + remove_indent("li") - * parsers.fail - - parsers.indented_content_tight = Ct( (parsers.blankline / "") - * #parsers.list_blank - * remove_indent("li") - + ( (V("Reference") + (parsers.blankline / "")) - * parsers.check_minimal_indent - * parsers.tight_list_content_loop - + (V("Reference") + (parsers.blankline / "")) - + (parsers.tickbox^-1 / writer.escape) - * parsers.tight_list_content_loop - ) - * parsers.list_item_tightness_condition - ) - - parsers.indented_content_loose = Ct( (parsers.blankline / "") - * #parsers.list_blank - + ( (V("Reference") + (parsers.blankline / "")) - * parsers.check_minimal_indent - * parsers.loose_list_content_loop - + (V("Reference") + (parsers.blankline / "")) - + (parsers.tickbox^-1 / writer.escape) - * parsers.loose_list_content_loop - ) - ) + parsers.ref_or_block_list_separated + = parsers.sep_group_no_output(parsers.list_blank) + * parsers.minimally_indented_ref + + parsers.block_sep_group(parsers.list_blank) + * parsers.minimally_indented_block + + parsers.ref_or_block_non_separated + = parsers.minimally_indented_ref + + (parsers.succeed / writer.interblocksep) + * parsers.minimally_indented_block + - parsers.minimally_indented_blankline + + parsers.tight_list_loop_body_pair = + parsers.create_loop_body_pair( + parsers.ref_or_block_non_separated, + parsers.minimally_indented_par_or_plain_no_blank, + (parsers.succeed / writer.interblocksep), + (parsers.succeed / writer.paragraphsep)) + + parsers.loose_list_loop_body_pair = + parsers.create_loop_body_pair( + parsers.ref_or_block_list_separated, + parsers.minimally_indented_par_or_plain, + parsers.block_sep_group(parsers.list_blank), + parsers.par_sep_group(parsers.list_blank)) + + parsers.tight_list_content_loop + = V("Block") + * parsers.tight_list_loop_body_pair.block^0 + + (V("Paragraph") + V("Plain")) + * parsers.ref_or_block_non_separated + * parsers.tight_list_loop_body_pair.block^0 + + (V("Paragraph") + V("Plain")) + * parsers.tight_list_loop_body_pair.par^0 + + parsers.loose_list_content_loop + = V("Block") + * parsers.loose_list_loop_body_pair.block^0 + + (V("Paragraph") + V("Plain")) + * parsers.ref_or_block_list_separated + * parsers.loose_list_loop_body_pair.block^0 + + (V("Paragraph") + V("Plain")) + * parsers.loose_list_loop_body_pair.par^0 + + parsers.list_item_tightness_condition + = -#( parsers.list_blank^0 + * parsers.minimally_indented_ref_or_block_or_par) + * remove_indent("li") + + remove_indent("li") + * parsers.fail + + parsers.indented_content_tight + = Ct( (parsers.blankline / "") + * #parsers.list_blank + * remove_indent("li") + + ( (V("Reference") + (parsers.blankline / "")) + * parsers.check_minimal_indent + * parsers.tight_list_content_loop + + (V("Reference") + (parsers.blankline / "")) + + (parsers.tickbox^-1 / writer.escape) + * parsers.tight_list_content_loop + ) + * parsers.list_item_tightness_condition) + + parsers.indented_content_loose + = Ct( (parsers.blankline / "") + * #parsers.list_blank + + ( (V("Reference") + (parsers.blankline / "")) + * parsers.check_minimal_indent + * parsers.loose_list_content_loop + + (V("Reference") + (parsers.blankline / "")) + + (parsers.tickbox^-1 / writer.escape) + * parsers.loose_list_content_loop)) parsers.TightListItem = function(starter) return -parsers.ThematicBreak @@ -29465,13 +31234,15 @@ end local enumerator = parsers.enumerator(delimiter_type) return Cg(enumerator, "listtype") * (Ct( parsers.TightListItem(Cb("listtype")) - * ((parsers.check_minimal_indent / "") * parsers.TightListItem(enumerator))^0) + * ( (parsers.check_minimal_indent / "") + * parsers.TightListItem(enumerator))^0) * Cc(true) * -#((parsers.list_blank^0 / "") * parsers.check_minimal_indent * enumerator) + Ct( parsers.LooseListItem(Cb("listtype")) * ((parsers.list_blank^0 / "") - * (parsers.check_minimal_indent / "") * parsers.LooseListItem(enumerator))^0) + * (parsers.check_minimal_indent / "") + * parsers.LooseListItem(enumerator))^0) * Cc(false) ) * Ct(Cb("listtype")) / ordered_list end @@ -29524,15 +31295,21 @@ end - parsers.thematic_break_lines parsers.heading_text = parsers.heading_line - * ((V("Endline") / "\n") * (parsers.heading_line - parsers.heading_level))^0 + * ( (V("Endline") / "\n") + * ( parsers.heading_line + - parsers.heading_level))^0 * parsers.newline^-1 - parsers.SetextHeading = parsers.freeze_trail * parsers.check_trail_no_rem - * #(parsers.heading_text - * parsers.check_minimal_indent * parsers.check_trail * parsers.heading_level) + parsers.SetextHeading = parsers.freeze_trail + * parsers.check_trail_no_rem + * #( parsers.heading_text + * parsers.check_minimal_indent + * parsers.check_trail + * parsers.heading_level) * Cs(parsers.heading_text) / parsers.parse_heading_text - * parsers.check_minimal_indent_and_trail * parsers.heading_level + * parsers.check_minimal_indent_and_trail + * parsers.heading_level * parsers.newline * parsers.unfreeze_trail / writer.heading @@ -29584,14 +31361,18 @@ end local current_extension_name = nil self.insert_pattern = function(selector, pattern, pattern_name) assert(pattern_name == nil or type(pattern_name) == "string") - local _, _, lhs, pos, rhs = selector:find("^(%a+)%s+([%a%s]+%a+)%s+(%a+)$") + local _, _, lhs, pos, rhs + = selector:find("^(%a+)%s+([%a%s]+%a+)%s+(%a+)$") assert(lhs ~= nil, - [[Expected selector in form "LHS (before|after|instead of) RHS", not "]] + [[Expected selector in form ]] + .. [["LHS (before|after|instead of) RHS", not "]] .. selector .. [["]]) assert(walkable_syntax[lhs] ~= nil, - [[Rule ]] .. lhs .. [[ -> ... does not exist in markdown grammar]]) + [[Rule ]] .. lhs + .. [[ -> ... does not exist in markdown grammar]]) assert(pos == "before" or pos == "after" or pos == "instead of", - [[Expected positional specifier "before", "after", or "instead of", not "]] + [[Expected positional specifier "before", "after", ]] + .. [[or "instead of", not "]] .. pos .. [["]]) local rule = walkable_syntax[lhs] local index = nil @@ -29609,10 +31390,12 @@ end .. [[ does not exist in markdown grammar]]) local accountable_pattern if current_extension_name then - accountable_pattern = { pattern, current_extension_name, pattern_name } + accountable_pattern + = {pattern, current_extension_name, pattern_name} else assert(type(pattern) == "string", - [[reader->insert_pattern() was called outside an extension with ]] + [[reader->insert_pattern() was called outside ]] + .. [[an extension with ]] .. [[a PEG pattern instead of a rule name]]) accountable_pattern = pattern end @@ -29635,11 +31418,9 @@ end local syntax = { "Blocks", - Blocks = V("InitializeState") - * ( V("ExpectedJekyllData") - * (V("Blank")^0 / writer.interblocksep) - )^-1 - * V("Blank")^0 + Blocks = V("InitializeState") + * V("ExpectedJekyllData") + * V("Blank")^0 % \end{macrocode} % \par % \begin{markdown} @@ -29650,71 +31431,73 @@ end % % \end{markdown} % \begin{macrocode} - * ( V("Block") - * ( V("Blank")^0 * parsers.eof - + ( V("Blank")^2 / writer.paragraphsep - + V("Blank")^0 / writer.interblocksep - ) - ) - + ( V("Paragraph") + V("Plain") ) - * ( V("Blank")^0 * parsers.eof - + ( V("Blank")^2 / writer.paragraphsep - + V("Blank")^0 / writer.interblocksep - ) - ) - * V("Block") - * ( V("Blank")^0 * parsers.eof - + ( V("Blank")^2 / writer.paragraphsep - + V("Blank")^0 / writer.interblocksep - ) - ) - + ( V("Paragraph") + V("Plain") ) - * ( V("Blank")^0 * parsers.eof - + V("Blank")^0 / writer.paragraphsep - ) - )^0, - - ExpectedJekyllData = parsers.fail, - - Blank = parsers.Blank, - Reference = parsers.Reference, - - Blockquote = parsers.Blockquote, - Verbatim = parsers.Verbatim, - ThematicBreak = parsers.ThematicBreak, - BulletList = parsers.BulletList, - OrderedList = parsers.OrderedList, - DisplayHtml = parsers.DisplayHtml, - Heading = parsers.Heading, - Paragraph = parsers.Paragraph, - Plain = parsers.Plain, - - EndlineExceptions = parsers.EndlineExceptions, + * ( V("Block") + * ( V("Blank")^0 * parsers.eof + + ( V("Blank")^2 / writer.paragraphsep + + V("Blank")^0 / writer.interblocksep + ) + ) + + ( V("Paragraph") + V("Plain") ) + * ( V("Blank")^0 * parsers.eof + + ( V("Blank")^2 / writer.paragraphsep + + V("Blank")^0 / writer.interblocksep + ) + ) + * V("Block") + * ( V("Blank")^0 * parsers.eof + + ( V("Blank")^2 / writer.paragraphsep + + V("Blank")^0 / writer.interblocksep + ) + ) + + ( V("Paragraph") + V("Plain") ) + * ( V("Blank")^0 * parsers.eof + + V("Blank")^0 / writer.paragraphsep + ) + )^0, + + ExpectedJekyllData = parsers.succeed, + + Blank = parsers.Blank, + Reference = parsers.Reference, + + Blockquote = parsers.Blockquote, + Verbatim = parsers.Verbatim, + ThematicBreak = parsers.ThematicBreak, + BulletList = parsers.BulletList, + OrderedList = parsers.OrderedList, + DisplayHtml = parsers.DisplayHtml, + Heading = parsers.Heading, + Paragraph = parsers.Paragraph, + Plain = parsers.Plain, + + ListStarter = parsers.ListStarter, + EndlineExceptions = parsers.EndlineExceptions, NoSoftLineBreakEndlineExceptions - = parsers.NoSoftLineBreakEndlineExceptions, - - Str = parsers.Str, - Space = parsers.Space, - NoSoftLineBreakSpace = parsers.NoSoftLineBreakSpace, - OptionalIndent = parsers.OptionalIndent, - Endline = parsers.Endline, - EndlineNoSub = parsers.EndlineNoSub, + = parsers.NoSoftLineBreakEndlineExceptions, + + Str = parsers.Str, + Space = parsers.Space, + NoSoftLineBreakSpace + = parsers.NoSoftLineBreakSpace, + OptionalIndent = parsers.OptionalIndent, + Endline = parsers.Endline, + EndlineNoSub = parsers.EndlineNoSub, NoSoftLineBreakEndline - = parsers.NoSoftLineBreakEndline, - EndlineBreak = parsers.EndlineBreak, - LinkAndEmph = parsers.LinkAndEmph, - Code = parsers.Code, - AutoLinkUrl = parsers.AutoLinkUrl, - AutoLinkEmail = parsers.AutoLinkEmail, + = parsers.NoSoftLineBreakEndline, + EndlineBreak = parsers.EndlineBreak, + LinkAndEmph = parsers.LinkAndEmph, + Code = parsers.Code, + AutoLinkUrl = parsers.AutoLinkUrl, + AutoLinkEmail = parsers.AutoLinkEmail, AutoLinkRelativeReference - = parsers.AutoLinkRelativeReference, - InlineHtml = parsers.InlineHtml, - HtmlEntity = parsers.HtmlEntity, - EscapedChar = parsers.EscapedChar, - Smart = parsers.Smart, - Symbol = parsers.Symbol, - SpecialChar = parsers.fail, - InitializeState = parsers.succeed, + = parsers.AutoLinkRelativeReference, + InlineHtml = parsers.InlineHtml, + HtmlEntity = parsers.HtmlEntity, + EscapedChar = parsers.EscapedChar, + Smart = parsers.Smart, + Symbol = parsers.Symbol, + SpecialChar = parsers.fail, + InitializeState = parsers.succeed, } % \end{macrocode} % \par @@ -29732,13 +31515,17 @@ end self.update_rule = function(rule_name, get_pattern) assert(current_extension_name ~= nil) assert(syntax[rule_name] ~= nil, - [[Rule ]] .. rule_name .. [[ -> ... does not exist in markdown grammar]]) + [[Rule ]] .. rule_name + .. [[ -> ... does not exist in markdown grammar]]) local previous_pattern local extension_name if walkable_syntax[rule_name] then - local previous_accountable_pattern = walkable_syntax[rule_name][1] + local previous_accountable_pattern + = walkable_syntax[rule_name][1] previous_pattern = previous_accountable_pattern[1] - extension_name = previous_accountable_pattern[2] .. ", " .. current_extension_name + extension_name + = previous_accountable_pattern[2] + .. ", " .. current_extension_name else previous_pattern = nil extension_name = current_extension_name @@ -29868,9 +31655,11 @@ end pattern_name = "Anonymous Pattern" end local extension_name = rhs[2] - human_readable_rhs = pattern_name .. [[ (]] .. extension_name .. [[)]] + human_readable_rhs = pattern_name .. [[ (]] + .. extension_name .. [[)]] end - local encoded_rhs = util.encode_json_string(human_readable_rhs) + local encoded_rhs + = util.encode_json_string(human_readable_rhs) local output_line = [[ ]] .. encoded_rhs if rhs_index < #rule then output_line = output_line .. "," @@ -29888,7 +31677,8 @@ end local output = table.concat(output_lines, "\n") local output_filename = options.debugExtensionsFileName local output_file = assert(io.open(output_filename, "w"), - [[Could not open file "]] .. output_filename .. [[" for writing]]) + [[Could not open file "]] .. output_filename + .. [[" for writing]]) assert(output_file:write(output)) assert(output_file:close()) end @@ -29981,7 +31771,7 @@ end end local blocks_nested_t = util.table_copy(syntax) - blocks_nested_t.ExpectedJekyllData = parsers.fail + blocks_nested_t.ExpectedJekyllData = parsers.succeed parsers.blocks_nested = Ct(blocks_nested_t) parsers.blocks = Ct(syntax) @@ -30011,8 +31801,10 @@ end local inlines_no_link_or_emphasis_t = util.table_copy(inlines_t) inlines_no_link_or_emphasis_t.LinkAndEmph = parsers.fail - inlines_no_link_or_emphasis_t.EndlineExceptions = parsers.EndlineExceptions - parsers.eof - parsers.inlines_no_link_or_emphasis = Ct(inlines_no_link_or_emphasis_t) + inlines_no_link_or_emphasis_t.EndlineExceptions + = parsers.EndlineExceptions - parsers.eof + parsers.inlines_no_link_or_emphasis + = Ct(inlines_no_link_or_emphasis_t) % \end{macrocode} % \par % \begin{markdown} @@ -30039,7 +31831,8 @@ end elseif form == "nfkd" then input = uni_algos.normalize.NFKD(input) else - error(format("Unknown normalization form %s", form)) + return writer.error( + format("Unknown normalization form %s.", form)) end end % \end{macrocode} @@ -30055,30 +31848,12 @@ end end % \end{macrocode} % \begin{markdown} -% When determining the name of the cache file, create salt for the hashing -% function out of the package version and the passed options recognized by the -% Lua interface (see Section <#sec:lua-options>). The \Opt{cacheDir} option -% is disregarded. +% Clear the table of references. % \end{markdown} % \begin{macrocode} references = {} - local opt_string = {} - for k, _ in pairs(defaultOptions) do - local v = options[k] - if type(v) == "table" then - for _, i in ipairs(v) do - opt_string[#opt_string+1] = k .. "=" .. tostring(i) - end - elseif k ~= "cacheDir" then - opt_string[#opt_string+1] = k .. "=" .. tostring(v) - end - end - table.sort(opt_string) - local salt = table.concat(opt_string, ",") .. "," .. metadata.version - local output - local function convert(input) - local document = self.parser_functions.parse_blocks(input) - local output = util.rope_to_string(writer.document(document)) + local document = self.parser_functions.parse_blocks(input) + local output = util.rope_to_string(writer.document(document)) % \end{macrocode} % \begin{markdown} % Remove block element / paragraph separators immediately followed by the @@ -30086,82 +31861,49 @@ end % Then, remove any leftover output of \luamref{writer->undosep}. % \end{markdown} % \begin{macrocode} - local undosep_start, undosep_end - local potential_secend_start, secend_start - local potential_sep_start, sep_start + local undosep_start, undosep_end + local potential_secend_start, secend_start + local potential_sep_start, sep_start + while true do + -- find a `writer->undosep` + undosep_start, undosep_end + = output:find(writer.undosep_text, 1, true) + if undosep_start == nil then break end + -- skip any preceding section ends + secend_start = undosep_start while true do - -- find a `writer->undosep` - undosep_start, undosep_end = output:find(writer.undosep_text, 1, true) - if undosep_start == nil then break end - -- skip any preceding section ends - secend_start = undosep_start - while true do - potential_secend_start = secend_start - #writer.secend_text - if potential_secend_start < 1 - or output:sub(potential_secend_start, secend_start - 1) ~= writer.secend_text then - break - end - secend_start = potential_secend_start + potential_secend_start = secend_start - #writer.secend_text + if potential_secend_start < 1 + or output:sub(potential_secend_start, + secend_start - 1) ~= writer.secend_text + then + break end - -- find an immediately preceding block element / paragraph separator - sep_start = secend_start - potential_sep_start = sep_start - #writer.interblocksep_text + secend_start = potential_secend_start + end + -- find an immediately preceding + -- block element / paragraph separator + sep_start = secend_start + potential_sep_start = sep_start - #writer.interblocksep_text + if potential_sep_start >= 1 + and output:sub(potential_sep_start, + sep_start - 1) == writer.interblocksep_text + then + sep_start = potential_sep_start + else + potential_sep_start = sep_start - #writer.paragraphsep_text if potential_sep_start >= 1 - and output:sub(potential_sep_start, sep_start - 1) == writer.interblocksep_text then + and output:sub(potential_sep_start, + sep_start - 1) == writer.paragraphsep_text + then sep_start = potential_sep_start - else - potential_sep_start = sep_start - #writer.paragraphsep_text - if potential_sep_start >= 1 - and output:sub(potential_sep_start, sep_start - 1) == writer.paragraphsep_text then - sep_start = potential_sep_start - end end - -- remove `writer->undosep` and immediately preceding block element / paragraph separator - output = output:sub(1, sep_start - 1) - .. output:sub(secend_start, undosep_start - 1) - .. output:sub(undosep_end + 1) end - return output - end -% \end{macrocode} -% \begin{markdown} -% If we cache markdown documents, produce the cache file and transform its -% filename to plain \TeX{} output via the \luamref{writer->pack} method. -% \end{markdown} -% \begin{macrocode} - if options.eagerCache or options.finalizeCache then - local name = util.cache(options.cacheDir, input, salt, convert, - ".md" .. writer.suffix) - output = writer.pack(name) -% \end{macrocode} -% \begin{markdown} -% Otherwise, return the result of the conversion directly. -% \end{markdown} -% \begin{macrocode} - else - output = convert(input) - end -% \end{macrocode} -% \begin{markdown} -% If the \Opt{finalizeCache} option is enabled, populate the frozen cache in -% the file \Opt{frozenCacheFileName} with an entry for markdown document -% number \Opt{frozenCacheCounter}. -% \end{markdown} -% \begin{macrocode} - if options.finalizeCache then - local file, mode - if options.frozenCacheCounter > 0 then - mode = "a" - else - mode = "w" - end - file = assert(io.open(options.frozenCacheFileName, mode), - [[Could not open file "]] .. options.frozenCacheFileName - .. [[" for writing]]) - assert(file:write([[\expandafter\global\expandafter\def\csname ]] - .. [[markdownFrozenCache]] .. options.frozenCacheCounter - .. [[\endcsname{]] .. output .. [[}]] .. "\n")) - assert(file:close()) + -- remove `writer->undosep` and immediately preceding + -- block element / paragraph separator + output = output:sub(1, sep_start - 1) + .. output:sub(secend_start, undosep_start - 1) + .. output:sub(undosep_end + 1) end return output end @@ -30223,10 +31965,13 @@ M.extensions.bracketed_spans = function() + parsers.autolink + V("InlineHtml") + ( parsers.backslash * parsers.backslash) - + ( parsers.backslash * (parsers.lbracket + parsers.rbracket) + + ( parsers.backslash + * (parsers.lbracket + parsers.rbracket) + V("Space") + V("Endline") + (parsers.any - - (parsers.newline + parsers.lbracket + parsers.rbracket + - ( parsers.newline + + parsers.lbracket + + parsers.rbracket + parsers.blankline^2))))^1) / self.parser_functions.parse_inlines) * parsers.rbracket @@ -30289,11 +32034,15 @@ M.extensions.citations = function(citation_nbsps) end end else - table.insert(buffer, {"\\markdownRenderer", text_cites and "TextCite" or "Cite", - "{", #cites, "}"}) + table.insert(buffer, + {"\\markdownRenderer", + text_cites and "TextCite" or "Cite", + "{", #cites, "}"}) for _,cite in ipairs(cites) do - table.insert(buffer, {cite.suppress_author and "-" or "+", "{", - cite.prenote or "", "}{", cite.postnote or "", "}{", cite.name, "}"}) + table.insert(buffer, + {cite.suppress_author and "-" or "+", "{", + cite.prenote or "", "}{", + cite.postnote or "", "}{", cite.name, "}"}) end end return buffer @@ -30309,12 +32058,16 @@ M.extensions.citations = function(citation_nbsps) local citation_name = Cs(parsers.dash^-1) * parsers.at * Cs(citation_chars - * (((citation_chars + parsers.internal_punctuation + * ((( citation_chars + + parsers.internal_punctuation - parsers.comma - parsers.semicolon) - * -#((parsers.internal_punctuation - parsers.comma + * -#(( parsers.internal_punctuation + - parsers.comma - parsers.semicolon)^0 - * -(citation_chars + parsers.internal_punctuation - - parsers.comma - parsers.semicolon)))^0 + * -( citation_chars + + parsers.internal_punctuation + - parsers.comma + - parsers.semicolon)))^0 * citation_chars)^-1) local citation_body_prenote @@ -30323,10 +32076,14 @@ M.extensions.citations = function(citation_nbsps) + parsers.inticks + parsers.autolink + V("InlineHtml") - + V("Space") + V("Endline") + + V("Space") + V("EndlineNoSub") + (parsers.anyescaped - - (parsers.newline + parsers.rbracket + parsers.blankline^2)) - - (parsers.spnl * parsers.dash^-1 * parsers.at))^1) + - ( parsers.newline + + parsers.rbracket + + parsers.blankline^2)) + - ( parsers.spnl + * parsers.dash^-1 + * parsers.at))^1) local citation_body_postnote = Cs((parsers.alphanumeric^1 @@ -30334,9 +32091,11 @@ M.extensions.citations = function(citation_nbsps) + parsers.inticks + parsers.autolink + V("InlineHtml") - + V("Space") + V("Endline") + + V("Space") + V("EndlineNoSub") + (parsers.anyescaped - - (parsers.newline + parsers.rbracket + parsers.semicolon + - ( parsers.newline + + parsers.rbracket + + parsers.semicolon + parsers.blankline^2)) - (parsers.spnl * parsers.rbracket))^1) @@ -30347,8 +32106,9 @@ M.extensions.citations = function(citation_nbsps) * parsers.spnlc ) * citation_name - * (parsers.internal_punctuation - parsers.semicolon)^-1 - * ( parsers.spnlc + * ( parsers.internal_punctuation + - parsers.semicolon)^-1 + * ( parsers.spnlc / function(_) return end * citation_body_postnote + Cc("") * parsers.spnlc @@ -30369,7 +32129,9 @@ M.extensions.citations = function(citation_nbsps) + V("InlineHtml") + V("Space") + V("Endline") + (parsers.anyescaped - - (parsers.newline + parsers.rbracket + parsers.at + - ( parsers.newline + + parsers.rbracket + + parsers.at + parsers.semicolon + parsers.blankline^2)) - (parsers.spnl * parsers.rbracket))^0) @@ -30463,7 +32225,8 @@ M.extensions.content_blocks = function(language_map) % \begin{macrocode} local languages_json = (function() local base, prev, curr - for _, pathname in ipairs{kpse.lookup(language_map, { all=true })} do + for _, pathname in ipairs{kpse.lookup(language_map, + {all=true})} do local file = io.open(pathname, "r") if not file then goto continue end local input = assert(file:read("*a")) @@ -30504,20 +32267,20 @@ M.extensions.content_blocks = function(language_map) suf = suf:lower() if type == "onlineimage" then return {"\\markdownRendererContentBlockOnlineImage{",suf,"}", - "{",self.string(src),"}", - "{",self.uri(src),"}", - "{",self.string(tit or ""),"}"} + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} elseif languages_json[suf] then return {"\\markdownRendererContentBlockCode{",suf,"}", - "{",self.string(languages_json[suf]),"}", - "{",self.string(src),"}", - "{",self.uri(src),"}", - "{",self.string(tit or ""),"}"} + "{",self.string(languages_json[suf]),"}", + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} else return {"\\markdownRendererContentBlock{",suf,"}", - "{",self.string(src),"}", - "{",self.uri(src),"}", - "{",self.string(tit or ""),"}"} + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} end end end, extend_reader = function(self) @@ -30552,8 +32315,8 @@ M.extensions.content_blocks = function(language_map) return parser end)("png", "jpg", "jpeg", "gif", "tif", "tiff") - -- online image url for iA Writer content blocks with mandatory suffix, - -- allowing nested brackets: + -- online image url for iA Writer content blocks with + -- mandatory suffix, allowing nested brackets: local onlineimageurl = (parsers.less * Cs((parsers.anyescaped @@ -30631,8 +32394,9 @@ M.extensions.definition_lists = function(tight_lists) local function dlitem(term, defs) local retVal = {"\\markdownRendererDlItem{",term,"}"} for _, def in ipairs(defs) do - retVal[#retVal+1] = {"\\markdownRendererDlDefinitionBegin ",def, - "\\markdownRendererDlDefinitionEnd "} + retVal[#retVal+1] + = {"\\markdownRendererDlDefinitionBegin ",def, + "\\markdownRendererDlDefinitionEnd "} end retVal[#retVal+1] = "\\markdownRendererDlItemEnd " return retVal @@ -30658,17 +32422,26 @@ M.extensions.definition_lists = function(tight_lists) local defstartchar = S("~:") - local defstart = parsers.check_trail_length(0) * defstartchar * #parsers.spacing - * (parsers.tab + parsers.space^-3) - + parsers.check_trail_length(1) * defstartchar * #parsers.spacing - * (parsers.tab + parsers.space^-2) - + parsers.check_trail_length(2) * defstartchar * #parsers.spacing - * (parsers.tab + parsers.space^-1) - + parsers.check_trail_length(3) * defstartchar * #parsers.spacing - - local indented_line = (parsers.check_minimal_indent / "") * parsers.check_code_trail * parsers.line - - local blank = parsers.check_minimal_blank_indent_and_any_trail * parsers.optionalspace * parsers.newline + local defstart + = parsers.check_trail_length(0) * defstartchar + * #parsers.spacing + * (parsers.tab + parsers.space^-3) + + parsers.check_trail_length(1) + * defstartchar * #parsers.spacing + * (parsers.tab + parsers.space^-2) + + parsers.check_trail_length(2) + * defstartchar * #parsers.spacing + * (parsers.tab + parsers.space^-1) + + parsers.check_trail_length(3) + * defstartchar * #parsers.spacing + + local indented_line + = (parsers.check_minimal_indent / "") + * parsers.check_code_trail * parsers.line + + local blank + = parsers.check_minimal_blank_indent_and_any_trail + * parsers.optionalspace * parsers.newline local dlchunk = Cs(parsers.line * (indented_line - blank)^0) @@ -30685,24 +32458,24 @@ M.extensions.definition_lists = function(tight_lists) end local DefinitionListItemLoose - = C(parsers.line) * blank^0 - * Ct((parsers.check_minimal_indent * (defstart - * indented_blocks(dlchunk) - / self.parser_functions.parse_blocks_nested))^1) - * Cc(false) / definition_list_item + = C(parsers.line) * blank^0 + * Ct((parsers.check_minimal_indent * (defstart + * indented_blocks(dlchunk) + / self.parser_functions.parse_blocks_nested))^1) + * Cc(false) / definition_list_item local DefinitionListItemTight - = C(parsers.line) - * Ct((parsers.check_minimal_indent * (defstart * dlchunk - / self.parser_functions.parse_blocks_nested))^1) - * Cc(true) / definition_list_item + = C(parsers.line) + * Ct((parsers.check_minimal_indent * (defstart * dlchunk + / self.parser_functions.parse_blocks_nested))^1) + * Cc(true) / definition_list_item local DefinitionList - = ( Ct(DefinitionListItemLoose^1) * Cc(false) - + Ct(DefinitionListItemTight^1) - * (blank^0 - * -DefinitionListItemLoose * Cc(true)) - ) / writer.definitionlist + = ( Ct(DefinitionListItemLoose^1) * Cc(false) + + Ct(DefinitionListItemTight^1) + * (blank^0 + * -DefinitionListItemLoose * Cc(true)) + ) / writer.definitionlist self.insert_pattern("Block after Heading", DefinitionList, "DefinitionList") @@ -30787,7 +32560,8 @@ M.extensions.fancy_lists = function() return {"\\markdownRendererFancyOlItemWithNumber{",num,"}",s, "\\markdownRendererFancyOlItemEnd "} else - return {"\\markdownRendererFancyOlItem ",s,"\\markdownRendererFancyOlItemEnd "} + return {"\\markdownRendererFancyOlItem ",s, + "\\markdownRendererFancyOlItemEnd "} end end end, extend_reader = function(self) @@ -30808,7 +32582,8 @@ M.extensions.fancy_lists = function() continuation_marker = marker end for _,delim in ipairs(delims) do - table.insert(markers_table, {start_marker, continuation_marker, delim}) + table.insert(markers_table, + {start_marker, continuation_marker, delim}) end end return markers_table @@ -30827,15 +32602,18 @@ M.extensions.fancy_lists = function() local roman_marker = function(chars) local m, d, c = P(chars[1]), P(chars[2]), P(chars[3]) - local l, x, v, i = P(chars[4]), P(chars[5]), P(chars[6]), P(chars[7]) + local l, x, v, i + = P(chars[4]), P(chars[5]), P(chars[6]), P(chars[7]) return m^-3 * (c*m + c*d + d^-1 * c^-3) * (x*c + x*l + l^-1 * x^-3) * (i*x + i*v + v^-1 * i^-3) end - local lowercase_roman_marker = roman_marker({"m", "d", "c", "l", "x", "v", "i"}) - local uppercase_roman_marker = roman_marker({"M", "D", "C", "L", "X", "V", "I"}) + local lowercase_roman_marker + = roman_marker({"m", "d", "c", "l", "x", "v", "i"}) + local uppercase_roman_marker + = roman_marker({"M", "D", "C", "L", "X", "V", "I"}) local lowercase_opening_roman_marker = P("i") local uppercase_opening_roman_marker = P("I") @@ -30859,7 +32637,8 @@ M.extensions.fancy_lists = function() local markers_table = combine_markers_and_delims(markers, delims) - local function enumerator(start_marker, _, delimiter_type, interrupting) + local function enumerator(start_marker, _, + delimiter_type, interrupting) local delimiter_range local allowed_end if interrupting then @@ -30867,7 +32646,8 @@ M.extensions.fancy_lists = function() allowed_end = C(parsers.spacechar^1) * #parsers.linechar else delimiter_range = start_marker - allowed_end = C(parsers.spacechar^1) + #(parsers.newline + parsers.eof) + allowed_end = C(parsers.spacechar^1) + + #(parsers.newline + parsers.eof) end return parsers.check_trail @@ -30889,13 +32669,15 @@ M.extensions.fancy_lists = function() end local function roman2number(roman) - local romans = { ["M"] = 1000, ["D"] = 500, ["C"] = 100, ["L"] = 50, ["X"] = 10, ["V"] = 5, ["I"] = 1 } + local romans = { ["M"] = 1000, ["D"] = 500, ["C"] = 100, + ["L"] = 50, ["X"] = 10, ["V"] = 5, ["I"] = 1 } local numeral = 0 local i = 1 local len = string.len(roman) while i < len do - local z1, z2 = romans[ string.sub(roman, i, i) ], romans[ string.sub(roman, i+1, i+1) ] + local z1, z2 = romans[ string.sub(roman, i, i) ], + romans[ string.sub(roman, i+1, i+1) ] if z1 < z2 then numeral = numeral + (z2 - z1) i = i + 2 @@ -30904,7 +32686,9 @@ M.extensions.fancy_lists = function() i = i + 1 end end - if i <= len then numeral = numeral + romans[ string.sub(roman,i,i) ] end + if i <= len then + numeral = numeral + romans[ string.sub(roman,i,i) ] + end return numeral end @@ -30929,11 +32713,13 @@ M.extensions.fancy_lists = function() end num = numstr:match("^([A-Z])$") if num then - return string.byte(num) - string.byte("A") + 1, "UpperAlpha", numdelim + return string.byte(num) - string.byte("A") + 1, + "UpperAlpha", numdelim end num = numstr:match("^([a-z])$") if num then - return string.byte(num) - string.byte("a") + 1, "LowerAlpha", numdelim + return string.byte(num) - string.byte("a") + 1, + "LowerAlpha", numdelim end num = numstr:match("^([IVXLCDM]+)") if num then @@ -30947,42 +32733,44 @@ M.extensions.fancy_lists = function() end local function fancylist(items,tight,start) - local startnum, numstyle, numdelim = sniffstyle(start[2][1], start[2][2]) + local startnum, numstyle, numdelim + = sniffstyle(start[2][1], start[2][2]) return writer.fancylist(items,tight, options.startNumber and startnum or 1, numstyle or "Decimal", numdelim or "Default") end - local FancyListOfType = function(start_marker, continuation_marker, delimiter_type) - local enumerator_start = enumerator(start_marker, continuation_marker, delimiter_type) - local enumerator_cont = enumerator(continuation_marker, continuation_marker, delimiter_type) - return Cg(enumerator_start, "listtype") - * (Ct( TightListItem(Cb("listtype")) - * ((parsers.check_minimal_indent / "") * TightListItem(enumerator_cont))^0) - * Cc(true) - * -#((parsers.conditionally_indented_blankline^0 / "") - * parsers.check_minimal_indent * enumerator_cont) - + Ct( LooseListItem(Cb("listtype")) - * ((parsers.conditionally_indented_blankline^0 / "") - * (parsers.check_minimal_indent / "") * LooseListItem(enumerator_cont))^0) - * Cc(false) - ) * Ct(Cb("listtype")) / fancylist - end + local FancyListOfType + = function(start_marker, continuation_marker, delimiter_type) + local enumerator_start + = enumerator(start_marker, continuation_marker, + delimiter_type) + local enumerator_cont + = enumerator(continuation_marker, continuation_marker, + delimiter_type) + return Cg(enumerator_start, "listtype") + * (Ct( TightListItem(Cb("listtype")) + * ((parsers.check_minimal_indent / "") + * TightListItem(enumerator_cont))^0) + * Cc(true) + * -#((parsers.conditionally_indented_blankline^0 / "") + * parsers.check_minimal_indent * enumerator_cont) + + Ct( LooseListItem(Cb("listtype")) + * ((parsers.conditionally_indented_blankline^0 / "") + * (parsers.check_minimal_indent / "") + * LooseListItem(enumerator_cont))^0) + * Cc(false) + ) * Ct(Cb("listtype")) / fancylist + end - local FancyList = join_table_with_func(FancyListOfType, markers_table) + local FancyList + = join_table_with_func(FancyListOfType, markers_table) - local Endline = parsers.newline - * (parsers.check_minimal_indent - * -parsers.EndlineExceptions - + parsers.check_optional_indent - * -parsers.EndlineExceptions - * -starter) - * parsers.spacechar^0 - / writer.soft_line_break + local ListStarter = starter self.update_rule("OrderedList", FancyList) - self.update_rule("Endline", Endline) + self.update_rule("ListStarter", ListStarter) end } end @@ -31026,14 +32814,17 @@ M.extensions.fenced_code = function(blank_before_code_fence, s = s:gsub("\n$", "") local buf = {} if attr ~= nil then - table.insert(buf, {"\\markdownRendererFencedCodeAttributeContextBegin", - self.attributes(attr)}) + table.insert(buf, + {"\\markdownRendererFencedCodeAttributeContextBegin", + self.attributes(attr)}) end local name = util.cache_verbatim(options.cacheDir, s) - table.insert(buf, {"\\markdownRendererInputFencedCode{", - name,"}{",self.string(i),"}{",self.infostring(i),"}"}) + table.insert(buf, + {"\\markdownRendererInputFencedCode{", + name,"}{",self.string(i),"}{",self.infostring(i),"}"}) if attr ~= nil then - table.insert(buf, "\\markdownRendererFencedCodeAttributeContextEnd{}") + table.insert(buf, + "\\markdownRendererFencedCodeAttributeContextEnd{}") end return buf end @@ -31073,11 +32864,13 @@ M.extensions.fenced_code = function(blank_before_code_fence, - parsers.newline)^0) / strip_enclosing_whitespaces) - local backtick_infostring = Cs(Cs((V("HtmlEntity") - + (-#(parsers.backslash * parsers.backtick) * parsers.anyescaped) - - parsers.newline - - parsers.backtick)^0) - / strip_enclosing_whitespaces) + local backtick_infostring + = Cs( Cs((V("HtmlEntity") + + ( -#(parsers.backslash * parsers.backtick) + * parsers.anyescaped) + - parsers.newline + - parsers.backtick)^0) + / strip_enclosing_whitespaces) local fenceindent @@ -31099,77 +32892,93 @@ M.extensions.fenced_code = function(blank_before_code_fence, end end - local function count_fenced_start_indent(_, _, indent_table, trail) - local last_indent_name = get_last_indent_name(indent_table) - fenceindent = 0 - if last_indent_name ~= "li" then - fenceindent = #trail + local count_fenced_start_indent = + function(_, _, indent_table, trail) + local last_indent_name = get_last_indent_name(indent_table) + fenceindent = 0 + if last_indent_name ~= "li" then + fenceindent = #trail + end + return true end - return true - end - local fencehead = function(char, infostring) - return Cmt(Cb("indent_info") * parsers.check_trail, count_fenced_start_indent) - * Cg(char^3, "fencelength") - * parsers.optionalspace - * infostring - * (parsers.newline + parsers.eof) + local fencehead = function(char, infostring) + return Cmt( Cb("indent_info") + * parsers.check_trail, count_fenced_start_indent) + * Cg(char^3, "fencelength") + * parsers.optionalspace + * infostring + * (parsers.newline + parsers.eof) end - local fencetail = function(char) - return parsers.check_trail_no_rem - * Cmt(C(char^3) * Cb("fencelength"), captures_geq_length) - * parsers.optionalspace * (parsers.newline + parsers.eof) - + parsers.eof + local fencetail = function(char) + return parsers.check_trail_no_rem + * Cmt(C(char^3) * Cb("fencelength"), captures_geq_length) + * parsers.optionalspace * (parsers.newline + parsers.eof) + + parsers.eof end - local function process_fenced_line(s, i, indent_table, line_content, is_blank) -- luacheck: ignore s i - local remainder = "" - if has_trail(indent_table) then - remainder = indent_table.trail.internal_remainder - end + local process_fenced_line = + function(s, i, -- luacheck: ignore s i + indent_table, line_content, is_blank) + local remainder = "" + if has_trail(indent_table) then + remainder = indent_table.trail.internal_remainder + end - if is_blank and get_last_indent_name(indent_table) == "li" then - remainder = "" - end + if is_blank + and get_last_indent_name(indent_table) == "li" then + remainder = "" + end - local str = remainder .. line_content - local index = 1 - local remaining = fenceindent + local str = remainder .. line_content + local index = 1 + local remaining = fenceindent - while true do - local c = str:sub(index, index) - if c == " " and remaining > 0 then - remaining = remaining - 1 - index = index + 1 - elseif c == "\t" and remaining > 3 then - remaining = remaining - 4 - index = index + 1 - else - break + while true do + local c = str:sub(index, index) + if c == " " and remaining > 0 then + remaining = remaining - 1 + index = index + 1 + elseif c == "\t" and remaining > 3 then + remaining = remaining - 4 + index = index + 1 + else + break + end end - end - return true, str:sub(index) - end + return true, str:sub(index) + end local fencedline = function(char) - return Cmt(Cb("indent_info") * C(parsers.line - fencetail(char)) * Cc(false), process_fenced_line) + return Cmt( Cb("indent_info") + * C(parsers.line - fencetail(char)) + * Cc(false), process_fenced_line) end - local blankfencedline = Cmt(Cb("indent_info") * C(parsers.blankline) * Cc(true), process_fenced_line) + local blankfencedline + = Cmt( Cb("indent_info") + * C(parsers.blankline) + * Cc(true), process_fenced_line) local TildeFencedCode - = fencehead(parsers.tilde, tilde_infostring) - * Cs(((parsers.check_minimal_blank_indent / "") * blankfencedline - + (parsers.check_minimal_indent / "") * fencedline(parsers.tilde))^0) - * ((parsers.check_minimal_indent / "") * fencetail(parsers.tilde) + parsers.succeed) + = fencehead(parsers.tilde, tilde_infostring) + * Cs(( (parsers.check_minimal_blank_indent / "") + * blankfencedline + + ( parsers.check_minimal_indent / "") + * fencedline(parsers.tilde))^0) + * ( (parsers.check_minimal_indent / "") + * fencetail(parsers.tilde) + parsers.succeed) local BacktickFencedCode = fencehead(parsers.backtick, backtick_infostring) - * Cs(((parsers.check_minimal_blank_indent / "") * blankfencedline - + (parsers.check_minimal_indent / "") * fencedline(parsers.backtick))^0) - * ((parsers.check_minimal_indent / "") * fencetail(parsers.backtick) + parsers.succeed) + * Cs(( (parsers.check_minimal_blank_indent / "") + * blankfencedline + + (parsers.check_minimal_indent / "") + * fencedline(parsers.backtick))^0) + * ( (parsers.check_minimal_indent / "") + * fencetail(parsers.backtick) + parsers.succeed) local infostring_with_attributes = Ct(C((parsers.linechar @@ -31179,28 +32988,28 @@ M.extensions.fenced_code = function(blank_before_code_fence, * Ct(parsers.attributes)) local FencedCode - = ((TildeFencedCode + BacktickFencedCode) - / function(infostring, code) - local expanded_code = self.expandtabs(code) - - if allow_raw_blocks then - local raw_attr = lpeg.match(parsers.raw_attribute, - infostring) - if raw_attr then - return writer.rawBlock(expanded_code, raw_attr) - end - end - - local attr = nil - if allow_attributes then - local match = lpeg.match(infostring_with_attributes, - infostring) - if match then - infostring, attr = table.unpack(match) - end - end - return writer.fencedCode(expanded_code, infostring, attr) - end) + = ((TildeFencedCode + BacktickFencedCode) + / function(infostring, code) + local expanded_code = self.expandtabs(code) + + if allow_raw_blocks then + local raw_attr = lpeg.match(parsers.raw_attribute, + infostring) + if raw_attr then + return writer.rawBlock(expanded_code, raw_attr) + end + end + + local attr = nil + if allow_attributes then + local match = lpeg.match(infostring_with_attributes, + infostring) + if match then + infostring, attr = table.unpack(match) + end + end + return writer.fencedCode(expanded_code, infostring, attr) + end) self.insert_pattern("Block after Verbatim", FencedCode, "FencedCode") @@ -31252,10 +33061,13 @@ M.extensions.fenced_divs = function(blank_before_div_fence) % \end{markdown} % \begin{macrocode} function self.div_begin(attributes) - local start_output = {"\\markdownRendererFencedDivAttributeContextBegin\n", - self.attributes(attributes)} - local end_output = {"\\markdownRendererFencedDivAttributeContextEnd{}"} - return self.push_attributes("div", attributes, start_output, end_output) + local start_output + = {"\\markdownRendererFencedDivAttributeContextBegin\n", + self.attributes(attributes)} + local end_output + = {"\\markdownRendererFencedDivAttributeContextEnd{}"} + return self.push_attributes( + "div", attributes, start_output, end_output) end % \end{macrocode} % \par @@ -31316,21 +33128,24 @@ M.extensions.fenced_divs = function(blank_before_div_fence) self.initialize_named_group("fenced_div_num_opening_indents") local function increment_div_level() - local function push_indent_table(s, i, indent_table, -- luacheck: ignore s i - fenced_div_num_opening_indents, fenced_div_level) - fenced_div_level = tonumber(fenced_div_level) + 1 - local num_opening_indents = 0 - if indent_table.indents ~= nil then - num_opening_indents = #indent_table.indents + local push_indent_table = + function(s, i, indent_table, -- luacheck: ignore s i + fenced_div_num_opening_indents, fenced_div_level) + fenced_div_level = tonumber(fenced_div_level) + 1 + local num_opening_indents = 0 + if indent_table.indents ~= nil then + num_opening_indents = #indent_table.indents + end + fenced_div_num_opening_indents[fenced_div_level] + = num_opening_indents + return true, fenced_div_num_opening_indents end - fenced_div_num_opening_indents[fenced_div_level] = num_opening_indents - return true, fenced_div_num_opening_indents - end - local function increment_level(s, i, fenced_div_level) -- luacheck: ignore s i - fenced_div_level = tonumber(fenced_div_level) + 1 - return true, tostring(fenced_div_level) - end + local increment_level = + function(s, i, fenced_div_level) -- luacheck: ignore s i + fenced_div_level = tonumber(fenced_div_level) + 1 + return true, tostring(fenced_div_level) + end return Cg( Cmt( Cb("indent_info") * Cb("fenced_div_num_opening_indents") @@ -31341,11 +33156,13 @@ M.extensions.fenced_divs = function(blank_before_div_fence) end local function decrement_div_level() - local function pop_indent_table(s, i, fenced_div_indent_table, fenced_div_level) -- luacheck: ignore s i - fenced_div_level = tonumber(fenced_div_level) - fenced_div_indent_table[fenced_div_level] = nil - return true, tostring(fenced_div_level - 1) - end + local pop_indent_table = + function(s, i, -- luacheck: ignore s i + fenced_div_indent_table, fenced_div_level) + fenced_div_level = tonumber(fenced_div_level) + fenced_div_indent_table[fenced_div_level] = nil + return true, tostring(fenced_div_level - 1) + end return Cg( Cmt( Cb("fenced_div_num_opening_indents") * Cb("fenced_div_level"), pop_indent_table) @@ -31353,21 +33170,24 @@ M.extensions.fenced_divs = function(blank_before_div_fence) end - local non_fenced_div_block = parsers.check_minimal_indent * V("Block") - - parsers.check_minimal_indent_and_trail * fenced_div_end + local non_fenced_div_block + = parsers.check_minimal_indent * V("Block") + - parsers.check_minimal_indent_and_trail * fenced_div_end - local non_fenced_div_paragraph = parsers.check_minimal_indent * V("Paragraph") - - parsers.check_minimal_indent_and_trail * fenced_div_end + local non_fenced_div_paragraph + = parsers.check_minimal_indent * V("Paragraph") + - parsers.check_minimal_indent_and_trail * fenced_div_end local blank = parsers.minimally_indented_blank - local block_separated = parsers.block_sep_group(blank) - * non_fenced_div_block + local block_separated = parsers.block_sep_group(blank) + * non_fenced_div_block - local loop_body_pair = parsers.create_loop_body_pair(block_separated, - non_fenced_div_paragraph, - parsers.block_sep_group(blank), - parsers.par_sep_group(blank)) + local loop_body_pair + = parsers.create_loop_body_pair(block_separated, + non_fenced_div_paragraph, + parsers.block_sep_group(blank), + parsers.par_sep_group(blank)) local content_loop = ( non_fenced_div_block * loop_body_pair.block^0 @@ -31380,7 +33200,9 @@ M.extensions.fenced_divs = function(blank_before_div_fence) local FencedDiv = fenced_div_begin / function (infostring) - local attr = lpeg.match(Ct(parsers.attributes), infostring) + local attr + = lpeg.match(Ct(parsers.attributes), + infostring) if attr == nil then attr = {"." .. infostring} end @@ -31391,7 +33213,8 @@ M.extensions.fenced_divs = function(blank_before_div_fence) * parsers.skipblanklines * Ct(content_loop) * parsers.minimally_indented_blank^0 - * parsers.check_minimal_indent_and_trail * fenced_div_end + * parsers.check_minimal_indent_and_trail + * fenced_div_end * decrement_div_level() * (Cc("") / writer.div_end) @@ -31412,23 +33235,27 @@ M.extensions.fenced_divs = function(blank_before_div_fence) % \end{markdown} % \begin{macrocode} local function is_inside_div() - local function check_div_level(s, i, fenced_div_level) -- luacheck: ignore s i - fenced_div_level = tonumber(fenced_div_level) - return fenced_div_level > 0 - end + local check_div_level = + function(s, i, fenced_div_level) -- luacheck: ignore s i + fenced_div_level = tonumber(fenced_div_level) + return fenced_div_level > 0 + end return Cmt(Cb("fenced_div_level"), check_div_level) end local function check_indent() - local function compare_indent(s, i, indent_table, -- luacheck: ignore s i - fenced_div_num_opening_indents, fenced_div_level) - fenced_div_level = tonumber(fenced_div_level) - local num_current_indents = (indent_table.current_line_indents ~= nil and - #indent_table.current_line_indents) or 0 - local num_opening_indents = fenced_div_num_opening_indents[fenced_div_level] - return num_current_indents == num_opening_indents - end + local compare_indent = + function(s, i, indent_table, -- luacheck: ignore s i + fenced_div_num_opening_indents, fenced_div_level) + fenced_div_level = tonumber(fenced_div_level) + local num_current_indents + = ( indent_table.current_line_indents ~= nil and + #indent_table.current_line_indents) or 0 + local num_opening_indents + = fenced_div_num_opening_indents[fenced_div_level] + return num_current_indents == num_opening_indents + end return Cmt( Cb("indent_info") * Cb("fenced_div_num_opening_indents") @@ -31500,26 +33327,31 @@ M.extensions.header_attributes = function() * parsers.newline))^1 - parsers.thematic_break_lines - local heading_text = heading_line - * ((V("Endline") / "\n") * (heading_line - parsers.heading_level))^0 - * parsers.newline^-1 - - local SetextHeading = parsers.freeze_trail * parsers.check_trail_no_rem - * #(heading_text - * (parsers.attributes - * parsers.optionalspace - * parsers.newline)^-1 - * parsers.check_minimal_indent * parsers.check_trail * parsers.heading_level) - * Cs(heading_text) / strip_trailing_spaces - / parsers.parse_heading_text - * Cg(Ct((parsers.attributes - * parsers.optionalspace - * parsers.newline)^-1), "attributes") - * parsers.check_minimal_indent_and_trail * parsers.heading_level - * Cb("attributes") - * parsers.newline - * parsers.unfreeze_trail - / writer.heading + local heading_text + = heading_line + * ( (V("Endline") / "\n") + * (heading_line - parsers.heading_level))^0 + * parsers.newline^-1 + + local SetextHeading + = parsers.freeze_trail * parsers.check_trail_no_rem + * #(heading_text + * (parsers.attributes + * parsers.optionalspace + * parsers.newline)^-1 + * parsers.check_minimal_indent + * parsers.check_trail + * parsers.heading_level) + * Cs(heading_text) / strip_trailing_spaces + / parsers.parse_heading_text + * Cg(Ct((parsers.attributes + * parsers.optionalspace + * parsers.newline)^-1), "attributes") + * parsers.check_minimal_indent_and_trail * parsers.heading_level + * Cb("attributes") + * parsers.newline + * parsers.unfreeze_trail + / writer.heading local Heading = AtxHeading + SetextHeading self.update_rule("Heading", Heading) @@ -31593,18 +33425,18 @@ M.extensions.line_blocks = function() local parsers = self.parsers local writer = self.writer - local LineBlock = Ct( - (Cs( - ( (parsers.pipe * parsers.space)/"" - * ((parsers.space)/entities.char_entity("nbsp"))^0 - * parsers.linechar^0 * (parsers.newline/"")) - * (-parsers.pipe - * (parsers.space^1/" ") - * parsers.linechar^1 - * (parsers.newline/"") - )^0 - * (parsers.blankline/"")^0 - ) / self.parser_functions.parse_inlines)^1) / writer.lineblock + local LineBlock + = Ct((Cs(( (parsers.pipe * parsers.space) / "" + * ((parsers.space)/entities.char_entity("nbsp"))^0 + * parsers.linechar^0 * (parsers.newline/"")) + * (-parsers.pipe + * (parsers.space^1/" ") + * parsers.linechar^1 + * (parsers.newline/"") + )^0 + * (parsers.blankline/"")^0) + / self.parser_functions.parse_inlines)^1) + / writer.lineblock self.insert_pattern("Block after Blockquote", LineBlock, "LineBlock") @@ -31644,8 +33476,9 @@ M.extensions.mark = function() local doubleequals = P("==") - local Mark = parsers.between(V("Inline"), doubleequals, doubleequals) - / function (inlines) return writer.mark(inlines) end + 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", @@ -31678,13 +33511,18 @@ M.extensions.link_attributes = function() % % \end{markdown} % \begin{macrocode} - local define_reference_parser = (parsers.check_trail / "") * parsers.link_label * parsers.colon - * parsers.spnlc * parsers.url - * ( parsers.spnlc_sep * parsers.title * (parsers.spnlc * Ct(parsers.attributes)) - * parsers.only_blank - + parsers.spnlc_sep * parsers.title * parsers.only_blank - + Cc("") * (parsers.spnlc * Ct(parsers.attributes)) * parsers.only_blank - + Cc("") * parsers.only_blank) + local define_reference_parser + = (parsers.check_trail / "") + * parsers.link_label + * parsers.colon + * parsers.spnlc * parsers.url + * ( parsers.spnlc_sep * parsers.title + * (parsers.spnlc * Ct(parsers.attributes)) + * parsers.only_blank + + parsers.spnlc_sep * parsers.title * parsers.only_blank + + Cc("") * (parsers.spnlc * Ct(parsers.attributes)) + * parsers.only_blank + + Cc("") * parsers.only_blank) local ReferenceWithAttributes = define_reference_parser / self.register_link @@ -31699,8 +33537,10 @@ M.extensions.link_attributes = function() % \end{markdown} % \begin{macrocode} - local LinkWithAttributesAndEmph = Ct(parsers.link_and_emph_table * Cg(Cc(true), "match_link_attributes")) - / self.defer_link_and_emphasis_processing + local LinkWithAttributesAndEmph + = Ct(parsers.link_and_emph_table * Cg(Cc(true), + "match_link_attributes")) + / self.defer_link_and_emphasis_processing self.update_rule("LinkAndEmph", LinkWithAttributesAndEmph) @@ -31781,11 +33621,14 @@ M.extensions.notes = function(notes, inline_notes) local parsers = self.parsers local writer = self.writer + local rawnotes = parsers.rawnotes + if inline_notes then local InlineNote - = parsers.circumflex - * (parsers.link_label / self.parser_functions.parse_inlines_no_inline_note) - / writer.note + = parsers.circumflex + * ( parsers.link_label + / self.parser_functions.parse_inlines_no_inline_note) + / writer.note self.insert_pattern("Inline after LinkAndEmph", InlineNote, "InlineNote") @@ -31799,8 +33642,6 @@ M.extensions.notes = function(notes, inline_notes) = #(parsers.lbracket * parsers.circumflex) * parsers.link_label / strip_first_char - local rawnotes = {} - -- like indirect_link local function lookup_note(ref) return writer.defer_call(function() @@ -31825,20 +33666,27 @@ M.extensions.notes = function(notes, inline_notes) local NoteRef = RawNoteRef / lookup_note - local optionally_indented_line = parsers.check_optional_indent_and_any_trail * parsers.line + local optionally_indented_line + = parsers.check_optional_indent_and_any_trail * parsers.line - local blank = parsers.check_optional_blank_indent_and_any_trail * parsers.optionalspace * parsers.newline + local blank + = parsers.check_optional_blank_indent_and_any_trail + * parsers.optionalspace * parsers.newline - local chunk = Cs(parsers.line * (optionally_indented_line - blank)^0) + local chunk + = Cs(parsers.line + * (optionally_indented_line - blank)^0) local indented_blocks = function(bl) return Cs( bl - * (blank^1 * (parsers.check_optional_indent / "") - * parsers.check_code_trail * -parsers.blankline * bl)^0) + * ( blank^1 * (parsers.check_optional_indent / "") + * parsers.check_code_trail + * -parsers.blankline * bl)^0) end local NoteBlock - = parsers.check_trail_no_rem * RawNoteRef * parsers.colon + = parsers.check_trail_no_rem + * RawNoteRef * parsers.colon * parsers.spnlc * indented_blocks(chunk) / register_note @@ -31996,24 +33844,26 @@ M.extensions.pipe_tables = function(table_captions, table_attributes) , table_hline_separator , table_hline_column) - local table_caption_beginning = (parsers.check_minimal_blank_indent_and_any_trail_no_rem - * parsers.optionalspace * parsers.newline)^0 - * parsers.check_minimal_indent_and_trail - * (P("Table")^-1 * parsers.colon) - * parsers.optionalspace + local table_caption_beginning + = ( parsers.check_minimal_blank_indent_and_any_trail_no_rem + * parsers.optionalspace * parsers.newline)^0 + * parsers.check_minimal_indent_and_trail + * (P("Table")^-1 * parsers.colon) + * parsers.optionalspace local function strip_trailing_spaces(s) return s:gsub("%s*$","") end - local table_row = pipe_table_row(true - , (C((parsers.linechar - parsers.pipe)^1) - / strip_trailing_spaces - / self.parser_functions.parse_inlines) - , parsers.pipe - , (C((parsers.linechar - parsers.pipe)^0) - / strip_trailing_spaces - / self.parser_functions.parse_inlines)) + local table_row + = pipe_table_row(true + , (C((parsers.linechar - parsers.pipe)^1) + / strip_trailing_spaces + / self.parser_functions.parse_inlines) + , parsers.pipe + , (C((parsers.linechar - parsers.pipe)^0) + / strip_trailing_spaces + / self.parser_functions.parse_inlines)) local table_caption if table_captions then @@ -32030,7 +33880,8 @@ M.extensions.pipe_tables = function(table_captions, table_attributes) + ( parsers.newline * #( parsers.optionalspace * parsers.linechar) - * C(parsers.optionalspace) / writer.space)) + * C(parsers.optionalspace) + / writer.space)) * (parsers.linechar - parsers.lbrace)^0)^1) / self.parser_functions.parse_inlines) @@ -32044,7 +33895,8 @@ M.extensions.pipe_tables = function(table_captions, table_attributes) + ( parsers.newline * #( parsers.optionalspace * parsers.linechar) - * C(parsers.optionalspace) / writer.space))^1) + * C(parsers.optionalspace) + / writer.space))^1) / self.parser_functions.parse_inlines * parsers.newline end @@ -32052,12 +33904,15 @@ M.extensions.pipe_tables = function(table_captions, table_attributes) table_caption = parsers.fail end - local PipeTable = Ct(table_row * parsers.newline * (parsers.check_minimal_indent_and_trail / {}) - * table_hline * parsers.newline - * ((parsers.check_minimal_indent / {}) * table_row * parsers.newline)^0) - / make_pipe_table_rectangular - * table_caption^-1 - / writer.table + local PipeTable + = Ct( table_row * parsers.newline + * (parsers.check_minimal_indent_and_trail / {}) + * table_hline * parsers.newline + * ( (parsers.check_minimal_indent / {}) + * table_row * parsers.newline)^0) + / make_pipe_table_rectangular + * table_caption^-1 + / writer.table self.insert_pattern("Block after Blockquote", PipeTable, "PipeTable") @@ -32225,7 +34080,8 @@ M.extensions.superscripts = function() local writer = self.writer local Superscript = ( - parsers.between(parsers.Str, parsers.circumflex, parsers.circumflex) + parsers.between(parsers.Str, parsers.circumflex, + parsers.circumflex) ) / writer.superscript self.insert_pattern("Inline after LinkAndEmph", @@ -32288,11 +34144,13 @@ M.extensions.tex_math = function(tex_math_dollars, return str:gsub("^%s*(.-)$", "%1") end - local allowed_before_closing = B( parsers.backslash * parsers.any - + parsers.any * (parsers.any - parsers.backslash)) + local allowed_before_closing + = B( parsers.backslash * parsers.any + + parsers.any * (parsers.any - parsers.backslash)) - local allowed_before_closing_no_space = B( parsers.backslash * parsers.any - + parsers.any * (parsers.nonspacechar - parsers.backslash)) + local allowed_before_closing_no_space + = B( parsers.backslash * parsers.any + + parsers.any * (parsers.nonspacechar - parsers.backslash)) % \end{macrocode} % \begin{markdown} @@ -32301,18 +34159,20 @@ M.extensions.tex_math = function(tex_math_dollars, % % \end{markdown} % \begin{macrocode} - local dollar_math_content = (parsers.newline * (parsers.check_optional_indent / "") - + parsers.backslash^-1 - * parsers.linechar) - - parsers.blankline^2 - - parsers.dollar + local dollar_math_content + = (parsers.newline * (parsers.check_optional_indent / "") + + parsers.backslash^-1 + * parsers.linechar) + - parsers.blankline^2 + - parsers.dollar local inline_math_opening_dollars = parsers.dollar * #(parsers.nonspacechar) - local inline_math_closing_dollars = allowed_before_closing_no_space - * parsers.dollar - * -#(parsers.digit) + local inline_math_closing_dollars + = allowed_before_closing_no_space + * parsers.dollar + * -#(parsers.digit) local inline_math_dollars = between(Cs( dollar_math_content), inline_math_opening_dollars, @@ -32335,9 +34195,10 @@ M.extensions.tex_math = function(tex_math_dollars, % % \end{markdown} % \begin{macrocode} - local backslash_math_content = (parsers.newline * (parsers.check_optional_indent / "") - + parsers.linechar) - - parsers.blankline^2 + local backslash_math_content + = (parsers.newline * (parsers.check_optional_indent / "") + + parsers.linechar) + - parsers.blankline^2 % \end{macrocode} % \begin{markdown} % @@ -32457,11 +34318,15 @@ end % \acro{yaml} metadata block syntax extension. When the % `expect_jekyll_data` parameter is `true`, then a markdown document % may begin directly with \acro{yaml} metadata and may contain nothing -% but \acro{yaml} metadata. +% but \acro{yaml} metadata. When both `expect_jekyll_data` and +% `ensure_jekyll_data` parameters are `true`, then a a markdown document must +% begin directly with \acro{yaml} metadata and must contain nothing but +% \acro{yaml} metadata. % % \end{markdown} % \begin{macrocode} -M.extensions.jekyll_data = function(expect_jekyll_data) +M.extensions.jekyll_data = function(expect_jekyll_data, + ensure_jekyll_data) return { name = "built-in jekyll_data syntax extension", extend_writer = function(self) @@ -32474,7 +34339,8 @@ M.extensions.jekyll_data = function(expect_jekyll_data) % the key `p` in the parent table; if `p` is nil, then the table has no parent. % All scalar keys and values encountered in the table will be cast to a string % following \acro{yaml} serialization rules. String values will also be -% transformed using the function `t`. +% transformed using the function `t` for the typographic output format used by +% the \mref{markdownRendererJekyllDataTypographicString} macro. % % \end{markdown} % \begin{macrocode} @@ -32519,17 +34385,18 @@ M.extensions.jekyll_data = function(expect_jekyll_data) ::not_a_sequence:: if is_sequence then - table.insert(buf, "\\markdownRendererJekyllDataSequenceBegin{") - table.insert(buf, self.identifier(p or "null")) - table.insert(buf, "}{") - table.insert(buf, #keys) - table.insert(buf, "}") + table.insert(buf, + "\\markdownRendererJekyllDataSequenceBegin{") + table.insert(buf, self.identifier(p or "null")) + table.insert(buf, "}{") + table.insert(buf, #keys) + table.insert(buf, "}") else - table.insert(buf, "\\markdownRendererJekyllDataMappingBegin{") - table.insert(buf, self.identifier(p or "null")) - table.insert(buf, "}{") - table.insert(buf, #keys) - table.insert(buf, "}") + table.insert(buf, "\\markdownRendererJekyllDataMappingBegin{") + table.insert(buf, self.identifier(p or "null")) + table.insert(buf, "}{") + table.insert(buf, #keys) + table.insert(buf, "}") end for _, k in ipairs(keys) do @@ -32557,7 +34424,14 @@ M.extensions.jekyll_data = function(expect_jekyll_data) table.insert(buf, v) table.insert(buf, "}") elseif typ == "string" then - table.insert(buf, "\\markdownRendererJekyllDataString{") + table.insert(buf, + "\\markdownRendererJekyllDataProgrammaticString{") + table.insert(buf, k) + table.insert(buf, "}{") + table.insert(buf, self.identifier(v)) + table.insert(buf, "}") + table.insert(buf, + "\\markdownRendererJekyllDataTypographicString{") table.insert(buf, k) table.insert(buf, "}{") table.insert(buf, t(v)) @@ -32567,8 +34441,10 @@ M.extensions.jekyll_data = function(expect_jekyll_data) table.insert(buf, k) table.insert(buf, "}") else - error(format("Unexpected type %s for value of " .. - "YAML key %s", typ, k)) + local error = self.error(format( + "Unexpected type %s for value of " + .. "YAML key %s.", typ, k)) + table.insert(buf, error) end end end @@ -32590,38 +34466,49 @@ M.extensions.jekyll_data = function(expect_jekyll_data) local writer = self.writer local JekyllData - = Cmt( C((parsers.line - P("---") - P("..."))^0) - , function(s, i, text) -- luacheck: ignore s i - local data - local ran_ok, _ = pcall(function() - -- TODO: Replace with `require("tinyyaml")` in TeX Live 2023 - local tinyyaml = require("markdown-tinyyaml") - data = tinyyaml.parse(text, {timestamps=false}) - end) - if ran_ok and data ~= nil then - return true, writer.jekyllData(data, function(s) - return self.parser_functions.parse_blocks_nested(s) - end, nil) - else - return false - end - end - ) + = Cmt( C((parsers.line - P("---") - P("..."))^0) + , function(s, i, text) -- luacheck: ignore s i + local data + local ran_ok, _ = pcall(function() + -- TODO: Use `require("tinyyaml")` in TeX Live 2023 + local tinyyaml = require("markdown-tinyyaml") + data = tinyyaml.parse(text, {timestamps=false}) + end) + if ran_ok and data ~= nil then + return true, writer.jekyllData(data, function(s) + return self.parser_functions.parse_blocks_nested(s) + end, nil) + else + return false + end + end + ) local UnexpectedJekyllData - = P("---") - * parsers.blankline / 0 - * #(-parsers.blankline) -- if followed by blank, it's thematic break - * JekyllData - * (P("---") + P("...")) + = P("---") + * parsers.blankline / 0 + -- if followed by blank, it's thematic break + * #(-parsers.blankline) + * JekyllData + * (P("---") + P("...")) local ExpectedJekyllData - = ( P("---") - * parsers.blankline / 0 - * #(-parsers.blankline) -- if followed by blank, it's thematic break - )^-1 - * JekyllData - * (P("---") + P("..."))^-1 + = ( P("---") + * parsers.blankline / 0 + -- if followed by blank, it's thematic break + * #(-parsers.blankline) + )^-1 + * JekyllData + * (P("---") + P("..."))^-1 + + if ensure_jekyll_data then + ExpectedJekyllData = ExpectedJekyllData + * parsers.eof + else + ExpectedJekyllData = ( ExpectedJekyllData + * (V("Blank")^0 / writer.interblocksep) + )^-1 + end self.insert_pattern("Block before Blockquote", UnexpectedJekyllData, "UnexpectedJekyllData") @@ -32636,9 +34523,123 @@ end % %### Conversion from Markdown to Plain \TeX{} % -% The \luamref{new} function returns a conversion function that takes a -% markdown string and turns it into a plain \TeX{} output. See Section -% <#sec:lua-conversion>. +% The \luamref{new} function of file `markdown.lua` loads file +% `markdown-parser.lua` and calls its own function \luamref{new} unless option +% \Opt{eagerCache} or \Opt{finalizeCache} has been enabled and a cached +% conversion output exists, in which case it is returned without loading file +% `markdown-parser.lua`. +% +% \end{markdown} +% \iffalse +%</lua> +%<*lua-loader> +% \fi +% \begin{macrocode} +function M.new(options) +% \end{macrocode} +% \par +% \begin{markdown} +% +% Make the `options` table inherit from the \luamref{defaultOptions} table. +% +% \end{markdown} +% \begin{macrocode} + options = options or {} + setmetatable(options, { __index = function (_, key) + return defaultOptions[key] end }) +% \end{macrocode} +% \par +% \begin{markdown} +% +% Return a conversion function that tries to produce a cached conversion output +% exists. If no cached conversion output exists, we load the file +% `markdown-parser.lua` and use it to convert the input. +% +% \end{markdown} +% \begin{macrocode} + local parser_convert = nil + return function(input) + local function convert(input) + if parser_convert == nil then +% \end{macrocode} +% \par +% \begin{markdown} +% +% Lazy-load `markdown-parser.lua` and check that it originates from the same +% version of the Markdown package. +% +% \end{markdown} +% \begin{macrocode} + local parser = require("markdown-parser") + if metadata.version ~= parser.metadata.version then + warn("markdown.lua " .. metadata.version .. " used with " .. + "markdown-parser.lua " .. parser.metadata.version .. ".") + end + parser_convert = parser.new(options) + end + return parser_convert(input) + end +% \end{macrocode} +% \begin{markdown} +% If we cache markdown documents, produce the cache file and transform its +% filename to plain \TeX{} output. +% +% When determining the name of the cache file, create salt for the hashing +% function out of the package version and the passed options recognized by the +% Lua interface (see Section <#sec:lua-options>). +% \end{markdown} +% \begin{macrocode} + local output + if options.eagerCache or options.finalizeCache then + local salt = util.salt(options) + local name = util.cache(options.cacheDir, input, salt, convert, + ".md.tex") + output = [[\input{]] .. name .. [[}\relax]] +% \end{macrocode} +% \begin{markdown} +% Otherwise, return the result of the conversion directly. +% \end{markdown} +% \begin{macrocode} + else + output = convert(input) + end +% \end{macrocode} +% \begin{markdown} +% If the \Opt{finalizeCache} option is enabled, populate the frozen cache in +% the file \Opt{frozenCacheFileName} with an entry for markdown document +% number \Opt{frozenCacheCounter}. +% \end{markdown} +% \begin{macrocode} + if options.finalizeCache then + local file, mode + if options.frozenCacheCounter > 0 then + mode = "a" + else + mode = "w" + end + file = assert(io.open(options.frozenCacheFileName, mode), + [[Could not open file "]] .. options.frozenCacheFileName + .. [[" for writing]]) + assert(file:write( + [[\expandafter\global\expandafter\def\csname ]] + .. [[markdownFrozenCache]] .. options.frozenCacheCounter + .. [[\endcsname{]] .. output .. [[}]] .. "\n")) + assert(file:close()) + end + return output + end +end +% \end{macrocode} +% \iffalse +%</lua-loader> +%<*lua> +% \fi +% \par +% \begin{markdown} +% +% The \luamref{new} function from file `markdown-parser.lua` returns a +% conversion function that takes a markdown string and turns it into a plain +% \TeX{} output. See Section <#sec:lua-conversion>. % % \end{markdown} % \begin{macrocode} @@ -32671,7 +34672,15 @@ function M.new(options) goto miss end end - elseif singletonCache.options[k] ~= options[k] then +% \end{macrocode} +% \begin{markdown} +% +% The \Opt{cacheDir} option is disregarded. +% +% \end{markdown} +% \begin{macrocode} + elseif k ~= "cacheDir" + and singletonCache.options[k] ~= options[k] then goto miss end end @@ -32732,7 +34741,7 @@ function M.new(options) if options.jekyllData then local jekyll_data_extension = M.extensions.jekyll_data( - options.expectJekyllData) + options.expectJekyllData, options.ensureJekyllData) table.insert(extensions, jekyll_data_extension) end @@ -32795,7 +34804,8 @@ function M.new(options) end if options.citations then - local citations_extension = M.extensions.citations(options.citationNbsps) + local citations_extension + = M.extensions.citations(options.citationNbsps) table.insert(extensions, citations_extension) end @@ -32820,7 +34830,9 @@ function M.new(options) % % \end{markdown} % \begin{macrocode} - local pathname = kpse.lookup(filename) + local pathname = assert(kpse.find_file(filename), + [[Could not locate user-defined syntax extension "]] + .. filename) local input_file = assert(io.open(pathname, "r"), [[Could not open user-defined syntax extension "]] .. pathname .. [[" for reading]]) @@ -32850,7 +34862,8 @@ function M.new(options) .. type(user_extension.api_version) .. [[" but "number" was expected]]) assert(user_extension.api_version > 0 - and user_extension.api_version <= metadata.user_extension_api_version, + and user_extension.api_version + <= metadata.user_extension_api_version, [[User-defined syntax extension "]] .. pathname .. [[" uses syntax extension API version "]] .. user_extension.api_version .. [[ but markdown.lua ]] @@ -32868,7 +34881,8 @@ function M.new(options) .. [[" but "number" was expected]]) assert(user_extension.grammar_version == metadata.grammar_version, [[User-defined syntax extension "]] .. pathname - .. [[" uses grammar version "]] .. user_extension.grammar_version + .. [[" uses grammar version "]] + .. user_extension.grammar_version .. [[ but markdown.lua ]] .. metadata.version .. [[ uses grammar version ]] .. metadata.grammar_version .. [[, which is incompatible]]) @@ -32950,11 +34964,16 @@ function M.new(options) % \begin{macrocode} return convert end - -return M % \end{macrocode} % \iffalse %</lua> +%<*lua,lua-loader> +% \fi +% \begin{macrocode} +return M +% \end{macrocode} +% \iffalse +%</lua,lua-loader> %<*lua-cli> % \fi % \par @@ -33033,7 +35052,7 @@ end % \end{markdown} % \begin{macrocode} if options.cacheDir then - lfs.rmdir(options["cacheDir"]) + lfs.rmdir(options.cacheDir) end % \end{macrocode} % \iffalse @@ -33119,60 +35138,98 @@ end %### Themes {#themes-implementation} % % This section implements the theme-loading mechanism and the built-in themes -% provided with the Markdown package. Futhermore, this section also implements +% provided with the Markdown package. Furthermore, this section also implements % the built-in plain \TeX{} themes provided with the Markdown package. % % \end{markdown} % \begin{macrocode} \ExplSyntaxOn \prop_new:N \g_@@_plain_tex_loaded_themes_linenos_prop +\prop_new:N \g_@@_plain_tex_loaded_themes_versions_prop \cs_new:Nn - \@@_plain_tex_load_theme:nn + \@@_plain_tex_load_theme:nnn { \prop_get:NnNTF \g_@@_plain_tex_loaded_themes_linenos_prop { #1 } \l_tmpa_tl { - \msg_warning:nnnV - { markdown } - { repeatedly-loaded-plain-tex-theme } + \prop_get:NnN + \g_@@_plain_tex_loaded_themes_versions_prop { #1 } - \l_tmpa_tl + \l_tmpb_tl + \str_if_eq:nVTF + { #2 } + \l_tmpb_tl + { + \msg_warning:nnnVn + { markdown } + { repeatedly-loaded-plain-tex-theme } + { #1 } + \l_tmpa_tl + { #2 } + } + { + \msg_error:nnnnVV + { markdown } + { different-versions-of-plain-tex-theme } + { #1 } + { #2 } + \l_tmpb_tl + \l_tmpa_tl + } } { - \msg_info:nnn + \msg_info:nnnn { markdown } { loading-plain-tex-theme } { #1 } + { #2 } \prop_gput:Nnx \g_@@_plain_tex_loaded_themes_linenos_prop { #1 } { \tex_the:D \tex_inputlineno:D } + \prop_gput:Nnn + \g_@@_plain_tex_loaded_themes_versions_prop + { #1 } + { #2 } \file_input:n - { markdown theme #2 } + { markdown theme #3 } } } \msg_new:nnn { markdown } { loading-plain-tex-theme } - { Loading~plain~TeX~Markdown~theme~#1 } + { Loading~version~#2~of~plain~TeX~Markdown~theme~#1 } \msg_new:nnn { markdown } { repeatedly-loaded-plain-tex-theme } { - Plain~TeX~Markdown~theme~#1~was~previously~ + Version~#3~of~plain~TeX~Markdown~theme~#1~was~previously~ loaded~on~line~#2,~not~loading~it~again } +\msg_new:nnn + { markdown } + { different-versions-of-plain-tex-theme } + { + Tried~to~load~version~#2~of~plain~TeX~Markdown~theme~#1~ + but~version~#3~has~already~been~loaded~on~line~#4 + } \cs_generate_variant:Nn \prop_gput:Nnn { Nnx } \cs_gset_eq:NN - \@@_load_theme:nn - \@@_plain_tex_load_theme:nn + \@@_load_theme:nnn + \@@_plain_tex_load_theme:nnn \cs_generate_variant:Nn - \@@_load_theme:nn - { nV } + \@@_load_theme:nnn + { VeV } +\cs_generate_variant:Nn + \msg_error:nnnnnn + { nnnnVV } +\cs_generate_variant:Nn + \msg_warning:nnnnn + { nnnVn } % \end{macrocode} % \begin{markdown} % @@ -33227,16 +35284,17 @@ end % % \end{markdown} % \begin{macrocode} - \@@_plain_tex_load_theme:VV + \@@_plain_tex_load_theme:VeV \l_tmpb_tl + { \markdownThemeVersion } \l_tmpa_str } \cs_generate_variant:Nn \tl_set:Nn { Ne } \cs_generate_variant:Nn - \@@_plain_tex_load_theme:nn - { VV } + \@@_plain_tex_load_theme:nnn + { VeV } \ExplSyntaxOff % \end{macrocode} % \iffalse @@ -33308,18 +35366,22 @@ end \def\markdownRendererUlEndTightPrototype{}% \def\markdownRendererOlBeginPrototype{}% \def\markdownRendererOlBeginTightPrototype{}% -\def\markdownRendererFancyOlBeginPrototype#1#2{\markdownRendererOlBegin}% -\def\markdownRendererFancyOlBeginTightPrototype#1#2{\markdownRendererOlBeginTight}% +\def\markdownRendererFancyOlBeginPrototype#1#2{% + \markdownRendererOlBegin}% +\def\markdownRendererFancyOlBeginTightPrototype#1#2{% + \markdownRendererOlBeginTight}% \def\markdownRendererOlItemPrototype{}% \def\markdownRendererOlItemWithNumberPrototype#1{}% \def\markdownRendererOlItemEndPrototype{}% \def\markdownRendererFancyOlItemPrototype{\markdownRendererOlItem}% -\def\markdownRendererFancyOlItemWithNumberPrototype{\markdownRendererOlItemWithNumber}% +\def\markdownRendererFancyOlItemWithNumberPrototype{% + \markdownRendererOlItemWithNumber}% \def\markdownRendererFancyOlItemEndPrototype{}% \def\markdownRendererOlEndPrototype{}% \def\markdownRendererOlEndTightPrototype{}% \def\markdownRendererFancyOlEndPrototype{\markdownRendererOlEnd}% -\def\markdownRendererFancyOlEndTightPrototype{\markdownRendererOlEndTight}% +\def\markdownRendererFancyOlEndTightPrototype{% + \markdownRendererOlEndTight}% \def\markdownRendererDlBeginPrototype{}% \def\markdownRendererDlBeginTightPrototype{}% \def\markdownRendererDlItemPrototype#1{#1}% @@ -33393,6 +35455,28 @@ end \ExplSyntaxOff \def\markdownRendererSectionBeginPrototype{}% \def\markdownRendererSectionEndPrototype{}% +\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} @@ -33407,7 +35491,7 @@ end % \begin{macrocode} \ExplSyntaxOn \cs_new:Nn - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { \str_case:nn { #2 } @@ -33417,7 +35501,7 @@ end } } \cs_new:Nn - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { \str_case:nn { #2 } @@ -33429,14 +35513,14 @@ end \cs_gset:Npn \markdownRendererInputRawInlinePrototype#1#2 { - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { #1 } { #2 } } \cs_gset:Npn \markdownRendererInputRawBlockPrototype#1#2 { - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { #1 } { #2 } } @@ -33673,7 +35757,17 @@ end { #1 } { #2 } } -\def\markdownRendererJekyllDataStringPrototype#1#2{ +% \end{macrocode} +% \par +% \begin{markdown} +% +% We will process all string scalar values assuming that they may contain +% markdown markup and are intended for typesetting. +% +% \end{markdown} +% \begin{macrocode} +\def\markdownRendererJekyllDataProgrammaticStringPrototype#1#2{} +\def\markdownRendererJekyllDataTypographicStringPrototype#1#2{ \markdown_jekyll_data_set_keyvals:nn { #1 } { #2 } @@ -33702,8 +35796,16 @@ end \@@_if_option:nF { noDefaults } { - \@@_setup:n - {theme = witiko/markdown/defaults} + \@@_if_option:nTF + { experimental } + { + \@@_setup:n + { theme = witiko/markdown/defaults@experimental } + } + { + \@@_setup:n + { theme = witiko/markdown/defaults } + } } \ExplSyntaxOn } @@ -33755,7 +35857,7 @@ end \l_tmpa_tl \tl_gput_right:Nx \g_@@_formatted_lua_options_tl - { #1~=~ \l_tmpa_tl ,~ } + { #1~=~ \l_tmpa_tl ,~ } } { \str_if_eq_p:VV @@ -33772,9 +35874,18 @@ end \clist_map_inline:Vn \l_tmpa_tl { - \tl_gput_right:Nx + \@@_lua_escape:xN + { ##1 } + \l_tmpb_tl + \tl_gput_right:Nn + \g_@@_formatted_lua_options_tl + { " } + \tl_gput_right:NV + \g_@@_formatted_lua_options_tl + \l_tmpb_tl + \tl_gput_right:Nn \g_@@_formatted_lua_options_tl - { "##1" ,~ } + { " ,~ } } \tl_gput_right:Nx \g_@@_formatted_lua_options_tl @@ -33785,9 +35896,18 @@ end \@@_get_option_value:nN { #1 } \l_tmpa_tl - \tl_gput_right:Nx + \@@_lua_escape:xN + { \l_tmpa_tl } + \l_tmpb_tl + \tl_gput_right:Nn \g_@@_formatted_lua_options_tl - { #1~=~ " \l_tmpa_tl " ,~ } + { #1~=~ " } + \tl_gput_right:NV + \g_@@_formatted_lua_options_tl + \l_tmpb_tl + \tl_gput_right:Nn + \g_@@_formatted_lua_options_tl + { " ,~ } } } \cs_generate_variant:Nn @@ -33795,7 +35915,61 @@ end { Vn } \let\markdownPrepareLuaOptions=\@@_format_lua_options: \def\markdownLuaOptions{{ \g_@@_formatted_lua_options_tl }} -\ExplSyntaxOff +\sys_if_engine_luatex:TF + { + \cs_new:Nn + \@@_lua_escape:nN + { + \tl_set:Nx + #2 + { + \lua_escape:n + { #1 } + } + } + } + { + \regex_const:Nn + \c_@@_lua_escape_regex + { [\\"'] } + \cs_new:Nn + \@@_lua_escape:nN + { + \tl_set:Nn + #2 + { #1 } + \regex_replace_all:NnN + \c_@@_lua_escape_regex + { \u { c_backslash_str } \0 } + #2 + } + } +\cs_generate_variant:Nn + \@@_lua_escape:nN + { xN } +% \end{macrocode} +% \begin{markdown} +% +% After the \mdef{markdownPrepareInputFilename} macro has been +% fully expanded, the \mdef{markdownInputFilename} macro will +% expands to a Lua string that contains the input filename passed +% as the first argument. +% +% \end{markdown} +% \begin{macrocode} +\tl_new:N + \markdownInputFilename +\cs_new:Npn + \markdownPrepareInputFilename + #1 + { + \@@_lua_escape:xN + { #1 } + \markdownInputFilename + \tl_gset:Nx + \markdownInputFilename + { " \markdownInputFilename " } + } % \end{macrocode} % \par % \begin{markdown} @@ -33806,17 +35980,19 @@ end % % \end{markdown} % \begin{macrocode} -\def\markdownPrepare{% +\cs_new:Npn + \markdownPrepare + { % \end{macrocode} % \begin{markdown} % First, ensure that the \Opt{cacheDir} directory exists. % \end{markdown} % \begin{macrocode} - local lfs = require("lfs") - local cacheDir = "\markdownOptionCacheDir" - if not lfs.isdir(cacheDir) then - assert(lfs.mkdir(cacheDir)) - end + local~lfs = require("lfs") + local~options = \markdownLuaOptions + if~not~lfs.isdir(options.cacheDir) then~ + assert(lfs.mkdir(options.cacheDir)) + end~ % \end{macrocode} % \begin{markdown} % Next, load the `markdown` module and create a converter function using @@ -33824,9 +36000,30 @@ end % \mref{markdownLuaOptions} macro. % \end{markdown} % \begin{macrocode} - local md = require("markdown") - local convert = md.new(\markdownLuaOptions) -}% + local~md = require("markdown") + local~convert = md.new(options) + } +% \end{macrocode} +% \par +% \begin{markdown} +% +% The \mdef{markdownConvert} macro contains the Lua code that is executed +% during the conversion from markdown to plain \TeX{}. It opens the +% input file, converts it, and prints the conversion result. +% +% \end{markdown} +% \begin{macrocode} +\cs_new:Npn + \markdownConvert + { + local~filename = \markdownInputFilename + local~file = assert(io.open(filename, "r"), + [[Could~not~open~file~"]] .. filename .. [["~for~reading]]) + local~input = assert(file:read("*a")) + assert(file:close()) + print(convert(input)) + } +\ExplSyntaxOff % \end{macrocode} % \par % \begin{markdown} @@ -33842,7 +36039,9 @@ end % Remove the `options.cacheDir` directory if it is empty. % \end{markdown} % \begin{macrocode} - lfs.rmdir(cacheDir) + if options.cacheDir then + lfs.rmdir(options.cacheDir) + end }% % \end{macrocode} % \par @@ -34063,6 +36262,9 @@ end } } } + \str_gset:NV + \g_luabridge_output_dirname_str + \markdownOptionOutputDir \luabridge_now:e { #1 } } @@ -34199,12 +36401,14 @@ end \msg_new:nnn { markdown } { buffering-markinline } - { Buffering~inline~markdown~input~into~the~temporary~input~file~"#1". } + { Buffering~inline~markdown~input~into~ + the~temporary~input~file~"#1". } \msg_new:nnnn { markdown } { markinline-peek-failure } { Use~of~\iow_char:N \\ markinline~doesn't~match~its~definition } - { The~macro~should~be~followed~by~inline~markdown~text~in~curly~braces } + { The~macro~should~be~followed~by~inline~ + markdown~text~in~curly~braces } \ExplSyntaxOff % \end{macrocode} % \begin{markdown} @@ -34223,6 +36427,13 @@ end \markdownInput #1 { + \@@_if_option:nTF + { frozenCache } + { + \markdownInputRaw + { #1 } + } + { % \end{macrocode} % \begin{markdown} % @@ -34232,19 +36443,23 @@ end % % \end{markdown} % \begin{macrocode} - \file_get_full_name:nNTF - { #1 } - \l_tmpa_tl - { - \exp_args:NV - \markdownInputRaw + \tl_set:Nx \l_tmpa_tl - } - { - \msg_error:nnnV - { markdown } - { markdown-file-does-not-exist } { #1 } + \file_get_full_name:VNTF + \l_tmpa_tl + \l_tmpb_tl + { + \exp_args:NV + \markdownInputRaw + \l_tmpb_tl + } + { + \msg_error:nnV + { markdown } + { markdown-file-does-not-exist } + \l_tmpa_tl + } } } \msg_new:nnn @@ -34298,7 +36513,8 @@ end |fi |markdownInfo{Including markdown document number "|the|markdownOptionFrozenCacheCounter" from frozen cache}% - |csname markdownFrozenCache|the|markdownOptionFrozenCacheCounter|endcsname + |csname markdownFrozenCache% + |the|markdownOptionFrozenCacheCounter|endcsname |global|advance|markdownOptionFrozenCacheCounter by 1|relax }{% |markdownInfo{Including markdown document "&1"}% @@ -34312,13 +36528,10 @@ end |openin|markdownInputFileStream&1 |closein|markdownInputFileStream |markdownPrepareLuaOptions + |markdownPrepareInputFilename{&1}% |markdownLuaExecute{% |markdownPrepare - local file = assert(io.open("&1", "r"), - [[Could not open file "&1" for reading]]) - local input = assert(file:read("*a")) - assert(file:close()) - print(convert(input)) + |markdownConvert |markdownCleanup}% % \end{macrocode} % \begin{markdown} @@ -34358,7 +36571,7 @@ end % \LaTeX{} Implementation {#lateximplementation} %------------------------- % -% The \LaTeX{} implemenation makes use of the fact that, apart from some subtle +% The \LaTeX{} implementation makes use of the fact that, apart from some subtle % differences, \LaTeX{} implements the majority of the plain \TeX{} % format~[@latex17, Section 9]. As a consequence, we can directly reuse the % existing plain \TeX{} implementation. @@ -34413,9 +36626,10 @@ end % \begin{markdown} % % The \mdef{markdownInputPlainTeX} macro is used to store the original plain -% \TeX{} implementation of the \mref{markdownInput} macro. The \mref{markdownInput} -% macro is then redefined to accept an optional argument with options recognized by -% the \LaTeX{} interface (see Section <#sec:latex-options>). +% \TeX{} implementation of the \mref{yamlInput} macro. The \mref{markdownInput} +% and \mref{yamlInput} macros are then redefined to accept an optional argument +% with options recognized by the \LaTeX{} interface (see Section +% <#sec:latex-options>). % % \end{markdown} % \begin{macrocode} @@ -34425,12 +36639,17 @@ end \markdownSetup{#1}% \markdownInputPlainTeX{#2}% \endgroup}% +\renewcommand\yamlInput[2][]{% + \begingroup + \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData, #1}% + \markdownInputPlainTeX{#2}% + \endgroup}% % \end{macrocode} % \par % \begin{markdown} % -% The \envmref{markdown}, and \envmref{markdown*} \LaTeX{} environments are -% implemented using the \mref{markdownReadAndConvert} macro. +% The \envmref{markdown}, \envmref{markdown*}, and \envmref{yaml} \LaTeX{} +% environments are implemented using the \mref{markdownReadAndConvert} macro. % % \end{markdown} % \begin{macrocode} @@ -34522,13 +36741,26 @@ end % we let the \mref{markdownReadAndConvert} macro process the rest of the % \LaTeX{} environment. % +% We also make provision for using the \mref{markdown} command as a part of a +% different \LaTeX{} environment as follows: +% +% ``` tex +% \newenvironment{foo}\% +% {code before \markdown[some, options]}\% +% {\markdownEnd code after} +% ``` +% % \end{markdown} % \begin{macrocode} - \c { markdownReadAndConvert@markdown } { } + \c { exp_args:NV } + \c { markdownReadAndConvert@ } + \c { @currenvir } } { \group_end: - \markdownReadAndConvert@markdown { } + \exp_args:NV + \markdownReadAndConvert@ + \@currenvir } } { \markdownEnd } @@ -34536,15 +36768,34 @@ end { markdown* } [ 1 ] { - \msg_warning:nnn - { markdown } - { latex-markdown-star-deprecated } - { #1 } + \@@_if_option:nTF + { experimental } + { + \msg_error:nnn + { markdown } + { latex-markdown-star-deprecated } + { #1 } + } + { + \msg_warning:nnn + { markdown } + { latex-markdown-star-deprecated } + { #1 } + } \@@_setup:n { #1 } - \markdownReadAndConvert@markdown * + \markdownReadAndConvert@ + { markdown* } } { \markdownEnd } +\renewenvironment + { yaml } + { + \group_begin: + \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}% + \markdown + } + { \yamlEnd } \msg_new:nnn { markdown } { latex-markdown-star-deprecated } @@ -34552,6 +36803,9 @@ end The~markdown*~LaTeX~environment~has~been~deprecated~and~will~ be~removed~in~the~next~major~version~of~the~Markdown~package. } +\cs_generate_variant:Nn + \@@_setup:n + { V } \ExplSyntaxOff \begingroup % \end{macrocode} @@ -34565,36 +36819,27 @@ end % \begin{macrocode} \catcode`\|=0\catcode`\<=1\catcode`\>=2% \catcode`\\=12|catcode`|{=12|catcode`|}=12% - |gdef|markdownReadAndConvert@markdown#1<% - |markdownReadAndConvert<\end{markdown#1}>% - <|end<markdown#1>>>% + |gdef|markdownReadAndConvert@#1<% + |markdownReadAndConvert<\end{#1}>% + <|end<#1>>>% |endgroup % \end{macrocode} % \par % \begin{markdown} % -%### Options -% The supplied package options are processed using the \mref{markdownSetup} macro. -% -% \end{markdown} -% \begin{macrocode} -\DeclareOption*{% - \expandafter\markdownSetup\expandafter{\CurrentOption}}% -\ProcessOptions\relax -% \end{macrocode} -% \begin{markdown} -% %### Themes {#latex-themes-implementation} % % This section overrides the plain \TeX{} implementation of the theme-loading -% mechanism from Section <#sec:themes-implementation>. Futhermore, this section +% mechanism from Section <#sec:themes-implementation>. Furthermore, this section % also implements the built-in \LaTeX{} themes provided with the Markdown package. % % \end{markdown} % \begin{macrocode} \ExplSyntaxOn +\prop_new:N \g_@@_latex_loaded_themes_linenos_prop +\prop_new:N \g_@@_latex_loaded_themes_versions_prop \cs_gset:Nn - \@@_load_theme:nn + \@@_load_theme:nnn { % \end{macrocode} % \par @@ -34618,7 +36863,7 @@ end % \end{markdown} % \begin{macrocode} \file_if_exist:nTF - { markdown theme #2.sty } + { markdown theme #3.sty } { \msg_error:nnn { markdown } @@ -34626,9 +36871,10 @@ end { #1 } } { - \@@_plain_tex_load_theme:nn + \@@_plain_tex_load_theme:nnn { #1 } { #2 } + { #3 } } \else % \end{macrocode} @@ -34641,19 +36887,61 @@ end % \end{markdown} % \begin{macrocode} \file_if_exist:nTF - { markdown theme #2.sty } + { markdown theme #3.sty } { - \msg_info:nnn - { markdown } - { loading-latex-theme } + \prop_get:NnNTF + \g_@@_latex_loaded_themes_linenos_prop { #1 } - \RequirePackage - { markdown theme #2 } + \l_tmpa_tl + { + \prop_get:NnN + \g_@@_latex_loaded_themes_versions_prop + { #1 } + \l_tmpb_tl + \str_if_eq:nVTF + { #2 } + \l_tmpb_tl + { + \msg_warning:nnnVn + { markdown } + { repeatedly-loaded-latex-theme } + { #1 } + \l_tmpa_tl + { #2 } + } + { + \msg_error:nnnnVV + { markdown } + { different-versions-of-latex-theme } + { #1 } + { #2 } + \l_tmpb_tl + \l_tmpa_tl + } + } + { + \msg_info:nnnn + { markdown } + { loading-latex-theme } + { #1 } + { #2 } + \prop_gput:Nnx + \g_@@_latex_loaded_themes_linenos_prop + { #1 } + { \tex_the:D \tex_inputlineno:D } + \prop_gput:Nnn + \g_@@_latex_loaded_themes_versions_prop + { #1 } + { #2 } + \RequirePackage + { markdown theme #3 } + } } { - \@@_plain_tex_load_theme:nn + \@@_plain_tex_load_theme:nnn { #1 } { #2 } + { #3 } } \fi \else @@ -34665,15 +36953,15 @@ end % % \end{markdown} % \begin{macrocode} - \msg_info:nnn + \msg_info:nnnn { markdown } { theme-loading-postponed } { #1 } + { #2 } \AtEndOfPackage { - \@@_load_theme:nn - { #1 } - { #2 } + \@@_set_theme:n + { #1 @ #2 } } \fi } @@ -34681,13 +36969,27 @@ end { markdown } { theme-loading-postponed } { - Postponing~loading~Markdown~theme~#1~until~ + Postponing~loading~version~#2~of~Markdown~theme~#1~until~ Markdown~package~has~finished~loading } \msg_new:nnn { markdown } { loading-latex-theme } - { Loading~LaTeX~Markdown~theme~#1 } + { Loading~version~#2~of~LaTeX~Markdown~theme~#1 } +\msg_new:nnn + { markdown } + { repeatedly-loaded-latex-theme } + { + Version~#3~of~LaTeX~Markdown~theme~#1~was~previously~ + loaded~on~line~#2,~not~loading~it~again + } +\msg_new:nnn + { markdown } + { different-versions-of-latex-theme } + { + Tried~to~load~version~#2~of~LaTeX~Markdown~theme~#1~ + but~version~#3~has~already~been~loaded~on~line~#4 + } \cs_generate_variant:Nn \msg_new:nnnn { nnVV } @@ -34782,7 +37084,8 @@ end % \end{markdown} % \begin{macrocode} }{% - \markdown@witiko@dot@oldRendererInputFencedCodePrototype{#1}{#2}{#3}% + \markdown@witiko@dot@oldRendererInputFencedCodePrototype + {#1}{#2}{#3}% }% }% \next#2 \relax}% @@ -34946,6 +37249,25 @@ end % See Section <#sec:latex-token-renderer-prototypes> for the actual % definitions. % +%### Options +% The supplied package options are processed using the \mref{markdownSetup} macro. +% +% \end{markdown} +% \iffalse +%</themes-witiko-markdown-defaults-latex> +%<*latex> +% \fi +% \begin{macrocode} +\DeclareOption*{% + \expandafter\markdownSetup\expandafter{\CurrentOption}}% +\ProcessOptions\relax +% \end{macrocode} +% \iffalse +%</latex> +%<*themes-witiko-markdown-defaults-latex> +% \fi +% \begin{markdown} +% %### Token Renderer Prototypes {#latex-token-renderer-prototypes} % % The following configuration should be considered placeholder. If the option @@ -34956,87 +37278,274 @@ end \markdownIfOption{plain}{\iffalse}{\iftrue} % \end{macrocode} % \par -% \begin{markdown}% +% \begin{markdown} +% +%#### Lists +% % If either the \Opt{tightLists} or the \Opt{fancyLists} Lua option is enabled -% and the current document class is not \pkg{beamer}, then load the -% \pkg{paralist} package. +% and the current document class is not \pkg{beamer}, use a package that +% provides support for tight and fancy lists. +% +% If either the package \pkg{paralist} or the package \pkg{enumitem} have already +% been loaded, use them. Otherwise, if the option \Opt{experimental} or any test +% phase has been enabled, use the package \pkg{enumitem}. Otherwise, use the +% package \pkg{paralist}. % % \end{markdown} % \begin{macrocode} -\@ifclassloaded{beamer}{}{% - \markdownIfOption{tightLists}{\RequirePackage{paralist}}{}% - \markdownIfOption{fancyLists}{\RequirePackage{paralist}}{}% -} +\ExplSyntaxOn +\bool_new:N + \g_@@_tight_or_fancy_lists_bool +\bool_gset_false:N + \g_@@_tight_or_fancy_lists_bool +\@@_if_option:nTF + { tightLists } + { + \bool_gset_true:N + \g_@@_tight_or_fancy_lists_bool + } + { + \@@_if_option:nT + { fancyLists } + { + \bool_gset_true:N + \g_@@_tight_or_fancy_lists_bool + } + } +\bool_new:N + \g_@@_beamer_paralist_or_enumitem_bool +\bool_gset_true:N + \g_@@_beamer_paralist_or_enumitem_bool +\@ifclassloaded + { beamer } + { } + { + \@ifpackageloaded + { paralist } + { } + { + \@ifpackageloaded + { enumitem } + { } + { + \bool_gset_false:N + \g_@@_beamer_paralist_or_enumitem_bool + } + } + } +\bool_if:nT + { + \g_@@_tight_or_fancy_lists_bool && + ! \g_@@_beamer_paralist_or_enumitem_bool + } + { + \bool_if:nTF + { + \bool_lazy_or_p:nn + { + \str_if_eq_p:en + { \markdownThemeVersion } + { experimental } + } + { + \bool_lazy_and_p:nn + { + \prop_if_exist_p:N + \g__pdfmanagement_documentproperties_prop + } + { + \bool_lazy_any_p:n + { + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-I } + } + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-II } + } + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-III } + } + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-IV } + } + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-V } + } + { + \prop_if_in_p:Nn + \g__pdfmanagement_documentproperties_prop + { document / testphase / phase-VI } + } + } + } + } + } + { + \RequirePackage + { enumitem } + } + { + \RequirePackage + { paralist } + } + } +\ExplSyntaxOff % \end{macrocode} % \par % \begin{markdown} % -% If we loaded the \pkg{paralist} package, define the respective renderer -% prototypes to make use of the capabilities of the package. Otherwise, -% define the renderer prototypes to fall back on the corresponding renderers -% for the non-tight lists. +% If we loaded the \pkg{enumitem} package, define the tight and +% fancy list renderer prototypes to make use of the capabilities of +% the package. % % \end{markdown} % \begin{macrocode} \ExplSyntaxOn -\@ifpackageloaded{paralist}{ - \tl_new:N - \l_@@_latex_fancy_list_item_label_number_style_tl - \tl_new:N - \l_@@_latex_fancy_list_item_label_delimiter_style_tl - \cs_new:Nn +\cs_new:Nn + \@@_latex_fancy_list_item_label_number:nn + { + \str_case:nn + { #1 } + { + { Decimal } { #2 } + { LowerRoman } { \int_to_roman:n { #2 } } + { UpperRoman } { \int_to_Roman:n { #2 } } + { LowerAlpha } { \int_to_alph:n { #2 } } + { UpperAlpha } { \int_to_Alph:n { #2 } } + } + } +\cs_new:Nn + \@@_latex_fancy_list_item_label_delimiter:n + { + \str_case:nn + { #1 } + { + { Default } { . } + { OneParen } { ) } + { Period } { . } + } + } +\cs_new:Nn + \@@_latex_fancy_list_item_label:nnn + { \@@_latex_fancy_list_item_label_number:nn - { - \str_case:nn - { #1 } - { - { Decimal } { #2 } - { LowerRoman } { \int_to_roman:n { #2 } } - { UpperRoman } { \int_to_Roman:n { #2 } } - { LowerAlpha } { \int_to_alph:n { #2 } } - { UpperAlpha } { \int_to_Alph:n { #2 } } - } - } - \cs_new:Nn + { #1 } + { #3 } \@@_latex_fancy_list_item_label_delimiter:n - { - \str_case:nn - { #1 } - { - { Default } { . } - { OneParen } { ) } - { Period } { . } - } - } - \cs_new:Nn - \@@_latex_fancy_list_item_label:nnn - { - \@@_latex_fancy_list_item_label_number:nn + { #2 } + } +\cs_generate_variant:Nn + \@@_latex_fancy_list_item_label:nnn + { VVn } +\tl_new:N + \l_@@_latex_fancy_list_item_label_number_style_tl +\tl_new:N + \l_@@_latex_fancy_list_item_label_delimiter_style_tl +\@ifpackageloaded{enumitem}{ + \markdownSetup{rendererPrototypes={ +% \end{macrocode} +% \begin{markdown} +% +% First, let's define the tight list item renderer prototypes. +% +% \end{markdown} +% \begin{macrocode} + ulBeginTight = { + \begin + { itemize } + [ noitemsep ] + }, + ulEndTight = { + \end + { itemize } + }, + olBeginTight = { + \begin + { enumerate } + [ noitemsep ] + }, + olEndTight = { + \end + { enumerate } + }, + dlBeginTight = { + \begin + { description } + [ noitemsep ] + }, + dlEndTight = { + \end + { description } + }, +% \end{macrocode} +% \begin{markdown} +% +% Second, let's define the fancy list item renderer prototypes. +% +% \end{markdown} +% \begin{macrocode} + fancyOlBegin = { + \group_begin: + \tl_set:Nn + \l_@@_latex_fancy_list_item_label_number_style_tl { #1 } - { #3 } - \@@_latex_fancy_list_item_label_delimiter:n + \tl_set:Nn + \l_@@_latex_fancy_list_item_label_delimiter_style_tl { #2 } - } - \cs_new:Nn - \@@_latex_paralist_style:nn - { - \str_case:nn + \begin + { enumerate } + }, + fancyOlBeginTight = { + \group_begin: + \tl_set:Nn + \l_@@_latex_fancy_list_item_label_number_style_tl { #1 } - { - { Decimal } { 1 } - { LowerRoman } { i } - { UpperRoman } { I } - { LowerAlpha } { a } - { UpperAlpha } { A } - } - \@@_latex_fancy_list_item_label_delimiter:n + \tl_set:Nn + \l_@@_latex_fancy_list_item_label_delimiter_style_tl { #2 } - } - \markdownSetup{rendererPrototypes={ + \begin + { enumerate } + [ noitemsep ] + }, + fancyOlEnd(|Tight) = { + \end { enumerate } + \group_end: + }, + fancyOlItemWithNumber = { + \item + [ + \@@_latex_fancy_list_item_label:VVn + \l_@@_latex_fancy_list_item_label_number_style_tl + \l_@@_latex_fancy_list_item_label_delimiter_style_tl + { #1 } + ] + }, + }} % \end{macrocode} % \par % \begin{markdown} % +% Otherwise, if we loaded the \pkg{paralist} package, define the +% tight and fancy list renderer prototypes to make use of the +% capabilities of the package. +% +% \end{markdown} +% \begin{macrocode} +}{\@ifpackageloaded{paralist}{ + \markdownSetup{rendererPrototypes={ +% \end{macrocode} +% \begin{markdown} +% % Make tight bullet lists a little less compact by adding extra vertical space % above and below them. % @@ -35060,33 +37569,13 @@ end \tl_set:Nn \l_@@_latex_fancy_list_item_label_delimiter_style_tl { #2 } - \@@_if_option:nTF - { startNumber } - { - \tl_set:Nn - \l_tmpa_tl - { \begin{enumerate} } - } - { - \tl_set:Nn - \l_tmpa_tl - { \begin{enumerate}[ } - \tl_put_right:Nx - \l_tmpa_tl - { \@@_latex_paralist_style:nn { #1 } { #2 } } - \tl_put_right:Nn - \l_tmpa_tl - { ] } - } - \tl_use:N - \l_tmpa_tl + \begin{enumerate} }, fancyOlEnd = { \end{enumerate} \group_end: }, % \end{macrocode} -% \par % \begin{markdown} % % Make tight ordered lists a little less compact by adding extra vertical @@ -35112,32 +37601,9 @@ end \tl_set:Nn \l_@@_latex_fancy_list_item_label_delimiter_style_tl { #2 } - \tl_set:Nn - \l_tmpa_tl - { - \plpartopsep=\partopsep - \pltopsep=\topsep - } - \@@_if_option:nTF - { startNumber } - { - \tl_put_right:Nn - \l_tmpa_tl - { \begin{compactenum} } - } - { - \tl_put_right:Nn - \l_tmpa_tl - { \begin{compactenum}[ } - \tl_put_right:Nx - \l_tmpa_tl - { \@@_latex_paralist_style:nn { #1 } { #2 } } - \tl_put_right:Nn - \l_tmpa_tl - { ] } - } - \tl_use:N - \l_tmpa_tl + \plpartopsep=\partopsep + \pltopsep=\topsep + \begin{compactenum} }, fancyOlEndTight = { \end{compactenum} @@ -35153,7 +37619,6 @@ end ] }, % \end{macrocode} -% \par % \begin{markdown} % % Make tight definition lists a little less compact by adding extra @@ -35170,23 +37635,36 @@ end dlEndTight = { \end{compactdesc} \group_end: - }}} - \cs_generate_variant:Nn - \@@_latex_fancy_list_item_label:nnn - { VVn } + } + }} }{ - \markdownSetup{rendererPrototypes={ - ulBeginTight = {\markdownRendererUlBegin}, - ulEndTight = {\markdownRendererUlEnd}, - fancyOlBegin = {\markdownRendererOlBegin}, - fancyOlEnd = {\markdownRendererOlEnd}, - olBeginTight = {\markdownRendererOlBegin}, - olEndTight = {\markdownRendererOlEnd}, - fancyOlBeginTight = {\markdownRendererOlBegin}, - fancyOlEndTight = {\markdownRendererOlEnd}, - dlBeginTight = {\markdownRendererDlBegin}, - dlEndTight = {\markdownRendererDlEnd}}} -} +% \end{macrocode} +% \par +% \begin{markdown} +% +% Otherwise, if we loaded neither the \pkg{enumitem} package nor the +% \pkg{paralist} package, define the tight and fancy list renderer +% prototypes to fall back on the corresponding renderers for the +% non-tight lists. +% +% \end{markdown} +% \begin{macrocode} + \markdownSetup + { + rendererPrototypes = { + ulBeginTight = \markdownRendererUlBegin, + ulEndTight = \markdownRendererUlEnd, + fancyOlBegin = \markdownRendererOlBegin, + fancyOlEnd = \markdownRendererOlEnd, + olBeginTight = \markdownRendererOlBegin, + olEndTight = \markdownRendererOlEnd, + fancyOlBeginTight = \markdownRendererOlBegin, + fancyOlEndTight = \markdownRendererOlEnd, + dlBeginTight = \markdownRendererDlBegin, + dlEndTight = \markdownRendererDlEnd, + }, + } +}} \ExplSyntaxOff \RequirePackage{amsmath} % \end{macrocode} @@ -35272,15 +37750,6 @@ end } \ExplSyntaxOff \markdownSetup{rendererPrototypes={ - image = {% - \begin{figure}% - \begin{center}% - \includegraphics[alt={#1}]{#3}% - \end{center}% - \ifx\empty#4\empty\else - \caption{#4}% - \fi - \end{figure}}, ulBegin = {\begin{itemize}}, ulEnd = {\end{itemize}}, olBegin = {\begin{enumerate}}, @@ -35431,11 +37900,13 @@ end \ltx@ifpackageloaded { minted } { + \catcode`\%=14\relax \catcode`\#=6\relax \exp_args:NV \inputminted \l_tmpa_tl { #1 } + \catcode`\%=12\relax \catcode`\#=12\relax } { @@ -35598,8 +38069,9 @@ end \advance\markdownLaTeXCitationsCounter by 1\relax \ifx\relax#4\relax \ifx\relax#5\relax - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax - \cite{#1#2#6}% Without prenotes and postnotes, just accumulate cites + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax + \cite{#1#2#6}% No prenotes/postnotes, just accumulate cites \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter \@gobblethree @@ -35609,7 +38081,8 @@ end \cite{#1}% \fi \cite[#5]{#6}% - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \else \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter @@ -35636,7 +38109,8 @@ end \space % Insert a space before the prenote in later citations \fi #4~\expandafter\cite\ifx\relax#5\relax{#6}\else[#5]{#6}\fi - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \else \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter @@ -35656,8 +38130,9 @@ end \advance\markdownLaTeXCitationsCounter by 1\relax \ifx\relax#3\relax \ifx\relax#4\relax - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax - \citep{#1,#5}% Without prenotes and postnotes, just accumulate cites + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax + \citep{#1,#5}% No prenotes/postnotes, just accumulate cites \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter \@gobbletwo @@ -35667,7 +38142,8 @@ end \citep{#1}% \fi \citep[][#4]{#5}% - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \else \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter @@ -35687,7 +38163,8 @@ end \citep{#1}% \fi \citep[#3][#4]{#5}% - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \else \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter @@ -35702,8 +38179,9 @@ end \advance\markdownLaTeXCitationsCounter by 1\relax \ifx\relax#3\relax \ifx\relax#4\relax - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax - \citet{#1,#5}% Without prenotes and postnotes, just accumulate cites + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax + \citet{#1,#5}% No prenotes/postnotes, just accumulate cites \expandafter\expandafter\expandafter \expandafter\expandafter\expandafter\expandafter \@gobbletwo @@ -35713,10 +38191,13 @@ end \citet{#1}% \fi , \citet[#3][#4]{#5}% - \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal + \relax , \else - \ifnum\markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal\relax + \ifnum + \markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal + \relax , \fi \fi @@ -35735,10 +38216,13 @@ end \citet{#1}% \fi , \citet[#3][#4]{#5}% - \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal + \relax , \else - \ifnum\markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal\relax + \ifnum + \markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal + \relax , \fi \fi @@ -35753,13 +38237,15 @@ end % BibLaTeX implementation \def\markdownLaTeXBibLaTeXCitations#1#2#3#4#5{% \advance\markdownLaTeXCitationsCounter by 1\relax - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \autocites#1[#3][#4]{#5}% \expandafter\@gobbletwo \fi\markdownLaTeXBibLaTeXCitations{#1[#3][#4]{#5}}} \def\markdownLaTeXBibLaTeXTextCitations#1#2#3#4#5{% \advance\markdownLaTeXCitationsCounter by 1\relax - \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal\relax + \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal + \relax \textcites#1[#3][#4]{#5}% \expandafter\@gobbletwo \fi\markdownLaTeXBibLaTeXTextCitations{#1[#3][#4]{#5}}} @@ -35852,7 +38338,8 @@ end { \markdownLaTeXRendererAutolink { #2 } { #3 } }{ - \markdownLaTeXRendererDirectOrIndirectLink { #1 } { #2 } { #3 } { #4 } + \markdownLaTeXRendererDirectOrIndirectLink + { #1 } { #2 } { #3 } { #4 } } } \def\markdownLaTeXRendererAutolink#1#2{% @@ -36050,72 +38537,166 @@ end }, }, } -\ExplSyntaxOff % \end{macrocode} % \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 Text +% If the \Opt{mark} option is enabled, we will load either the \pkg{soulutf8} +% package or the \pkg{lua-ul} package and use it to implement marked text. % % \end{markdown} % \begin{macrocode} -\markdownIfOption{strikeThrough}{% - \RequirePackage{soulutf8}% - \markdownSetup{ - rendererPrototypes = { - strikeThrough = {% - \st{#1}% - }, - } +\@@_if_option:nT + { mark } + { + \sys_if_engine_luatex:TF + { + \RequirePackage + { luacolor } + \RequirePackage + { lua-ul } + \markdownSetup + { + rendererPrototypes = { + mark = { + \highLight + { #1 } + }, + } + } + } + { + \RequirePackage + { xcolor } + % TODO: Use just package soul after TeX Live 2023. + \IfFormatAtLeastTF + { 2023-02-18 } + { + \RequirePackage + { soul } + } + { + \RequirePackage + { soulutf8 } + } + \markdownSetup + { + rendererPrototypes = { + mark = { + \hl + { #1 } + }, + } + } + } } -}{} % \end{macrocode} % \par % \begin{markdown} % -%#### Marked Text -% If the \Opt{mark} option is enabled, we will load the \pkg{soulutf8} package -% and use it to implement marked text. +%#### Strike-Through +% If the \Opt{strikeThrough} option is enabled, we will load either the +% \pkg{soulutf8} package or the \pkg{lua-ul} package and use it to implement +% strike-throughs. % % \end{markdown} % \begin{macrocode} -\markdownIfOption{mark}{% - \RequirePackage{soulutf8}% - \markdownSetup{ - rendererPrototypes = { - mark = {% - \hl{#1}% - }, - } +\@@_if_option:nT + { strikeThrough } + { + \sys_if_engine_luatex:TF + { + \RequirePackage + { lua-ul } + \markdownSetup + { + rendererPrototypes = { + strikeThrough = { + \strikeThrough + { #1 } + }, + } + } + } + { + % TODO: Use just package soul after TeX Live 2023. + \IfFormatAtLeastTF + { 2023-02-18 } + { + \RequirePackage + { soul } + } + { + \RequirePackage + { soulutf8 } + } + \markdownSetup + { + rendererPrototypes = { + strikeThrough = { + \st + { #1 } + }, + } + } + } } -}{} % \end{macrocode} % \par % \begin{markdown} % -%#### Image Attributes +%#### Images and their attributes +% +% We define images to be rendered as floating figures using the command +% `\includegraphics`, where the image label is the alt text and the image +% title is the caption of the figure. % -% If the \Opt{linkAttributes} option is enabled, we will load -% the \pkg{graphicx} package. Furthermore, in image attribute contexts, -% we will make attributes in the form \meta{key}`=`\meta{value} set the -% corresponding keys of the \pkg{graphicx} package to the corresponding -% values. +% If the \Opt{linkAttributes} option is enabled, we will make attributes in the +% form \meta{key}`=`\meta{value} set the corresponding keys of the +% \pkg{graphicx} package to the corresponding values and we will register any +% identifiers, so that they can be used as \LaTeX{} labels for referencing +% figures. % % \end{markdown} % \begin{macrocode} \ExplSyntaxOn +\seq_new:N + \l_@@_image_identifiers_seq +\markdownSetup { + rendererPrototypes = { + image = { + \begin { figure } + \begin { center } + \includegraphics + [ alt = { #1 } ] + { #3 } + \tl_if_empty:nF + { #4 } + { \caption { #4 } } + \seq_map_inline:Nn + \l_@@_image_identifiers_seq + { \label { ##1 } } + \end { center } + \end { figure } + }, + } +} \@@_if_option:nT { linkAttributes } { - \RequirePackage{graphicx} - \markdownSetup{ + \RequirePackage { graphicx } + \markdownSetup { rendererPrototypes = { imageAttributeContextBegin = { \group_begin: - \markdownSetup{ + \markdownSetup { rendererPrototypes = { + attributeIdentifier = { + \seq_put_right:Nn + \l_@@_image_identifiers_seq + { ##1 } + }, attributeKeyValue = { \setkeys { Gin } @@ -36151,13 +38732,13 @@ end { { latex } { - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { #1 } { tex } } } { - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { #1 } { #2 } } @@ -36170,13 +38751,13 @@ end { { latex } { - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { #1 } { tex } } } { - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { #1 } { #2 } } @@ -36252,9 +38833,9 @@ end % \begin{markdown} % %### Typesetting Markdown -% The \mref{inputmarkdown} macro is defined to accept an optional argument with -% options recognized by the \Hologo{ConTeXt} interface (see Section -% <#sec:context-options>). +% The \mref{inputmarkdown} and \mref{inputyaml} macros are defined to accept an +% optional argument with options recognized by the \Hologo{ConTeXt} interface +% (see Section <#sec:context-options>). % % \end{markdown} % \begin{macrocode} @@ -36268,11 +38849,18 @@ end \fi \markdownInput{#2}% \endgroup}% +\long\def\inputyaml{% + \dosingleempty + \doinputyaml}% +\long\def\doinputyaml[#1]#2{% + \doinputmarkdown + [jekyllData, expectJekyllData, ensureJekyllData, #1]{#2}}% % \end{macrocode} % \par % \begin{markdown} % -% The \mref{startmarkdown} and \mref{stopmarkdown} macros are implemented using the +% The \mref{startmarkdown}, \mref{stopmarkdown}, \mref{startyaml}, and +% \mref{stopyaml} macros are implemented using the % \mref{markdownReadAndConvert} macro. % % In Knuth's \TeX, trailing spaces are removed very early on when a line is @@ -36306,6 +38894,15 @@ end |gdef|stopmarkdown{% |ctxlua{document.markdown_buffering = false}% |markdownEnd}% + |gdef|startyaml{% + |begingroup + |ctxlua{document.markdown_buffering = true}% + |setupyaml[jekyllData, expectJekyllData, ensureJekyllData]% + |markdownReadAndConvert{\stopyaml}% + {|stopyaml}}% + |gdef|stopyaml{% + |ctxlua{document.markdown_buffering = false}% + |yamlEnd}% |endgroup % \end{macrocode} % \par @@ -36314,15 +38911,17 @@ end %### Themes {#context-themes-implementation} % % This section overrides the plain \TeX{} implementation of the theme-loading -% mechanism from Section <#sec:themes-implementation>. Futhermore, this section +% mechanism from Section <#sec:themes-implementation>. Furthermore, this section % also implements the built-in \Hologo{ConTeXt} themes provided with the % Markdown package. % % \end{markdown} % \begin{macrocode} \ExplSyntaxOn +\prop_new:N \g_@@_context_loaded_themes_linenos_prop +\prop_new:N \g_@@_context_loaded_themes_versions_prop \cs_gset:Nn - \@@_load_theme:nn + \@@_load_theme:nnn { % \end{macrocode} % \par @@ -36335,31 +38934,87 @@ end % \end{markdown} % \begin{macrocode} \file_if_exist:nTF - { t - markdown theme #2.tex } + { t - markdown theme #3.tex } { - \msg_info:nnn - { markdown } - { loading-context-theme } + \prop_get:NnNTF + \g_@@_context_loaded_themes_linenos_prop { #1 } - \usemodule - [ t ] - [ markdown theme #2 ] + \l_tmpa_tl + { + \prop_get:NnN + \g_@@_context_loaded_themes_versions_prop + { #1 } + \l_tmpb_tl + \str_if_eq:nVTF + { #2 } + \l_tmpb_tl + { + \msg_warning:nnnVn + { markdown } + { repeatedly-loaded-context-theme } + { #1 } + \l_tmpa_tl + { #2 } + } + { + \msg_error:nnnnVV + { markdown } + { different-versions-of-context-theme } + { #1 } + { #2 } + \l_tmpb_tl + \l_tmpa_tl + } + } + { + \msg_info:nnn + { markdown } + { loading-context-theme } + { #1 } + { #2 } + \prop_gput:Nnx + \g_@@_context_loaded_themes_linenos_prop + { #1 } + { \tex_the:D \tex_inputlineno:D } + \prop_gput:Nnn + \g_@@_context_loaded_themes_versions_prop + { #1 } + { #2 } + \usemodule + [ t ] + [ markdown theme #3 ] + } } { - \@@_plain_tex_load_theme:nn + \@@_plain_tex_load_theme:nnn { #1 } { #2 } + { #3 } } } \msg_new:nnn { markdown } { loading-context-theme } - { Loading~ConTeXt~Markdown~theme~#1 } + { Loading~version~#2~of~ConTeXt~Markdown~theme~#1 } +\msg_new:nnn + { markdown } + { repeatedly-loaded-context-theme } + { + Version~#3~of~ConTeXt~Markdown~theme~#1~was~previously~ + loaded~on~line~#2,~not~loading~it~again + } +\msg_new:nnn + { markdown } + { different-versions-of-context-theme } + { + Tried~to~load~version~#2~of~ConTeXt~Markdown~theme~#1~ + but~version~#3~has~already~been~loaded~on~line~#4 + } \ExplSyntaxOff % \end{macrocode} % \iffalse %</context> -%<*themes-witiko-markdown-defaults-context> +%<*themes-witiko-markdown-defaults-ctx> % \fi % \par % \begin{markdown} @@ -36541,7 +39196,8 @@ end \def\markdownRendererStrikeThroughPrototype#1{\overstrikes{#1}} \def\markdownRendererSuperscriptPrototype#1{\high{#1}} \def\markdownRendererSubscriptPrototype#1{\low{#1}} -\def\markdownRendererDisplayMathPrototype#1{\startformula#1\stopformula}% +\def\markdownRendererDisplayMathPrototype#1{% + \startformula#1\stopformula}% % \end{macrocode} % \par % \begin{markdown} @@ -36567,8 +39223,10 @@ end \placetable{#1}{\the\markdownConTeXtTable}}% \fi \begingroup - \setupTABLE[r][each][topframe=off, bottomframe=off, leftframe=off, rightframe=off] - \setupTABLE[c][each][topframe=off, bottomframe=off, leftframe=off, rightframe=off] + \setupTABLE[r][each][topframe=off, bottomframe=off, + leftframe=off, rightframe=off] + \setupTABLE[c][each][topframe=off, bottomframe=off, + leftframe=off, rightframe=off] \setupTABLE[r][1][topframe=on, bottomframe=on] \setupTABLE[r][#1][bottomframe=on] \markdownConTeXtRowCounter=0% @@ -36606,14 +39264,16 @@ end \fi\if#1r% \setupTABLE[c][\the\markdownConTeXtColumnCounter][align=left] \fi - \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax\else + \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax + \else \expandafter\gobbleoneargument \fi\markdownConTeXtReadAlignments} \def\markdownConTeXtRenderTableCell#1{% \advance\markdownConTeXtColumnCounter by 1\relax \markdownConTeXtTable=\expandafter{% \the\markdownConTeXtTable\bTD#1\eTD}% - \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax\else + \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax + \else \expandafter\gobbleoneargument \fi\markdownConTeXtRenderTableCell} % \end{macrocode} @@ -36636,13 +39296,13 @@ end { { latex } { - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { #1 } { context } } } { - \@@_plain_tex_default_input_raw_inline_renderer_prototype:nn + \@@_plain_tex_default_input_raw_inline:nn { #1 } { #2 } } @@ -36655,13 +39315,13 @@ end { { context } { - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { #1 } { tex } } } { - \@@_plain_tex_default_input_raw_block_renderer_prototype:nn + \@@_plain_tex_default_input_raw_block:nn { #1 } { #2 } } @@ -36675,7 +39335,7 @@ end \protect % \end{macrocode} % \iffalse -%</themes-witiko-markdown-defaults-context> +%</themes-witiko-markdown-defaults-ctx> %<*context> % \fi % \par @@ -36688,9 +39348,29 @@ end % % \end{markdown} % \begin{macrocode} -\markdownIfOption{noDefaults}{}{ - \setupmarkdown[theme=witiko/markdown/defaults] -} +\ExplSyntaxOn +\str_if_eq:VVT + \c_@@_top_layer_tl + \c_@@_option_layer_context_tl + { + \ExplSyntaxOff + \@@_if_option:nF + { noDefaults } + { + \@@_if_option:nTF + { experimental } + { + \@@_setup:n + { theme = witiko/markdown/defaults@experimental } + } + { + \@@_setup:n + { theme = witiko/markdown/defaults } + } + } + \ExplSyntaxOn + } +\ExplSyntaxOff \stopmodule \protect % \end{macrocode} |