Skip to content

Commit

Permalink
Fix monkeypatch of nbconvert.filters.markdown_mistune.IPythonRenderer (
Browse files Browse the repository at this point in the history
  • Loading branch information
metab0t committed Mar 21, 2023
1 parent ba7b86a commit f3b5175
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mkdocs_jupyter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# ------------------------------------------------------------------------------
# This makes the links from the TOC work
# We monkeypatch nbconvert.filters.markdown_mistune.IPythonRenderer.header
# We monkeypatch nbconvert.filters.markdown_mistune.IPythonRenderer.heading
# to use a version that makes the id all lowercase
# We do this because mkdocs uses all lowercase TOC titles
# (to make them url-friendly)
Expand Down Expand Up @@ -38,13 +38,12 @@ def add_anchor_lower_id(html, anchor_link_text="¶"):
return ElementTree.tostring(h).decode("utf-8", "replace")


def new_header(self, text, level, raw=None):
html = super(IPythonRenderer, self).header(text, level, raw=raw)
anchor_link_text = self.options.get("anchor_link_text", "¶")
return add_anchor_lower_id(html, anchor_link_text=anchor_link_text)
def new_heading(self, text, level):
html = super(IPythonRenderer, self).heading(text, level)
return add_anchor_lower_id(html, anchor_link_text=self.anchor_link_text)


IPythonRenderer.header = new_header
IPythonRenderer.heading = new_heading

# End monkeypatch --------------------------------------------------------------

Expand Down

0 comments on commit f3b5175

Please sign in to comment.