mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user