Skip to content

Instantly share code, notes, and snippets.

@airekans
Created April 7, 2013 09:40
Show Gist options
  • Save airekans/5329785 to your computer and use it in GitHub Desktop.
Save airekans/5329785 to your computer and use it in GitHub Desktop.
use python-markdown to generate Gitlab compatible TOC.
import markdown
def inc_header(): data = [0]
def fun(x, *rest):
header = 'toc_%d' % data[0]
data[0] += 1
return header
return fun
if __name__ == '__main__':
fd = open('test.md')
md_text = fd.read()
toc_html = markdown.markdown(md_text, extensions=['toc'],
extension_configs={'toc': [('slugify', inc_header())]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment