Lua: traverse nested blocks and inlines in correct order

Traversal methods are updated to use the new Walk module such that
sequences with nested Inline (or Block) elements are traversed in the
order in which they appear in the linearized document.

Fixes: #5667
This commit is contained in:
Albert Krewinkel
2019-08-16 20:52:15 +02:00
parent 813e1fc7e0
commit 2712d3e869
3 changed files with 62 additions and 11 deletions
+38
View File
@@ -171,4 +171,42 @@ return {
)
end)
},
group 'walk_block' {
test('block walking order', function ()
local acc = {}
local nested_nums = pandoc.Div {
pandoc.Para{pandoc.Str'1'},
pandoc.Div{
pandoc.Para{pandoc.Str'2'},
pandoc.Para{pandoc.Str'3'}
},
pandoc.Para{pandoc.Str'4'}
}
pandoc.walk_block(
nested_nums,
{Para = function (p) table.insert(acc, p.content[1].text) end}
)
assert.are_equal('1234', table.concat(acc))
end)
},
group 'walk_inline' {
test('inline walking order', function ()
local acc = {}
local nested_nums = pandoc.Span {
pandoc.Str'1',
pandoc.Emph {
pandoc.Str'2',
pandoc.Str'3'
},
pandoc.Str'4'
}
pandoc.walk_inline(
nested_nums,
{Str = function (s) table.insert(acc, s.text) end}
)
assert.are_equal('1234', table.concat(acc))
end)
}
}