From daa67656a4a9765cb09f76fe0bd0554c71103f58 Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Sun, 31 Jan 2021 21:49:37 +0100 Subject: [PATCH] Add support for tables of contents in articles --- tildewiki/compilation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tildewiki/compilation.py b/tildewiki/compilation.py index 80c668b..53f7ccf 100644 --- a/tildewiki/compilation.py +++ b/tildewiki/compilation.py @@ -5,6 +5,7 @@ from shutil import copy from typing import Optional, Callable from markdown import markdown +from markdown.extensions.toc import TocExtension DOUBLE_NEWLINE_RE = re.compile(r'\n\n', flags=re.MULTILINE|re.DOTALL) HEADER_TITLE_RE = re.compile(r'(.*?)') @@ -189,7 +190,9 @@ def compile_markdown(file_path:str) -> str: """Given a string of markdown, compiles it and returns the result.""" return markdown( slurp(file_path), - output_format='html5') + output_format='html5', + # Allow tables of contents and exclude

tags (page titles) + extensions=[TocExtension(toc_depth='2-6')]) def compile_plaintext(file_path:str) -> str: output = '

\n' -- 2.47.0