Skip to content
/ mdtree Public

MdTree, Convert markdown into html with TOC(table of contents).

Notifications You must be signed in to change notification settings

menduo/mdtree

Repository files navigation

MdTree

Convert markdown to html with TOC(table of contents) tree. https://github.com/menduo/mdtree

Screenshot

https://github.com/menduo/mdtree

Install

pip install -U mdtree

Usage

In Python

from mdtree import MdTree
with open(path_of_md_file) as f:
    md_str = f.read()

mt = MdTree()
html = mt.convert(md_str)
fpath = mt.save_file("/tmp/mdtree.html")

mt = MdTree()
html = mt.convert_file("/tmp/gitit_bigger_readme.md")

In Shell

mdtree /path/of/markdown/file.md > /tmp/mdtree.html

Options

  • to64 : convert local image URL to base64. add --to64 to shell argument or add to64 option to meta area.

Meta

mdtree allows you to add more things to the html file:

  • css
  • js
  • title
---
title: 这是一个标题
js:
    https://raw.githubusercontent.com/menduo/mdtree/master/static/js/mdtree.min.js
    https://raw.githubusercontent.com/menduo/mdtree/master/static/js/mdtree2.min.js
css:
    https://raw.githubusercontent.com/menduo/mdtree/master/static/css/mdtree.min.css
    https://raw.githubusercontent.com/menduo/mdtree/master/static/css/mdtree2.min.css
---

Markdown Extensions

By default, these extensions were enabled. You can add more extensions or disable them.

_md_extensions = [
    "markdown.extensions.meta",
    "markdown.extensions.headerid",
    "markdown.extensions.tables",
    "markdown.extensions.toc",
    "markdown.extensions.fenced_code",
    "markdown.extensions.codehilite",
]

You can customize them in the meta section:

---
title: 这是一个标题
js:
    https://raw.githubusercontent.com/menduo/mdtree/master/static/js/mdtree.min.js
css:
    https://raw.githubusercontent.com/menduo/mdtree/master/static/css/mdtree.min.css
exts:
    markdown.extensions.wikilinks
    -markdown.extensions.codehilite
---

As you know, markdown.extensions.wikilinks will be added, and -markdown.extensions.codehilite which starts with - will be removed.

The name of the extensioins should be the same as https://pythonhosted.org/Markdown/extensions/#officially-supported-extensions

Credits

  • Markdown - A Python implementation of John Gruber’s Markdown