isthisnagee
isthisnagee

Reputation: 23

How do I change the output of pandoc's markdown to html conversion

So for example, if I do

# Header

pandoc gives out <h1 id="header">Header</h1>. I want something like

<h1 class="something" id="header">Header</h1>

Is there some file where I can change the html tag output in $body$?

Edit, I'm looking for a "natural" change (if that makes sense). So # header "naturally" gives back <h1 class="classname">header</h1>

I guess I'll look through the source code/docs for something.

Upvotes: 2

Views: 806

Answers (2)

scoa
scoa

Reputation: 19857

To add a class to all elements of a certain type, you could use a filter. Here is one made with panflute; let us save it as add_class_to_header1.py, and then compile the document with pandoc mydoc.md -F add_class_to_header1.py -t ...

import panflute as pf


def add_class_to_header1(elem, doc):
    if isinstance(elem, pf.Header) and elem.level == 1:
        elem.classes = ["classname"]
    return elem


if __name__ == "__main__":
    pf.run_filter(add_class_to_header1)

Upvotes: 2

Sergio Correia
Sergio Correia

Reputation: 1101

Is this what you want?

>echo # header {.something} | pandoc
<h1 id="header" class="something">header</h1>

If you want more info on how this works, check the section on bracketed_spans on the manual, but in general adding {.class} to many objects will set their class.

Upvotes: 1

Related Questions