diff options
| author | Albert Krewinkel <[email protected]> | 2025-08-12 21:19:56 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2025-08-12 21:37:35 +0200 |
| commit | a36654b22286c0459fb4d7d354c865da23d6061f (patch) | |
| tree | b188c7f4af08910d7d553916a2f12bc3e93e0d89 /pandoc-lua-engine/test/lua/module/pandoc-structure.lua | |
| parent | 68d80cc9d914c23831aace776f0d5c981fd882e9 (diff) | |
Lua: add function `pandoc.structure.unique_identifier`.
The function generates element identifiers based on inlines content.
It's primary use case is the programmatic generation of ID, similar to
what the `auto_identifiers` extension provides for many formats.
Diffstat (limited to 'pandoc-lua-engine/test/lua/module/pandoc-structure.lua')
| -rw-r--r-- | pandoc-lua-engine/test/lua/module/pandoc-structure.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-structure.lua b/pandoc-lua-engine/test/lua/module/pandoc-structure.lua index ff2abba22..159e6e27b 100644 --- a/pandoc-lua-engine/test/lua/module/pandoc-structure.lua +++ b/pandoc-lua-engine/test/lua/module/pandoc-structure.lua @@ -136,4 +136,28 @@ return { ) end), }, + group 'unique_identifier' { + test('returns an identifier based on the input', function () + local inlines = pandoc.Inlines{pandoc.Emph{'This'}, ' is nice'} + local id = structure.unique_identifier(inlines) + assert.are_equal('this-is-nice', id) + end), + test('respects the list of used IDs', function () + local inlines = pandoc.Inlines('Hello, World!') + local used = {['hello-world'] = true} + local id = structure.unique_identifier(inlines, used) + assert.are_equal('hello-world-1', id) + end), + test('defaults to pandoc Markdown identifiers', function () + local inlines = pandoc.Inlines('Mr. Jones') + local id = structure.unique_identifier(inlines, {}) + assert.are_equal('mr.-jones', id) + end), + test('can generate gfm identifiers', function () + local inlines = pandoc.Inlines('Mr. Jones') + local exts = {'gfm_auto_identifiers'} + local id = structure.unique_identifier(inlines, {}, exts) + assert.are_equal('mr-jones', id) + end), + } } |
