Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep counting across a split ordered list
| -rw-r--r-- | custom/extensions/about-render.lua | 9 | |
| -rw-r--r-- | tests/extensions/test-about-render.lua | 7 |
2 files changed, 15 insertions, 1 deletion
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 5738b00..35f30d0 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -309,7 +309,13 @@ local function emit_blocks(blocks) html("</tbody></table>") elseif kind == "list" then local tag = block.ordered and "ol" or "ul" - html("<" .. tag .. ">") + html("<" .. tag) + -- Even a blank line between two items ends a list, so the next + -- one keeps counting from the number its first item gives. + if block.ordered and block.start ~= 1 then + html(" start='" .. block.start .. "'") + end + html(">") for _, item in ipairs(block.items) do html("<li>") emit_lines(item) @@ -626,6 +632,7 @@ if has_lpeg then blocks[#blocks + 1] = { kind = "list", ordered = is_ordered, + start = is_ordered and tonumber(mark:match("%d+")), items = items, } -- Four spaces or a tab start a code block, except straight diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index feb1a68..95e95bb 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -307,6 +307,13 @@ h.contains("dashes render an unordered list", out, "<ul><li>first</li><li>second out = render("README.md", "1. first\n2. second") h.contains("numbers render an ordered list", out, "<ol><li>first</li><li>second</li></ol>") +out = render("README.md", "1. first\n\n2. second\n\n3. third") +h.contains("a list split by blank lines keeps counting", out, + "<ol><li>first</li></ol><ol start='2'><li>second</li></ol><ol start='3'><li>third</li></ol>") + +out = render("README.md", "07) seventh\n08) eighth") +h.contains("a list that opens past one starts there", out, "<ol start='7'><li>seventh</li><li>eighth</li></ol>") + out = render("README.md", "- one\n wrapped\n- two") h.contains("a wrapped item stays one item", out, "<ul><li>one\nwrapped</li><li>two</li></ul>") |
