htmlmarkdownpandocconverters

Pandoc: Convert Markdown to HTML *without* any HTML attributes


Is there a way to tell Pandoc to convert Markdown to HTML so that it only generates plain HTML tags without any attributes/classes?

Current Pandoc output

<pre class="sourceCode bash">
  <code class="sourceCode bash">
    TEXT
  </code>
</pre>

Desired Pandoc output

<pre>
  <code>
    TEXT
  </code>
</pre>

Solution

  • There is no built-in option, but you can use a simple filter to remove all attributes and classes. Save the following to a file remove-attr.lua and call pandoc with --lua-filter=remove-attr.lua.

    function remove_attr (x)
      if x.attr then
        x.attr = pandoc.Attr()
        return x
      end
    end
    
    return {{Inline = remove_attr, Block = remove_attr}}