Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Wrap a man page's font runs with the macros' helper
-rw-r--r--custom/extensions/about-render.lua38
1 file changed, 11 insertions, 27 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua
index fe0d599..fb5dee7 100644
--- a/custom/extensions/about-render.lua
+++ b/custom/extensions/about-render.lua
@@ -741,30 +741,23 @@ if has_lpeg then
+ C((1 - backslash) ^ 1) / text_token
) ^ 0)
+ local function in_font(font, nodes)
+ if font == "B" then
+ return { { kind = "strong", kids = nodes } }
+ elseif font == "I" then
+ return { { kind = "em", kids = nodes } }
+ end
+ return nodes
+ end
+
local function man_inline(text)
local tokens = man_inline_grammar:match(text)
local nodes, parts, font = {}, {}, "R"
local function flush()
- if #parts == 0 then
- return
- end
local run = table.concat(parts)
parts = {}
- if run == "" then
- return
- end
- if font == "B" then
- nodes[#nodes + 1] = {
- kind = "strong",
- kids = { { kind = "text", text = run } },
- }
- elseif font == "I" then
- nodes[#nodes + 1] = {
- kind = "em",
- kids = { { kind = "text", text = run } },
- }
- else
- nodes[#nodes + 1] = { kind = "text", text = run }
+ if run ~= "" then
+ nodes[#nodes + 1] = in_font(font, { node_text(run) })[1]
end
end
for _, token in ipairs(tokens) do
@@ -811,15 +804,6 @@ if has_lpeg then
end
end
- local function in_font(font, nodes)
- if font == "B" then
- return { { kind = "strong", kids = nodes } }
- elseif font == "I" then
- return { { kind = "em", kids = nodes } }
- end
- return nodes
- end
-
-- Each alternating macro sets its arguments in its two fonts by turns
-- with nothing between them, as in .BR ls (1).
local single_font = { B = "B", I = "I" }