Skip to content

Commit

Permalink
Remove condition on headers of level 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaudinFlorence committed Nov 4, 2024
1 parent 5708233 commit 14a3ab8
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
MISTUNE_V3 = False

def import_plugin(name: str) -> "MarkdownPlugin": # type: ignore[misc]
"""Simple implementation of Mistune V3's import_plugin for V2."""
"""Simple implementation of Mistune V3"s import_plugin for V2."""
return PLUGINS[name] # type: ignore[no-any-return]


Expand All @@ -59,7 +59,7 @@ class InvalidNotebook(Exception):


def _dotall(pattern: str) -> str:
"""Makes the '.' special character match any character inside the pattern, including a newline.
"""Makes the "." special character match any character inside the pattern, including a newline.
This is implemented with the inline flag `(?s:...)` and is equivalent to using `re.DOTALL`.
It is useful for LaTeX environments, where line breaks may be present.
Expand All @@ -74,7 +74,7 @@ class MathBlockParser(BlockParser):
order to avoid other block level rules splitting math sections apart.
It works by matching each multiline math environment as a single paragraph,
so that other rules don't think each section is its own paragraph. Inline
so that other rules don"t think each section is its own paragraph. Inline
is ignored here.
"""

Expand Down Expand Up @@ -198,7 +198,7 @@ class MathBlockParser(BlockParser): # type: ignore[no-redef]
re.DOTALL,
)

# Regex for header that doesn't require space after '#'
# Regex for header that doesn"t require space after "#"
AXT_HEADING = re.compile(r" {0,3}(#{1,6})(?!#+)(?: *\n+|([^\n]*?)(?:\n+|\s+?#+\s*\n+))")

# Multiline math must be searched before other rules
Expand Down Expand Up @@ -239,7 +239,7 @@ class MathInlineParser(InlineParser): # type: ignore[no-redef]

def parse_block_math_tex(self, m: Match[str], state: Any) -> Tuple[str, str]:
"""Parse block text math."""
# sometimes the Scanner keeps the final '$$', so we use the
# sometimes the Scanner keeps the final "$$", so we use the
# full matched string and remove the math markers
text = m.group(0)[2:-2]
return "block_math", text
Expand Down Expand Up @@ -432,7 +432,7 @@ def _html_embed_images(self, html: str) -> str:
parsed_html = bs4.BeautifulSoup(html, features="html.parser")
imgs: bs4.ResultSet[bs4.Tag] = parsed_html.find_all("img")

# Replace img tags's sources by base64 dataurls
# Replace img tags"s sources by base64 dataurls
for img in imgs:
src = img.attrs.get("src")
if src is None:
Expand Down Expand Up @@ -516,31 +516,34 @@ def extract_titles_from_notebook_node(nb: NotebookNode):
if cell.cell_type == "markdown":
lines = cell.source.splitlines()
for line in lines:
if line.startswith('#') and line.count('#') != 1: # exclude the main title to build the table of content
markdown_collection = markdown_collection + line.strip() + "\n"
if line.startswith('<h2>'):
if line.startswith("<h1>"):
newline = line.replace("<h1>", "# ")
if line.startswith("<h2>"):
newline = line.replace("<h2>", "# ")
if line.startswith('<h3>'):
if line.startswith("<h3>"):
newline = line.replace("<h3>", "# ")
if line.startswith('<h4>'):
if line.startswith("<h4>"):
newline = line.replace("<h4>", "# ")
if line.startswith('<h5>'):
if line.startswith("<h5>"):
newline = line.replace("<h5>", "# ")
if line.startswith('<h6>'):
if line.startswith("<h6>"):
newline = line.replace("<h6>", "# ")
if '</h2>' in line:
if "</h1>" in line:
newline = line.replace("</h1>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"
if "</h2>" in line:
newline = line.replace("</h2>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"
if '</h3>' in line:
if "</h3>" in line:
newline = line.replace("</h3>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"
if '</h4>' in line:
if "</h4>" in line:
newline = line.replace("</h4>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"
if '</h5>' in line:
if "</h5>" in line:
newline = line.replace("</h5>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"
if '</h6>' in line:
if "</h6>" in line:
newline = line.replace("</h6>", "")
markdown_collection = markdown_collection + newline.strip() + "\n"

Expand All @@ -559,6 +562,6 @@ def extract_titles_from_notebook_node(nb: NotebookNode):
id = raw_text.replace(" ", "-")
href = "#" + id
titles_array.append([header_level, raw_text, id, href])
# print('header_level:', header_level)
# print('raw_text:', raw_text)
# print("header_level:", header_level)
# print("raw_text:", raw_text)
return titles_array

0 comments on commit 14a3ab8

Please sign in to comment.