From 9f984ff26ac248a27212a37ab34754a2e9261e8c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 7 Sep 2019 11:23:12 -0700 Subject: Replace Element and makeHierarchical with makeSections. Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`. --- test/lua/module/pandoc-utils.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'test/lua/module') diff --git a/test/lua/module/pandoc-utils.lua b/test/lua/module/pandoc-utils.lua index dc37ec354..963e70686 100644 --- a/test/lua/module/pandoc-utils.lua +++ b/test/lua/module/pandoc-utils.lua @@ -39,20 +39,17 @@ return { end) }, - group 'hierarchicalize' { + group 'make_sections' { test('sanity check', function () local blks = { pandoc.Header(1, {pandoc.Str 'First'}), pandoc.Header(2, {pandoc.Str 'Second'}), pandoc.Header(2, {pandoc.Str 'Third'}), } - local hblks = utils.hierarchicalize(blks) - -- cannot create Elements directly; performing only an approximate - -- sanity checking instead of a full equality comparison. - assert.are_equal('Sec', hblks[1].t) - assert.are_equal('Sec', hblks[1].contents[1].t) - assert.are_equal(1, hblks[1].contents[2].numbering[1]) - assert.are_equal(2, hblks[1].contents[2].numbering[2]) + local hblks = utils.make_sections(true, 1, blks) + assert.are_equal('Div', hblks[1].t) + assert.are_equal('Header', hblks[1].content[1].t) + assert.are_equal('1', hblks[1].content[1].attributes['number']) end) }, -- cgit v1.2.3