From ab87f83b617680a11e6f90f240e6ad2ac796dd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 13:42:38 +0200 Subject: [PATCH 1/6] Add `jekyll-data-mixed-keys.test` --- .../jekyll-data-mixed-keys.test | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test diff --git a/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test b/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test new file mode 100644 index 00000000..df42d8f5 --- /dev/null +++ b/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test @@ -0,0 +1,31 @@ +\markdownSetup{jekyllData=true} +<<< +This test ensures that the Lua `jekyllData` option correctly propagates +through the plain TeX interface and that mixed numeric and string keys +are correctly sorted. + +--- +1: foo +a: bar +--- +>>> +BEGIN document +codeSpan: jekyllData +softLineBreak +interblockSeparator +jekyllDataBegin +BEGIN jekyllDataMappingBegin +- key: null +- length: 2 +END jekyllDataMappingBegin +BEGIN jekyllDataString +- key: 1 +- value: foo +END jekyllDataString +BEGIN jekyllDataString +- key: a +- value: bar +END jekyllDataString +jekyllDataMappingEnd +jekyllDataEnd +END document From 6137d0ec57e19905a3cf5f0778cd083c1e761796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 13:50:59 +0200 Subject: [PATCH 2/6] For mixed string/numeric YAML keys, sort numeric keys before string keys --- markdown.dtx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/markdown.dtx b/markdown.dtx index bbbd06e8..9fcb5519 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -32359,7 +32359,21 @@ 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") From d1afe86f940618ab3f8f7eb3b0eaff53f840bdf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 14:17:07 +0200 Subject: [PATCH 3/6] Distinguish YAML maps / sequences in the presence of numeric keys --- markdown.dtx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/markdown.dtx b/markdown.dtx index 9fcb5519..5c01142d 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -32379,7 +32379,18 @@ M.extensions.jekyll_data = function(expect_jekyll_data) 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, "}{") From b8023e3d616741d3d4e00dd2f391fe7bda693c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 14:17:17 +0200 Subject: [PATCH 4/6] Update `jekyll-data-mixed-keys.test` --- tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test b/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test index df42d8f5..e782a6b3 100644 --- a/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test +++ b/tests/testfiles/lunamark-markdown/jekyll-data-mixed-keys.test @@ -12,6 +12,7 @@ a: bar BEGIN document codeSpan: jekyllData softLineBreak +softLineBreak interblockSeparator jekyllDataBegin BEGIN jekyllDataMappingBegin From 8cb6e332794bc1af7598af8a8a30a479f0647011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 14:17:30 +0200 Subject: [PATCH 5/6] Update `CHANGES.md` --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8e061c7f..0164a489 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ## 3.5.1 +Fixes: + +- Correctly sort YAML map keys with mixed types. (#433, #441) + ## 3.5.0 (2024-04-29) Development: From 05becb8f2c8294e8138cf3bbb34b6a3500752305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Star=C3=BD=20Novotn=C3=BD?= Date: Mon, 6 May 2024 14:49:10 +0200 Subject: [PATCH 6/6] Distinguish YAML maps / sequences in the presence of numeric keys --- markdown.dtx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown.dtx b/markdown.dtx index 5c01142d..dcc8e6af 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -32445,7 +32445,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")