Search code examples
markdownpandocdocusaurus

Prevent pandoc from escaping a characters


In source markdown (WikiJS format) i have the following element:

![](/src/guides/administrator-guide/media/button_dataset.png){height=0.8cm}

I need to transform it into an md that can be used in docusaurus. Since docusaurus supports mdx it is possible to use html-tags inside *.md code. Something like this:

<img src="/src/guides/administrator-guide/media/button_dataset.png" height="0.8cm" />

I'm trying to write a custom lua filter to convert source to img tag. Like this:

function Image (elem)
    return '<img src="' .. img.src .. '"' .. 'height="' .. img.attributes.height .. '" />'
end

The problem is tha pandoc keeps escaping <, > and " characters so tag cannot be rendered. The output markdown is:

\<img
src=\"/src/guides/administrator-guide/media/button_dataset.png\"
/\>

Is it possible in pandoc to write string to output markdown document as it is without escaping characters? Maybe there is some option that i need to enable? Thanks.


Solution

  • For this specific problem, a good solution might be to choose commonmark instead of pandoc's default Markdown as output format:

    $ pandoc -t commonmark input.md
    <img src="/src/guides/administrator-guide/media/button_dataset.png"
    style="height:0.8cm" />
    

    However, if you prefer to use a filter, then use RawInline elements to avoid escaping:

    function Image (elem)
      return pandoc.RawInline(
        'html',
        string.format('<img src="%s" height="%s" />', img.src, img.attributes.height)
      )
    end