Pandoc Lua : how to add a markdown block around a header without losing the markdown syntax #
Asked Answered
R

1

3

I am trying to add a div around a markdown header in a Lua filter, but the # in front of the title disappear in the output.

Header = function(el)
    if el.level == 1 then
        local content = el.content
        local pre = pandoc.RawBlock('markdown','::: test')
        local post = pandoc.RawBlock('markdown',':::')
        table.insert(content,1,pre)
        table.insert(content, post)
        return content
    else
        return el
    end
end

Input:

# Linux
## Support for Linux users
Create a shell script


Expected Output

::: test
# Linux
:::
## Support for Linux users
Create a shell script
Rimini answered 3/7, 2022 at 5:58 Comment(0)
P
3

The content field contains the heading text, but the heading itself is the el element that's not returned. Returning it together with the raw blocks should work though:

return {
  pre, el, post
}

Or use a Div element:

function Header (el)
  if h.level == 1 then
    return pandoc.Div(el, {class = 'test'})
  end
end
Pettus answered 3/7, 2022 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.