Get css for highlighted code with markdown from code without using a command

323 Views Asked by At

I was able to convert markdown to html with code highlighting using python markdown library with the following code:

md = Markdown(
    extensions=[
        FencedCodeExtension(),
        'fenced_code',
        'markdown.extensions.fenced_code:FencedCodeExtension',
        CodeHiliteExtension(),
        'codehilite',
        'markdown.extensions.codehilite'
    ]
)
html = md.convert(content)

Now I need to generate the actual css and I can do it using the following command pygmentize -S default -f html > style.css. The only problem is that I don't want to use the command line interface but do it from within the code. Is there a simple way to do it. I know I can do it using os.system or some subprocess shenanigans but I'd prefer a cleaner solution if there is one.

0

There are 0 best solutions below