feature/table-of-content-docx #2

Merged
jason merged 58 commits from jonathan/cpolis:feature/table-of-content-docx into devel 2025-02-04 17:36:46 +01:00
Showing only changes of commit 38af6d3f0b - Show all commits

View File

@ -1,6 +1,3 @@
-- custom-toc.lua
-- This filter builds a custom TOC without images in the link text,
-- leaving the actual header content (with images) untouched.
-- Helper function: remove all image inlines from a list of inlines.
local function remove_images(inlines)
@ -18,11 +15,9 @@ local function build_toc(doc)
local toc_items = {}
for _, block in ipairs(doc.blocks) do
if block.t == "Header" then
-- Remove images from the header content to use for the TOC.
local clean_inlines = remove_images(block.content)
local header_text = pandoc.utils.stringify(clean_inlines)
if header_text ~= "" then
-- Create a link using the cleaned inlines and the headers identifier.
local link = pandoc.Link(clean_inlines, "#" .. block.identifier)
table.insert(toc_items, { link })
end
@ -33,7 +28,6 @@ end
-- The Pandoc function runs after the document is fully constructed.
function Pandoc(doc)
-- Build the custom TOC.
local toc = build_toc(doc)
-- Insert the TOC at the very beginning of the document.
table.insert(doc.blocks, 1, toc)