From 518cf46337836ccab80593621ed09e176532e61c Mon Sep 17 00:00:00 2001 From: lbonn Date: Tue, 5 Mar 2024 15:34:32 +0100 Subject: [PATCH] [Doc] Make pandoc filter 2.9 compatible Man pages look better with pandoc >= 2.17 --- configure.ac | 2 +- doc/man_filter.lua | 26 +++++++++++++++++++------- doc/meson.build | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index f9ec4bf80..58b937f3e 100644 --- a/configure.ac +++ b/configure.ac @@ -174,7 +174,7 @@ dnl Build man pages dnl --------------------------------------------------------------------- AC_ARG_ENABLE([man], AS_HELP_STRING([--disable-man], [Build man pages (default: enabled)])) -pandoc_min_version="2.17" +pandoc_min_version="2.9" AS_IF([test "x$enable_man" != "xno" ], [ AC_CHECK_PROG([pandoc], [pandoc >= ${pandoc_min_version}], [yes])]) AM_CONDITIONAL([FOUND_PANDOC], [test "x$pandoc" = xyes]) diff --git a/doc/man_filter.lua b/doc/man_filter.lua index f1e5401a6..4a556f611 100644 --- a/doc/man_filter.lua +++ b/doc/man_filter.lua @@ -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 @@ -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 = {} @@ -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) @@ -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 @@ -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) diff --git a/doc/meson.build b/doc/meson.build index 17df2da65..b5bb2f015 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -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 = []