Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify initial header level on HTML output #55

Closed
nosammai opened this issue Aug 22, 2018 · 2 comments
Closed

Specify initial header level on HTML output #55

nosammai opened this issue Aug 22, 2018 · 2 comments
Assignees
Labels

Comments

@nosammai
Copy link

nosammai commented Aug 22, 2018

Hi,

Sorry if this is a silly question, but I'm trying to parse some markdown and embed it as html inside of a page on my web application. This page already has a couple levels of Header tags, so I'd like for the headings inside the markdown to start at <h3> rather than <h1>. Is it possible to pass in an initial header level to the HTMLRenderer?

Thanks!

@miyuchina miyuchina self-assigned this Aug 25, 2018
@miyuchina
Copy link
Owner

Hey! Not stupid at all, although it is going to be slightly more complicated than passing in a value. Something like this will do:

class MyRenderer(HTMLRenderer):
    def render_heading(self, token):
        template = '<h{level}>{inner}</h{level}>'
        inner = self.render_inner(token)
        return template.format(level=token.level+2, inner=inner)

... and you can use MyRenderer just like HTMLRenderer.

Let me know if you have more questions!

@nosammai
Copy link
Author

Awesome, that worked great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants