Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Build every code block in one place
Diffstat (limited to '')
| -rw-r--r-- | custom/extensions/about-render.lua | 28 |
1 file changed, 11 insertions, 17 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 62da9a8..e549478 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -522,6 +522,14 @@ if has_lpeg then or table_starts(lines, i) end + local function code_block(lines) + local text = table.concat(lines, "\n") + if #lines > 0 then + text = text .. "\n" + end + return { kind = "code", text = text } + 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. @@ -562,14 +570,7 @@ if has_lpeg then i = i + 1 end i = i + 1 - local body = table.concat(code, "\n") - if #code > 0 then - body = body .. "\n" - end - blocks[#blocks + 1] = { - kind = "code", - text = body, - } + blocks[#blocks + 1] = code_block(code) elseif hashes then blocks[#blocks + 1] = { kind = "heading", @@ -653,10 +654,7 @@ if has_lpeg then while code[#code]:match("^%s*$") do code[#code] = nil end - blocks[#blocks + 1] = { - kind = "code", - text = table.concat(code, "\n") .. "\n", - } + blocks[#blocks + 1] = code_block(code) else local paragraph, level = { line }, nil i = i + 1 @@ -872,11 +870,7 @@ if has_lpeg then end local function flush_nofill() if nofill_lines then - local body = table.concat(nofill_lines, "\n") - if #nofill_lines > 0 then - body = body .. "\n" - end - blocks[#blocks + 1] = { kind = "code", text = body } + blocks[#blocks + 1] = code_block(nofill_lines) nofill_lines = nil end end |
