From 2712d3e869b8a371e1fa261f05fbd5d76561e3a0 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 15 Aug 2019 22:53:02 +0200 Subject: 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 --- test/lua/module/pandoc.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/lua') diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua index ca2168805..1725d275b 100644 --- a/test/lua/module/pandoc.lua +++ b/test/lua/module/pandoc.lua @@ -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) + } } -- cgit v1.2.3