Skip to content

Commit

Permalink
Add sysmetically an id to the headers to be sure to have a defined href.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaudinFlorence committed Nov 7, 2024
1 parent e5d2da6 commit 8e2a89f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,13 @@ def extract_titles_from_notebook_node(nb: NotebookNode):
titles_array = []
html_collection = bs4.BeautifulSoup(cells_html_collection, "html.parser")
headings = html_collection.select("h1, h2, h3, h4, h5, h6")

# Iterate on all headings to get the necessary information on the various titles
for heading in headings:
text = heading.get_text().lstrip().rstrip()
level = int(heading.name[1])
id = text.replace(" ", "-")
href = "#" + id
header_id = text.replace(" ", "-")
heading["id"] = header_id
href = "#" + header_id
titles_array.append([str(heading), level, href])
return titles_array

0 comments on commit 8e2a89f

Please sign in to comment.