Lua: add normalize function to *Pandoc* objects

This function performs a normalization of Pandoc documents. E.g.,
multiple successive spaces are collapsed, and tables are normalized such
that all rows and columns contain the same number of cells.

Closes: #10356
This commit is contained in:
Albert Krewinkel
2025-07-19 15:33:21 +02:00
parent 826f487818
commit 9893fe8c65
2 changed files with 25 additions and 0 deletions
+18
View File
@@ -1039,6 +1039,24 @@ equal in Lua if and only if they are equal in Haskell.
`meta`
: document meta information ([Meta] object)
### Methods {#type-pandoc-methods}
#### normalize
`normalize(self)`
Perform a normalization of Pandoc documents. E.g., multiple
successive spaces are collapsed, and tables are normalized, so
that all rows and columns contain the same number of cells.
Parameters:
`self`
: the element ([Pandoc][])
Results:
- cloned and normalized document. ([Pandoc][])
### walk {#type-pandoc:walk}
@@ -164,6 +164,13 @@ return {
assert.are_same(meta.test, {pandoc.Plain{pandoc.Str 'check'}})
end),
},
group 'Pandoc' {
test('normalize', function ()
local doc = pandoc.Pandoc({{'a', pandoc.Space(), pandoc.Space(), 'b'}})
local normalized = pandoc.Pandoc({{'a', pandoc.Space(), 'b'}})
assert.are_equal(normalized, doc:normalize())
end),
},
group 'Other types' {
group 'ReaderOptions' {
test('returns a userdata value', function ()