1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python Markdown - Not adding codehilite

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Flask to write a Blog, with that I am using Markdown's Python library to generate HTML for me, I am willing to have syntax highlighting, therefore I am using markdown.markdown(string, extensions=['codehilite']

    According to their wiki, it should add a html class;

    <div class="codehilite"><pre><code># Code goes here ...</code></pre></div>


    But it doesn't seem to be working, following the tryouts from my interpreter;

    In [9]: markdown.version
    Out[9]: '2.3.1'

    In [10]: text = """:::python
    ....: import os
    ....: print "This is a text!"
    ....: """

    In [11]: html = markdown.markdown(text, extensions=['codehilite'])

    In [12]: html
    Out[12]: u'<p>:::python\nimport os\nprint "This is a text!"</p>'

    In [13]: # Even more funnier, when following the examples in the usage section "..['codehilite(linenums=True)']

    In [14]: html = markdown.markdown(text, extensions=['codehilite(linenums=True)'])

    In [15]: html
    Out[15]: u'<p>:::python\nimport os\nprint "This is a text!"</p>'

    In [16]: # No line numbers, or any class..


    I am not sure what's the problem here, I have Pygments installed, I already upgraded Markdown's lib, but nothing. The expected results here would be that Markdown would add the html class codehilite so I will be able to get the syntax working. What seems to be the problem here?

    Continue reading...

Compartilhe esta Página