Extend Pandoc with custom Markdown syntax
Asked Answered
T

0

0

I want to extend R Markdown with the following syntactic sugar for acronyms:

The (WHO:: World Health Organization) is an agency of the (UN:: United Nations)

which should be translated to the following raw LaTeX with \nomenclature

The WHO\nomenclature{WHO}{World Health Organization} is an agency of the UN\nomenclature{UN}{United Nations}

and after compilation I would see a glossary page and this text:

The WHO is an agency of the UN

I figured out, that Pandoc has Lua filters, but I'm not a Lua (or Haskel) programmer and It's hard for me to understand where I'm wrong:

– get an entire paragraph from AST
function Para(s)
    -- match new syntax: (ACRONYM:: definition)
    before, acronym, definition, after = tostring(s):match("(.*)%((.*)::(.-)%)(.*)")

    -- if matched
    if acronym then
        -- interpolate new paragrath string
        new = string.format('%s%s\\nomenclature{%s}{%s}%s', before, acronym, acronym, definition, after)
        -- return new AST element
        return pandoc.read(new)
    else
        return s
    end

end

Unfortunately, I see raw Para structure in an output PDF.

Tumbleweed answered 18/2, 2022 at 6:32 Comment(2)
You should put together a complete example that other can run and see what you saw.Deeprooted
I'd recommend you use a native span instead of your custom syntax, which is much easier to match on in a filter...Oshaughnessy

© 2022 - 2024 — McMap. All rights reserved.