diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Let a table cut a paragraph short
A table written right under a line of text came out as more of the paragraph, pipes and all.
Diffstat (limited to 'custom/extensions/about-render.lua')
-rw-r--r--custom/extensions/about-render.lua17
1 file changed, 15 insertions, 2 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua
index af18d1b..ed7e340 100644
--- a/custom/extensions/about-render.lua
+++ b/custom/extensions/about-render.lua
@@ -377,6 +377,19 @@ if has_lpeg then
local function ordered(mark) return mark:match("%d") ~= nil end
+ local function table_starts(lines, i)
+ return i < #lines and lines[i]:find("|", 1, true) ~= nil
+ and table_delimiter:match(lines[i + 1]) ~= nil
+ end
+
+ -- A blank line ends a paragraph, and so does the start of any other
+ -- block. That includes a table, which GitHub's own parser lets cut a
+ -- paragraph short.
+ local function ends_paragraph(lines, i)
+ return lines[i]:match("^%s*$") or block_start:match(lines[i])
+ or table_starts(lines, i)
+ end
+
-- A paragraph's lines run together the way GitHub shows them, unless one
-- ends in two spaces or a backslash, which breaks the line there. The
-- last line of a paragraph has nothing to break before.
@@ -455,7 +468,7 @@ if has_lpeg then
lines = paragraph_lines(inner),
}
end
- elseif i + 1 <= n and line:find("|", 1, true) and table_delimiter:match(lines[i + 1]) then
+ elseif table_starts(lines, i) then
local head = {}
for _, cell in ipairs(split_cells(line)) do
head[#head + 1] = parse_inline(cell)
@@ -494,7 +507,7 @@ if has_lpeg then
else
local paragraph = { line }
i = i + 1
- while i <= n and not lines[i]:match("^%s*$") and not block_start:match(lines[i]) do
+ while i <= n and not ends_paragraph(lines, i) do
paragraph[#paragraph + 1] = lines[i]
i = i + 1
end