Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Read a setext heading's level off its capture
Diffstat (limited to 'custom/extensions/about-render.lua')
| -rw-r--r-- | custom/extensions/about-render.lua | 14 |
1 file changed, 4 insertions, 10 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index e549478..5889e97 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -354,7 +354,8 @@ end local render_markdown, render_man if has_lpeg then - local P, R, S, B, C, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.B, lpeg.C, lpeg.Ct + local P, R, S, B = lpeg.P, lpeg.R, lpeg.S, lpeg.B + local C, Cc, Ct = lpeg.C, lpeg.Cc, lpeg.Ct local space = S(" \t") local whitespace = S(" \t\r\n\f\v") @@ -458,7 +459,7 @@ if has_lpeg then local heading_line = C(P("#") * P("#") ^ -5) * space ^ 1 * C(P(1) ^ 0) -- A run of equals signs or dashes under a paragraph turns it into a -- heading, as on GitHub, rather than reading as more of its text. - local setext_line = space ^ 0 * (C(P("=") ^ 1) + C(P("-") ^ 1)) + local setext_line = space ^ 0 * (P("=") ^ 1 * Cc(1) + P("-") ^ 1 * Cc(2)) * space ^ 0 * eol local code_indent = P(" ") + P("\t") local function thematic(mark) @@ -502,13 +503,6 @@ if has_lpeg then return line:match("^\t(.*)$") or line:match("^ ? ? ? ?(.*)$") end - local function setext_level(line) - local run = setext_line:match(line) - if run then - return run:sub(1, 1) == "=" and 1 or 2 - end - 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 @@ -659,7 +653,7 @@ if has_lpeg then local paragraph, level = { line }, nil i = i + 1 while i <= n do - level = setext_level(lines[i]) + level = setext_line:match(lines[i]) if level or ends_paragraph(lines, i) or break_line:match(lines[i]) then break |
