From 2d717ceeb2b29ec75a153df9ac33ac9c0b846419 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 27 Mar 2020 19:11:02 -0700 Subject: [PATCH] Fix table of contents lines not having text of formatted headers. If the header was called "Hello *world*" then the toc would only say Hello because the toc generator wasn't getting the text of child elements. This fixes that at the expense of having to cut the paragraph sign back off. --- voussoir.net/writing/vmarkdown.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/voussoir.net/writing/vmarkdown.py b/voussoir.net/writing/vmarkdown.py index 5aa8912..99d1615 100644 --- a/voussoir.net/writing/vmarkdown.py +++ b/voussoir.net/writing/vmarkdown.py @@ -199,6 +199,7 @@ def dump_file(path): # SOUP HELPERS ################################################################################ +PARAGRAPH_SYMBOL = chr(182) def add_header_anchors(soup): ''' Give each an to link to it. @@ -215,8 +216,7 @@ def add_header_anchors(soup): new_a = soup.new_tag('a') new_a['href'] = '#' + slug new_a['class'] = 'header_anchor_link' - paragraph_symbol = chr(182) - new_a.append(f' ({paragraph_symbol})') + new_a.append(f' ({PARAGRAPH_SYMBOL})') header.append(new_a) def add_toc(soup, max_level=None): @@ -261,7 +261,7 @@ def add_toc(soup, max_level=None): toc_line = toc.new_tag('li') toc_a = toc.new_tag('a') - toc_a.append(str(header.find(text=True))) + toc_a.append(get_innertext(header).replace(f' ({PARAGRAPH_SYMBOL})', '')) toc_a['href'] = f'#{header["id"]}' toc_line.append(toc_a)