diff options
| author | Albert Krewinkel <[email protected]> | 2025-07-19 15:33:21 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2025-07-19 15:42:37 +0200 |
| commit | 9893fe8c656fc164259fec59426705cee242a6e2 (patch) | |
| tree | 81b687d6d86aa7c71110097e0ff8c15c80d88109 | |
| parent | 826f487818e6b36ec1e6feeafaa2e9449ce47695 (diff) | |
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
| -rw-r--r-- | doc/lua-filters.md | 18 | ||||
| -rw-r--r-- | pandoc-lua-engine/test/lua/module/pandoc.lua | 7 |
2 files changed, 25 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 4725967eb..1f5998fb5 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -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} diff --git a/pandoc-lua-engine/test/lua/module/pandoc.lua b/pandoc-lua-engine/test/lua/module/pandoc.lua index 18b3c64a9..3d745b428 100644 --- a/pandoc-lua-engine/test/lua/module/pandoc.lua +++ b/pandoc-lua-engine/test/lua/module/pandoc.lua @@ -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 () |
