diff options
author | Karl Berry <karl@freefriends.org> | 2024-05-28 19:27:46 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-05-28 19:27:46 +0000 |
commit | 64304ec2dbfd8f37ddb60de7807cc0d87ba6ce1f (patch) | |
tree | b2289448adb054e2be5f236fc8d6414ff52054ad /Master/texmf-dist/source | |
parent | 38bc6dbea6a969856de132f557a281abd09cd9e1 (diff) |
markdown (28may24)
git-svn-id: svn://tug.org/texlive/trunk@71378 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/generic/markdown/markdown.dtx | 201 |
1 files changed, 195 insertions, 6 deletions
diff --git a/Master/texmf-dist/source/generic/markdown/markdown.dtx b/Master/texmf-dist/source/generic/markdown/markdown.dtx index bbbd06e8bb9..6ad42a46b26 100644 --- a/Master/texmf-dist/source/generic/markdown/markdown.dtx +++ b/Master/texmf-dist/source/generic/markdown/markdown.dtx @@ -2574,6 +2574,107 @@ local singletonCache = { % \iffalse %</lua> %<*manual-options> + +#### Option `unicodeNormalization` + +`unicodeNormalization` (default value: `true`) + +% \fi +% \begin{markdown} +% +% \Optitem[true]{unicodeNormalization}{\opt{true}, \opt{false}} +% +: true + + : Markdown documents will be normalized using one of the four [Unicode + normalization forms][unicode-normalization] before conversion. The + Unicode normalization norm used is determined by option + \Opt{unicodeNormalizationForm}. + +: false + + : Markdown documents will not be Unicode-normalized before conversion. + + [unicode-normalization]: https://unicode.org/faq/normalization.html + +% \end{markdown} +% \iffalse +%</manual-options> +%<*tex> +% \fi +% \begin{macrocode} +\@@_add_lua_option:nnn + { unicodeNormalization } + { boolean } + { true } +% \end{macrocode} +% \iffalse +%</tex> +%<*lua,lua-cli> +% \fi +% \begin{macrocode} +defaultOptions.unicodeNormalization = true +% \end{macrocode} +% \par +% \iffalse +%</lua,lua-cli> +%<*manual-options> + +#### Option `unicodeNormalizationForm` + +`unicodeNormalizationForm` (default value: `nfc`) + +% \fi +% \begin{markdown} +% +% \Optitem[nfc]{unicodeNormalizationForm}{\opt{nfc}, \opt{nfd}, \opt{nfkc}, \opt{nfkd}} +% +: nfc + + : When option \Opt{unicodeNormalization} has been enabled, markdown documents + will be normalized using Unicode Normalization Form C (NFC) before + conversion. + +: nfd + + : When option \Opt{unicodeNormalization} has been enabled, markdown documents + will be normalized using Unicode Normalization Form D (NFD) before + conversion. + +: nfkc + + : When option \Opt{unicodeNormalization} has been enabled, markdown documents + will be normalized using Unicode Normalization Form KC (NFKC) before + conversion. + +: nfkd + + : When option \Opt{unicodeNormalization} has been enabled, markdown documents + will be normalized using Unicode Normalization Form KD (NFKD) before + conversion. + +% \end{markdown} +% \iffalse +%</manual-options> +%<*tex> +% \fi +% \begin{macrocode} +\@@_add_lua_option:nnn + { unicodeNormalizationForm } + { string } + { nfc } +% \end{macrocode} +% \iffalse +%</tex> +%<*lua,lua-cli> +% \fi +% \begin{macrocode} +defaultOptions.unicodeNormalizationForm = "nfc" +% \end{macrocode} +% \par +% \iffalse +%</lua,lua-cli> +%<*manual-options> % \fi % \begin{markdown} % @@ -25705,8 +25806,12 @@ function M.writer.new(options) local buffer = {} local prev_space = false local letter_found = false + local normalized_s = s + if not options.unicodeNormalization or options.unicodeNormalizationForm ~= "nfc" then + normalized_s = uni_algos.normalize.NFC(normalized_s) + end - for _, code in utf8.codes(uni_algos.normalize.NFC(s)) do + for _, code in utf8.codes(normalized_s) do local char = utf8.char(code) -- Remove everything up to the first letter. @@ -25761,8 +25866,12 @@ function M.writer.new(options) local buffer = {} local prev_space = false local letter_found = false + local normalized_s = s + if not options.unicodeNormalization or options.unicodeNormalizationForm ~= "nfc" then + normalized_s = uni_algos.normalize.NFC(normalized_s) + end - for _, code in utf8.codes(uni_algos.normalize.NFC(s)) do + for _, code in utf8.codes(normalized_s) do local char = utf8.char(code) -- Remove everything up to the first non-space. @@ -29916,6 +30025,25 @@ end return function(input) % \end{macrocode} % \begin{markdown} +% Unicode-normalize the input. +% \end{markdown} +% \begin{macrocode} + if options.unicodeNormalization then + local form = options.unicodeNormalizationForm + if form == "nfc" then + input = uni_algos.normalize.NFC(input) + elseif form == "nfd" then + input = uni_algos.normalize.NFD(input) + elseif form == "nfkc" then + input = uni_algos.normalize.NFKC(input) + elseif form == "nfkd" then + input = uni_algos.normalize.NFKD(input) + else + error(format("Unknown normalization form %s", form)) + end + end +% \end{macrocode} +% \begin{markdown} % Since the Lua converter expects \acro{unix} line endings, normalize the % input. Also add a line ending at the end of the file in case the input file % has none. @@ -32359,13 +32487,38 @@ M.extensions.jekyll_data = function(expect_jekyll_data) for k, _ in pairs(d) do table.insert(keys, k) end - table.sort(keys) +% \end{macrocode} +% \begin{markdown} +% +% For reproducibility, sort the keys. For mixed string-and-numeric keys, sort +% numeric keys before string keys. +% +% \end{markdown} +% \begin{macrocode} + table.sort(keys, function(first, second) + if type(first) ~= type(second) then + return type(first) < type(second) + else + return first < second + end + end) if not p then table.insert(buf, "\\markdownRendererJekyllDataBegin") end - if #d > 0 then + local is_sequence = false + if #d > 0 and #d == #keys then + for i=1, #d do + if d[i] == nil then + goto not_a_sequence + end + end + is_sequence = true + end + ::not_a_sequence:: + + if is_sequence then table.insert(buf, "\\markdownRendererJekyllDataSequenceBegin{") table.insert(buf, self.identifier(p or "null")) table.insert(buf, "}{") @@ -32420,7 +32573,7 @@ M.extensions.jekyll_data = function(expect_jekyll_data) end end - if #d > 0 then + if is_sequence then table.insert(buf, "\\markdownRendererJekyllDataSequenceEnd") else table.insert(buf, "\\markdownRendererJekyllDataMappingEnd") @@ -34065,6 +34218,42 @@ end % % \end{markdown} % \begin{macrocode} +\ExplSyntaxOn +\cs_new:Npn + \markdownInput + #1 + { +% \end{macrocode} +% \begin{markdown} +% +% If the file does not exist in the current directory, we will search for it in +% the directories specified in \mref{l_file_search_path_seq}. On \LaTeX, this +% also includes the directories specified in \mref{input@path}. +% +% \end{markdown} +% \begin{macrocode} + \file_get_full_name:nNTF + { #1 } + \l_tmpa_tl + { + \exp_args:NV + \markdownInputRaw + \l_tmpa_tl + } + { + \msg_error:nnnV + { markdown } + { markdown-file-does-not-exist } + { #1 } + } + } +\msg_new:nnn + { markdown } + { markdown-file-does-not-exist } + { + Markdown~file~#1~does~not~exist + } +\ExplSyntaxOff \begingroup % \end{macrocode} % \begin{markdown} @@ -34076,7 +34265,7 @@ end \catcode`|=0% \catcode`\\=12% \catcode`|&=6% - |gdef|markdownInput#1{% + |gdef|markdownInputRaw#1{% % \end{macrocode} % \begin{markdown} % Change the category code of the percent sign (`\%`) to other, so that a user |