简体   繁体   English

Pandoc过滤器pandoc中的字符escaping.Para Lua function

[英]Character escaping in Pandoc filter pandoc.Para Lua function

I'm using Pandoc for a large HTML to Markdown conversion project and am trying to write lua filters to handle some of the special cases.我正在将 Pandoc 用于大型 HTML 到 Markdown 转换项目,并且正在尝试编写 lua 过滤器来处理一些特殊情况。

The most common case I am trying to handle is converting specially formatted information boxes into the pymarkdown summary/detail formatting .我试图处理的最常见的情况是将特殊格式的信息框转换为 pymarkdown 摘要/详细信息格式

Source HTML来源 HTML

<div class="special-info-block">
  <p class="title">INFO</p>
</div>

Goal Markdown目标 Markdown

???+ info "INFO"

I can use this function to replace the "INFO":我可以使用这个 function 来替换“INFO”:

function Div(el)
   if el.classes[2] == "special-info-block" and pandoc.utils.stringify(el.content[1]) == "INFO" then
      el.content[1] = pandoc.Para('??? info "INFO"+')
      return el
   end
end

but the resulting markdown escapes the quotation marks around INFO:但生成的 markdown 转义了 INFO 周围的引号:

???+ info \"INFO\"

How do I insert the literal string instead?如何改为插入文字字符串? Is this a feature of the pandoc.Para constructor or should I be looking elsewhere?这是 pandoc.Para 构造函数的一个特性还是我应该在别处寻找?

The escaping happens during Markdown generation, so there are two options here: escaping 发生在 Markdown 生成期间,因此这里有两个选项:

  1. Call pandoc with -t markdown-smart , which will instruct the Markdown writer to treat quotes as normal chars;使用-t markdown-smart调用 pandoc,这将指示 Markdown 编写器将引号视为普通字符;

  2. Create a raw Markdown block instead of a Para to get maximal control over the output: el.content[1] = pandoc.RawBlock('markdown', '??? info "INFO"+') .创建原始 Markdown 块而不是 Para 以获得对 output 的最大控制: el.content[1] = pandoc.RawBlock('markdown', '??? info "INFO"+')

Both methods these should give the desired result, but the second is probably preferable.这两种方法都应该给出预期的结果,但第二种方法可能更可取。

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

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