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.
This commit is contained in:
Ethan Dalool 2020-03-27 19:11:02 -07:00
parent ccd9d88ed2
commit 2d717ceeb2

View file

@ -199,6 +199,7 @@ def dump_file(path):
# SOUP HELPERS # SOUP HELPERS
################################################################################ ################################################################################
PARAGRAPH_SYMBOL = chr(182)
def add_header_anchors(soup): def add_header_anchors(soup):
''' '''
Give each <hX> an <a> to link to it. Give each <hX> an <a> to link to it.
@ -215,8 +216,7 @@ def add_header_anchors(soup):
new_a = soup.new_tag('a') new_a = soup.new_tag('a')
new_a['href'] = '#' + slug new_a['href'] = '#' + slug
new_a['class'] = 'header_anchor_link' 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) header.append(new_a)
def add_toc(soup, max_level=None): 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_line = toc.new_tag('li')
toc_a = toc.new_tag('a') 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_a['href'] = f'#{header["id"]}'
toc_line.append(toc_a) toc_line.append(toc_a)