From f9d2b3fb56cad884a9b29b4903cfe4a4f1685204 Mon Sep 17 00:00:00 2001 From: ryanvilbrandt Date: Mon, 25 Nov 2019 13:16:27 -0800 Subject: [PATCH 01/11] Added support for TOCs that don't start with h1 headers --- lib/markdown2.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index 3a5d5d9b..9a646ce0 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -2293,13 +2293,19 @@ def calculate_toc_html(toc): This expects the `_toc` attribute to have been set on this instance. """ - if toc is None: + if not toc: return None def indent(): return ' ' * (len(h_stack) - 1) lines = [] h_stack = [0] # stack of header-level numbers + # Check first item in list, and start building our table early if we don't start with an

+ first_header_level = toc[0][0] + for i in range(1, first_header_level): + lines.append("%s