From 114f5b6fc7673ea8ac68d9841b6bb16e6dfbd044 Mon Sep 17 00:00:00 2001 From: Chouaieb Nemri Date: Tue, 31 Dec 2024 23:04:58 +0100 Subject: [PATCH] =?UTF-8?q?#=20Pull=20Request:=20Fix=20=E2=80=9CAXT=20Head?= =?UTF-8?q?ing=E2=80=9D=20Typos=20to=20=E2=80=9CATX=20Heading=E2=80=9D=20i?= =?UTF-8?q?n=20Markdown=20Filters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Overview ### What’s wrong In the markdown filtering code for **nbconvert**, the standard Markdown headings (commonly referred to as “ATX headings”) were mistakenly spelled as **“AXT.”** This can lead to confusion and errors such as: ``` AttributeError: 'MathBlockParser' object has no attribute 'parse_axt_heading' ``` if something tries to call a method by the wrong name. ### Why it matters - Markdown headings of the form `# Heading` are typically referred to as **ATX headings**. - Maintaining consistent naming is helpful for contributors and future maintainers; it also aligns with official Mistune 2.x/3.x naming conventions. --- ## Proposed Changes ### Rename All Instances of “AXT” to “ATX” In the `MathBlockParser` for Mistune ≥ 3.0, rename: ```diff - AXT_HEADING_WITHOUT_LEADING_SPACES + ATX_HEADING_WITHOUT_LEADING_SPACES ``` ```diff - "axt_heading": AXT_HEADING_WITHOUT_LEADING_SPACES + "atx_heading": ATX_HEADING_WITHOUT_LEADING_SPACES ``` Also, change any internal references accordingly (for example, if there were a `parse_axt_heading` method, rename it to `parse_atx_heading`). --- ### Ensure Backward Compatibility - The change is purely a naming fix, so it should not break existing code or templates, as long as the references within **nbconvert** are updated consistently. - If any external plugins or code rely on the old `axt_heading` name, they might need a minor update, but that’s highly unlikely unless they were already overriding **nbconvert**’s internal parser. ``` --- nbconvert/filters/markdown_mistune.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 02ab346e0..63d6b7a34 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -75,8 +75,8 @@ class MathBlockParser(BlockParser): is ignored here. """ - AXT_HEADING_WITHOUT_LEADING_SPACES = ( - r"^ {0,3}(?P#{1,6})(?!#+)(?P[ \t]*(.*?)?)$" + ATX_HEADING_WITHOUT_LEADING_SPACES = ( + r"^ {0,3}(?P#{1,6})(?!#+)(?P[ \t]*(.*?)?)$" ) MULTILINE_MATH = _dotall( @@ -92,7 +92,7 @@ class MathBlockParser(BlockParser): SPECIFICATION = { **BlockParser.SPECIFICATION, - "axt_heading": AXT_HEADING_WITHOUT_LEADING_SPACES, + "atx_heading": ATX_HEADING_WITHOUT_LEADING_SPACES, "multiline_math": MULTILINE_MATH, } @@ -196,7 +196,7 @@ class MathBlockParser(BlockParser): # type: ignore[no-redef] ) # Regex for header that doesn't require space after '#' - AXT_HEADING = re.compile(r" {0,3}(#{1,6})(?!#+)(?: *\n+|([^\n]*?)(?:\n+|\s+?#+\s*\n+))") + ATX_HEADING = re.compile(r" {0,3}(#{1,6})(?!#+)(?: *\n+|([^\n]*?)(?:\n+|\s+?#+\s*\n+))") # Multiline math must be searched before other rules RULE_NAMES = ("multiline_math", *BlockParser.RULE_NAMES) # type: ignore[attr-defined]