简体   繁体   English

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

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

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.我正在尝试在 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

Input:输入:

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


Expected Output预计 Output

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

The content field contains the heading text, but the heading itself is the el element that's not returned. content字段包含标题文本,但标题本身是不返回的el元素。 Returning it together with the raw blocks should work though:将它与原始块一起返回应该可以工作:

return {
  pre, el, post
}

Or use a Div element:或者使用 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.

相关问题 Pandoc:在 a.md 文件中,如何修改 YAML 元数据块并使用 lua 过滤器将修改后的块放入 markdown 格式 - Pandoc: in a .md file, how to modifiy the YAML metadata block and put the modified block in markdown format using a lua filter 将 Markdown 警告语法转换为 HTML,将 Lua 用于 Pandoc - Convertng Markdown admonition syntax to HTML, using Lua for Pandoc 从 markdown 转换为 HTML 时,使用 Pandoc Lua 过滤器替换 HTML 标签 - Replace HTML tags using Pandoc Lua filter when converting from markdown to HTML Pandoc Lua:如何将类添加到 Para - Pandoc Lua: how to add class to a Para 如何使用pandoc lua过滤器将标题添加为1级标题? - How pandoc lua filters can be used to add the title as the level-1 header? 如何在 R Markdown 中将两个单独的 lua 过滤器应用于 Span 元素? - How to apply two separate lua filters to Span elements, in R Markdown? 在 Pandoc markdown 中为 html 和 pdf 使用跨度(f)或字体颜色? - Using span (f)or font color in Pandoc markdown for both html and pdf? 通过pandoc lua过滤器添加元数据字段 - add metadata field via pandoc lua filter 如何在Lua中创建字符串模式以查找类似于markdown的封装文本? - How could I create a string pattern in Lua to find encapsulated text similar to markdown? 如何在pandoc中自动在标题前添加分页符 - How to add a page break before header automatically in pandoc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM