I'm trying to convert an HTML file to Markdown using Pandoc, but I'm having a hard time finding the correct options.

I would like convert the entire HTML file to the simplest Markdown possible. That is, no <div> tags and no CSS styling in curly brackets. However, when I input the following HTML to pandoc by calling pandoc -f html -t markdown reduced.html -o res.md:

<div class="section-content">
<div class="section-inner sectionLayout--insetColumn">
    <h3 name="2ee9" id="2ee9" class="graf graf--h3 graf--leading graf--title">Post Title</h3>
    <p name="021f" id="021f" class="graf graf--p graf-after--h3">Preamble <a href="https://cogsci.stackexchange.com/users/4397/seanny123?tab=questions" data-href="https://cogsci.stackexchange.com/users/4397/seanny123?tab=questions" class="markup--anchor markup--p-anchor" rel="noopener" target="_blank">link</a> and conclusion.</p>

I get the following Markdown output with all the things I'd like to ignore:

<div class="section-content">

<div class="section-inner sectionLayout--insetColumn">

### Post Title {#2ee9 .graf .graf--h3 .graf--leading .graf--title name="2ee9"}

.markup--p-anchor} and conclusion.



I tried reading the Pandoc Markdown docs, but I couldn't find any indication of what parameters I should be using.


If you use pandoc -f html -t markdown_github-raw_html reduced.html -o res.md it solves the problem.

  • markdown_github reduces the set of outputs to ignore the CSS

  • -raw_html removes the raw_html extension, which fixes the links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.