PYTHON-MARKDOWN EXTENSIONS -- MARKDOWN 扩展教程

Python-Markdown has been updated to 3.1.1. Markdown could transfer the text content into rich styled web content with simple markdown syntax. However, besides the basic text formation and style, it has great extensions especially for code contents. This tutorial provide a simple guide to use these extensions. The list of extensions are down below, check details at official document.
extensions

Use without extension would be:

import markdow

content = "**this** would be the `content`"
markdown_content= markdown.markdown(content)

With the extension, it is like:

import markdow

content = "**this** would be the `content`"
markdown_content= markdown.markdown(content, extensions=['extra', 'codehilite'])

codehilite and extra are the most commonly used extensions. In order to make codehilite working, it also needs the Pygments Package. You can install through pip:

$ sudo pip install pygments

pygments also need a css to define its syntax color style, to generate default color theme css:

$ pygmentize -S default -f html -a .codehilite > style.css

then link the css into your HTML pages. If you like to change to other color themes, swap out default for the desired theme. To check list of themes:

$ pygmentize -L style

It is better to define the language of code through markdown sytax for example when using the fenced block. It should starts like: ``` python .
Codehilite extension also has different options including: linenums, guess_lang, css_class, pygments_style, noclasses, use_pygments. Check the chart below for details: codehilite


Powered by Aodabo Copyright © 2021.

Zhiyuan Yang. All rights reserved.

豫ICP备2020036600号