fix: align nested Word blocks and synchronize CSS and heading navigation
This commit is contained in:
@@ -81,5 +81,37 @@ local function quoted_paragraphs(quote)
|
||||
return block
|
||||
end})
|
||||
end
|
||||
-- Raw metadata has no visible paragraph and does not consume a list number.
|
||||
-- The style adapter consumes it before the final DOCX is written.
|
||||
local function contexts(blocks, target, level, depth, item_state)
|
||||
local output = pandoc.List()
|
||||
for _, block in ipairs(blocks) do
|
||||
if block.t == 'OrderedList' or block.t == 'BulletList' then
|
||||
local nested_target = block.t == 'OrderedList' and 'list_ordered' or 'list_bullet'
|
||||
for _, item in ipairs(block.content) do
|
||||
local transformed = contexts(item, nested_target, level + 1, depth, {pending=true})
|
||||
for i=#item,1,-1 do item:remove(i) end
|
||||
item:extend(transformed)
|
||||
end
|
||||
elseif block.t == 'BlockQuote' then
|
||||
block.content = contexts(block.content, target, level, depth + 1, item_state)
|
||||
elseif block.t == 'Div' then
|
||||
block.content = contexts(block.content, target, level, depth, item_state)
|
||||
else
|
||||
if block.t == 'Header' or block.t == 'CodeBlock' or block.t == 'Table' then
|
||||
local continuation = item_state and not item_state.pending and '1' or '0'
|
||||
output:insert(pandoc.RawBlock('openxml', '<mdh:context xmlns:mdh="urn:mdhelper:source"' ..
|
||||
' mdh:list-target="' .. target .. '" mdh:list-level="' .. math.max(0,level) ..
|
||||
'" mdh:quote-depth="' .. depth .. '" mdh:continuation="' .. continuation .. '"/>'))
|
||||
end
|
||||
if item_state and (block.t == 'Para' or block.t == 'Plain' or block.t == 'Header' or block.t == 'CodeBlock' or block.t == 'Table') then
|
||||
item_state.pending = false
|
||||
end
|
||||
end
|
||||
output:insert(block)
|
||||
end
|
||||
return output
|
||||
end
|
||||
return {{Inlines=function(items) return mark(items, {}) end},
|
||||
{BulletList=list_paragraphs, OrderedList=list_paragraphs, BlockQuote=quoted_paragraphs}}
|
||||
{BulletList=list_paragraphs, OrderedList=list_paragraphs, BlockQuote=quoted_paragraphs},
|
||||
{Pandoc=function(doc) doc.blocks=contexts(doc.blocks, '', -1, 0, nil); return doc end}}
|
||||
|
||||
Reference in New Issue
Block a user