繁体   English   中英

Pandoc Lua:如何在 header 周围添加 markdown 块而不丢失 Z590FC197FE73DB0AA2EC03687A372

[英]Pandoc Lua : how to add a markdown block around a header without losing the markdown syntax #

我正在尝试在 Lua 过滤器中围绕 markdown header 添加一个 div,但标题前面的 # 在 Z7135CEDD1F39383 中消失了

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

输入:

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


预计 Output

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

content字段包含标题文本,但标题本身是不返回的el元素。 将它与原始块一起返回应该可以工作:

return {
  pre, el, post
}

或者使用 Div 元素:

function Header (el)
  if h.level == 1 then
    return pandoc.Div(el, {class = 'test'})
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM