Use Markdown fences longer than the snippet’s backticks #21

Merged
eleith merged 1 commits from fix/markdown-snippet-fences into main 2026-11-30 23:56:37 +00:00
3 changed files with 9 additions and 6 deletions

No files matched your search

+1
View File
@@ -18,6 +18,7 @@
- Remove stale quickfix entries when clearing comments without touching other lists.
- Leave the quickfix list alone if it contains rows from another plugin.
- Export to write-only clipboards without trying to read the clipboard back.
- Keep nested backtick fences from breaking Markdown exports.
### Changed
+4 -3
View File
@@ -7,10 +7,11 @@ local function extension(path)
end
local function fence_for(text)
if (text or ""):find("```", 1, true) then
return "````"
local length = 3
for run in (text or ""):gmatch("`+") do
length = math.max(length, #run + 1)
end
return "```"
return string.rep("`", length)
end
---@param views ScratchCommentView[]
+4 -3
View File
@@ -72,9 +72,10 @@ describe("markdown", function()
expect.no_equality(rendered:find("- line 3, col 7–11 (comment-1)", 1, true), nil)
end)
it("fences a snippet that contains a fence with four backticks", function()
local rendered = markdown.render({ view({ snippet = "```\ncode\n```" }) }, {})
expect.no_equality(rendered:find("````lua\n```\ncode\n```\n````", 1, true), nil)
it("wraps a snippet in a fence longer than any fence inside it", function()
local snippet = "`````\nmore code\n`````\n```lua\ncode\n```"
local rendered = markdown.render({ view({ snippet = snippet }) }, {})
expect.no_equality(rendered:find("\n``````lua\n" .. snippet .. "\n``````\n", 1, true), nil)
end)
it("lists orphans in their own section", function()