简体   繁体   中英

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.

The most common case I am trying to handle is converting specially formatted information boxes into the pymarkdown summary/detail formatting .

Source HTML

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

Goal Markdown

???+ info "INFO"

I can use this function to replace the "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:

???+ 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?

The escaping happens during Markdown generation, so there are two options here:

  1. Call pandoc with -t markdown-smart , which will instruct the Markdown writer to treat quotes as normal chars;

  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"+') .

Both methods these should give the desired result, but the second is probably preferable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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