0

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.

Chen Guevara
  • 324
  • 1
  • 4
  • 14
  • 1
    Why do you need to call this from within your code? You already have the generated file. Just save it and reuse it. – Waylan Jun 26 '19 at 13:22
  • 1
    In fact, you can find all of the generated files (for all supported themes) [here](https://github.com/richleland/pygments-css), so you don't have to generate them yourself. – Waylan Jun 26 '19 at 13:26
  • I thought that the generated css is specific for a file but now I see that the command doesn't even use a specific file, how silly of me. Thanks @Waylan – Chen Guevara Jun 26 '19 at 13:27

0 Answers0