Home  >  Q&A  >  body text

html - python-markdown2不能识别 ``` 包含的代码块?

把markdown代码转换成html代码如何实现?
尝试过python-markdown,看到有人说markdown2可以识别代码块,但是我使用后仍然无法识别?

import markdown2
html_txt = markdown2.markdown(post.body_markdown)

另外,pandoc好用吗?如果好用就准备换pandoc试试。

天蓬老师天蓬老师2742 days ago883

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:11:35

    I haven’t tried python-markdown2, so I can’t give you a direct answer. python-markdown2 has nothing to do with python-markdown 2.x. I have been using the latter myself. However, as far as I know, python-markdown2's syntax for processing tables is different (that is, incompatible). I don't know if the same is true for processing code blocks. python-markdown2 ,因此无法直接给你回答。python-markdown2python-markdown 2.x 没有任何关系,我自己一直在用后者。但是,据我所知,python-markdown2 处理表格的语法是与众不同的(也就是不兼容啦),不知道对代码块的处理是否也是这样。

    python-markdown2 号称比 python-markdown

    python-markdown2 is claimed to be faster than python-markdown, but according to Markdown Parsers in Python it is not.

    The materials mentioned above were written by mistune, another author of the python markdown library. You need to judge by yourself whether it is notarized and objective. It is recommended that you take some time to read through this blog, and you may find a python markdown library that is more suitable for you.

    pandoc is a completely different world :-) It supports a large number of input formats and output formats, and is more like a personal publishing solution. It depends on how you plan to use it. It is developed based on Haskell (you can use lua to write extensions). If you are not familiar with these, you can only use it as a command line tool. In addition, whether the GPL license will affect your redistribution of the application also needs to be evaluated. 🎜

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:11:35

    You need to add the extension fetch-code. Please see the extra parameters for details.

    reply
    0
  • Cancelreply