Skip to content

Commit

Permalink
[Doc] Make pandoc filter 2.9 compatible
Browse files Browse the repository at this point in the history
Man pages look better with pandoc >= 2.17
  • Loading branch information
lbonn committed Mar 5, 2024
1 parent 262c2f8 commit 78b50f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions doc/man_filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ function convert_defs(doc, defs)
return pandoc.Pandoc(outBlocks, doc.meta)
end

-- for <2.17 compatibility
-- equivalent to `doc:walk(filter)`
local function walk_doc(doc, filter)
local div = pandoc.Div(doc.blocks)
local blocks = pandoc.walk_block(div, filter).content
return pandoc.Pandoc(blocks, doc.meta)
end

local function extract_title(doc)
local title = {}
local section
Expand All @@ -141,14 +149,14 @@ local function extract_title(doc)
end,
}
if el.level == 1 then
el:walk(f)
pandoc.walk_block(el, f)
return {} -- drop
end
return nil
end,
}

doc = doc:walk(filter)
doc = walk_doc(doc, filter)

local to_inline = function(s)
local r = {}
Expand Down Expand Up @@ -190,7 +198,8 @@ local function decrement_heading(doc)
end,
}

return doc:walk(filter)
doc = walk_doc(doc, filter)
return doc
end

local function code_in_strong(doc)
Expand All @@ -200,7 +209,8 @@ local function code_in_strong(doc)
end,
}

return doc:walk(filter)
doc = walk_doc(doc, filter)
return doc
end

--- Run filtering function through whole document
Expand All @@ -211,9 +221,11 @@ end
-- * decrement heading from 1 for better display
-- * convert inline code text to Strong as usual in man pages
function Pandoc(doc)
local defs = find_defs(doc)

doc = convert_defs(doc, defs)
if PANDOC_VERSION >= pandoc.types.Version("2.17.0") then
-- 2.17 is required for topdown traversal
local defs = find_defs(doc)
doc = convert_defs(doc, defs)
end

doc = extract_title(doc)

Expand Down
2 changes: 1 addition & 1 deletion doc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ man_files = [

fs = import('fs')

pandoc = find_program('pandoc', required: false, version: '>=2.17')
pandoc = find_program('pandoc', required: false, version: '>=2.9')

if pandoc.found()
man_targets = []
Expand Down

0 comments on commit 78b50f2

Please sign in to comment.