From 088fedd73d6b4d280d796edb4683f34f92a9816e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Wed, 28 Aug 2024 11:59:48 +0200 Subject: [PATCH] Make `markdown.lua` interact with options `eagerCache` & `finalizeCache` --- markdown.dtx | 616 +++++++++++++++++++++++++++++---------------------- 1 file changed, 351 insertions(+), 265 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 10d1bf48..8495f81d 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -2172,7 +2172,7 @@ In this section, I will describe all the options recognized by the Markdown package. % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} local defaultOptions = {} @@ -2181,7 +2181,7 @@ local defaultOptions = {} % \markdownSetup{snippet=lua-options} % \par % \iffalse -% +% %<*manual-options> ### Lua @@ -2654,14 +2654,14 @@ Hello \markdownRendererEmphasis{world}!\relax % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.eagerCache = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `singletonCache` @@ -2742,13 +2742,13 @@ conversion function. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.singletonCache = true % \end{macrocode} % \iffalse -% +% %<*lua> % \fi % \begin{macrocode} @@ -2797,14 +2797,14 @@ local singletonCache = { % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.unicodeNormalization = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `unicodeNormalizationForm` @@ -2853,14 +2853,14 @@ defaultOptions.unicodeNormalization = true % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.unicodeNormalizationForm = "nfc" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> % \fi % \begin{markdown} @@ -3029,14 +3029,14 @@ option. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.cacheDir = "." % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `contentBlocksLanguageMap` @@ -3193,14 +3193,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentBlocksLanguageMap = "markdown-languages.json" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `debugExtensionsFileName` @@ -3242,14 +3242,14 @@ defaultOptions.contentBlocksLanguageMap = "markdown-languages.json" % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.debugExtensionsFileName = "debug-extensions.json" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `frozenCacheFileName` @@ -3484,14 +3484,14 @@ the markdown document from “Hello *world*!” to “Hi *world*!” was not ref % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.frozenCacheFileName = "frozenCache.tex" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> % \fi % \begin{markdown} @@ -3541,14 +3541,14 @@ See also the option \Opt{gfmAutoIdentifiers}. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.autoIdentifiers = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `blankBeforeBlockquote` @@ -3765,14 +3765,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeBlockquote = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `blankBeforeCodeFence` @@ -4022,14 +4022,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeCodeFence = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `blankBeforeDivFence` @@ -4105,14 +4105,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeDivFence = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `blankBeforeHeading` @@ -4345,14 +4345,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeHeading = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `blankBeforeList` @@ -4571,14 +4571,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.blankBeforeList = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `bracketedSpans` @@ -4667,14 +4667,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.bracketedSpans = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `breakableBlockquotes` @@ -4901,14 +4901,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.breakableBlockquotes = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `citationNbsps` @@ -4995,14 +4995,14 @@ following text, where the middot (`·`) denotes a non-breaking space: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.citationNbsps = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `citations` @@ -5098,14 +5098,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.citations = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `codeSpans` @@ -5324,14 +5324,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.codeSpans = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `contentBlocks` @@ -5498,14 +5498,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentBlocks = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `contentLevel` @@ -5635,14 +5635,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.contentLevel = "block" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `debugExtensions` @@ -5790,14 +5790,14 @@ inserted to the grammar of markdown. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.debugExtensions = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `definitionLists` @@ -5929,14 +5929,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.definitionLists = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `ensureJekyllData` @@ -5975,14 +5975,14 @@ defaultOptions.definitionLists = false % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.ensureJekyllData = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `expectJekyllData` @@ -6099,14 +6099,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.expectJekyllData = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `extensions` @@ -6250,14 +6250,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.extensions = {} % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `fancyLists` @@ -6352,14 +6352,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fancyLists = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `fencedCode` @@ -6519,14 +6519,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedCode = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `fencedCodeAttributes` @@ -6619,14 +6619,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedCodeAttributes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `fencedDivs` {#fenced-divs} @@ -6698,14 +6698,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.fencedDivs = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `finalizeCache` @@ -6862,14 +6862,14 @@ the markdown document from “Hello *world*!” to “Hi *world*!” was not ref % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.finalizeCache = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `frozenCacheCounter` @@ -6931,14 +6931,14 @@ requested using the `frozenCacheCounter` option. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.frozenCacheCounter = 0 % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `gfmAutoIdentifiers` @@ -6980,14 +6980,14 @@ See also the option \Opt{autoIdentifiers}. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.gfmAutoIdentifiers = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `hashEnumerators` @@ -7111,14 +7111,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.hashEnumerators = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `headerAttributes` {#header-attributes} @@ -7160,14 +7160,14 @@ defaultOptions.hashEnumerators = false % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.headerAttributes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `html` @@ -7432,14 +7432,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.html = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `hybrid` @@ -7658,14 +7658,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.hybrid = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `inlineCodeAttributes` @@ -7754,14 +7754,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.inlineCodeAttributes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `inlineNotes` @@ -7855,14 +7855,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.inlineNotes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `jekyllData` @@ -8022,14 +8022,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.jekyllData = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `linkAttributes` @@ -8119,14 +8119,14 @@ image (from [Martin Scharrer's mwe package][mwe]) displayed at size 5cm × 4cm. % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.linkAttributes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `lineBlocks` @@ -8254,14 +8254,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.lineBlocks = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `mark` @@ -8325,14 +8325,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.mark = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `notes` @@ -8488,14 +8488,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.notes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `pipeTables` {#pipe-tables} @@ -8597,14 +8597,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.pipeTables = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `preserveTabs` @@ -8637,14 +8637,14 @@ defaultOptions.pipeTables = false % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.preserveTabs = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `rawAttribute` @@ -8732,14 +8732,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.rawAttribute = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `relativeReferences` @@ -8821,14 +8821,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.relativeReferences = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `shiftHeadings` @@ -8961,14 +8961,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.shiftHeadings = 0 % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `slice` @@ -9179,14 +9179,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.slice = "^ $" % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `smartEllipses` @@ -9394,14 +9394,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.smartEllipses = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `startNumber` @@ -9530,14 +9530,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.startNumber = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `strikeThrough` @@ -9652,14 +9652,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.strikeThrough = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `stripIndent` @@ -9765,14 +9765,14 @@ text “Hello *world*!” % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.stripIndent = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `subscripts` @@ -9857,14 +9857,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.subscripts = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `superscripts` @@ -9949,14 +9949,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.superscripts = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `tableAttributes` @@ -10074,14 +10074,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tableAttributes = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `tableCaptions` {#table-captions} @@ -10204,14 +10204,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tableCaptions = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `taskLists` @@ -10317,14 +10317,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.taskLists = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `texComments` @@ -10433,14 +10433,14 @@ text “Hello *world*!” % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texComments = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `texMathDollars` @@ -10644,14 +10644,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathDollars = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `texMathDoubleBackslash` @@ -10855,14 +10855,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathDoubleBackslash = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `texMathSingleBackslash` @@ -11066,14 +11066,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.texMathSingleBackslash = false % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `tightLists` @@ -11187,14 +11187,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.tightLists = true % \end{macrocode} % \par % \iffalse -% +% %<*manual-options> #### Option `underscores` @@ -11330,14 +11330,14 @@ following text: % \end{macrocode} % \iffalse % -%<*lua,lua-cli> +%<*lua,lua-cli,lua-loader> % \fi % \begin{macrocode} defaultOptions.underscores = true % \end{macrocode} % \endgroup % \iffalse -% +% %<*lua-cli> % \fi % \par @@ -22769,9 +22769,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-loader> +% \fi % \begin{macrocode} local util = {} % \end{macrocode} +% \iffalse +% +%<*lua> +% \fi % \par % \begin{markdown} % @@ -22786,13 +22794,17 @@ function util.err(msg, exit_code) os.exit(exit_code or 1) end % \end{macrocode} +% \iffalse +% +%<*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} @@ -22813,6 +22825,10 @@ function util.cache(dir, string, salt, transform, suffix) return name end % \end{macrocode} +% \iffalse +% +%<*lua> +% \fi % \par % \begin{markdown} % @@ -23071,6 +23087,10 @@ function util.escaper(char_escapes, string_escapes) end end % \end{macrocode} +% \iffalse +% +%<*lua,lua-loader> +% \fi % \par % \begin{markdown} % @@ -23090,6 +23110,55 @@ 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.pack} method takes the pathname `name` of the output file +% prepared by the reader and transforms it to the output format. +% +% \end{markdown} +% \begin{macrocode} +function util.pack(name) + return [[\input{]] .. name .. [[}\relax]] +end +% \end{macrocode} +% \iffalse +% +%<*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` @@ -25406,15 +25475,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} @@ -25459,19 +25519,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. % @@ -31032,31 +31079,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 @@ -31064,92 +31092,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 + 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 @@ -33777,7 +33762,10 @@ end %### Conversion from Markdown to Plain \TeX{} % % The \luamref{new} function of file `markdown.lua` loads file -% `markdown-parser.lua` and calls its own function \luamref{new}. +% `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 @@ -33790,12 +33778,102 @@ local function warn(s) end function M.new(options) - 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{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} +% \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 .. ". " .. + "This will prevent option `eagerCache` from working properly.") + 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 via the \luamref{util.pack} method. +% +% 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 = util.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()) + end + return output end - return parser.new(options) end % \end{macrocode} % \iffalse @@ -33840,7 +33918,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