9f984ff26a
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
c1d058aeb1
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`.
93 lines
2.6 KiB
Lua
93 lines
2.6 KiB
Lua
local tasty = require 'tasty'
|
|
local utils = require 'pandoc.utils'
|
|
|
|
local assert = tasty.assert
|
|
local test = tasty.test_case
|
|
local group = tasty.test_group
|
|
|
|
return {
|
|
group 'blocks_to_inlines' {
|
|
test('default separator', function ()
|
|
local blocks = {
|
|
pandoc.Para { pandoc.Str 'Paragraph1' },
|
|
pandoc.Para { pandoc.Emph { pandoc.Str 'Paragraph2' } }
|
|
}
|
|
local expected = {
|
|
pandoc.Str 'Paragraph1',
|
|
pandoc.Space(), pandoc.Str '¶', pandoc.Space(),
|
|
pandoc.Emph { pandoc.Str 'Paragraph2' }
|
|
}
|
|
assert.are_same(
|
|
expected,
|
|
utils.blocks_to_inlines(blocks)
|
|
)
|
|
end),
|
|
test('custom separator', function ()
|
|
local blocks = {
|
|
pandoc.Para{ pandoc.Str 'Paragraph1' },
|
|
pandoc.Para{ pandoc.Emph 'Paragraph2' }
|
|
}
|
|
local expected = {
|
|
pandoc.Str 'Paragraph1',
|
|
pandoc.LineBreak(),
|
|
pandoc.Emph { pandoc.Str 'Paragraph2' }
|
|
}
|
|
assert.are_same(
|
|
expected,
|
|
utils.blocks_to_inlines(blocks, { pandoc.LineBreak() })
|
|
)
|
|
end)
|
|
},
|
|
|
|
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.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)
|
|
},
|
|
|
|
group 'normalize_date' {
|
|
test('09 Nov 1989', function ()
|
|
assert.are_equal('1989-11-09', utils.normalize_date '09 Nov 1989')
|
|
end),
|
|
test('12/31/2017', function ()
|
|
assert.are_equal('2017-12-31', utils.normalize_date '12/31/2017')
|
|
end),
|
|
},
|
|
|
|
group 'sha1' {
|
|
test('hashing', function ()
|
|
local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
|
|
assert.are_equal(ref_hash, utils.sha1 'Hello, World!')
|
|
end)
|
|
},
|
|
|
|
group 'stringify' {
|
|
test('inlines', function ()
|
|
local inline = pandoc.Emph{
|
|
pandoc.Str 'Cogito',
|
|
pandoc.Space(),
|
|
pandoc.Str 'ergo',
|
|
pandoc.Space(),
|
|
pandoc.Str 'sum.',
|
|
}
|
|
assert.are_equal('Cogito ergo sum.', utils.stringify(inline))
|
|
end)
|
|
},
|
|
|
|
group 'to_roman_numeral' {
|
|
test('convertes number', function ()
|
|
assert.are_equal('MDCCCLXXXVIII', utils.to_roman_numeral(1888))
|
|
end),
|
|
test('fails on non-convertible argument', function ()
|
|
assert.is_falsy(pcall(utils.to_roman_numeral, 'not a number'))
|
|
end)
|
|
},
|
|
}
|