Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Example:

Current Pandoc output

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

Desired Pandoc output

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

I browsed the official documentation but didn't find any options to do that.

Thanks!

like image 239
glitchform Avatar asked Nov 20 '18 23:11

glitchform


People also ask

How do you change Markdown to HTML?

To convert Markdown to HTML using Typora, click File —> Export —> HTML. Then save the file in your preferred location. The image below shows that the HTML output looks exactly as how the Markdown is displayed inside Typora.

How do I convert to pandoc?

At its most basic, the pandoc command is among the easiest commands to use. You type pandoc into a terminal, provide it the file you want to convert, then type --output and a name for the output file you want. Pandoc can usually auto-detect both formats from their filename extensions and convert from one to the other.

Can pandoc convert from PDF?

You can't. You can try opening the PDF in Word or Google Docs and saving in a format from which pandoc can convert directly.

Does pandoc need LaTeX?

By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed (see --pdf-engine below). Alternatively, pandoc can use ConTeXt, roff ms, or HTML as an intermediate format. To do this, specify an output file with a .


1 Answers

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}}
like image 52
tarleb Avatar answered Oct 07 '22 21:10

tarleb