@@ -35,7 +35,7 @@ class PyconDetectorExtension(markdown.Extension):
3535 def extendMarkdown (self , md : markdown .Markdown ) -> None :
3636 """Add the preprocessor to the markdown instance."""
3737 processor = PyconDetectorPreprocessor (md )
38- md .preprocessors .register (processor , "pycon_detector" , 175 )
38+ md .preprocessors .register (processor , "pycon_detector" , 30 )
3939
4040
4141class PyconDetectorPreprocessor (markdown .preprocessors .Preprocessor ):
@@ -53,12 +53,9 @@ class PyconDetectorPreprocessor(markdown.preprocessors.Preprocessor):
5353
5454 def __init__ (self , md : markdown .Markdown ) -> None :
5555 super ().__init__ (md )
56- # Pattern to match fenced code blocks (backreference \2 ensures the
57- # closing fence matches the opening fence marker, preventing greedy
58- # over-consumption of adjacent fenced blocks)
56+ # Pattern to match fenced code blocks
5957 self .fence_pattern = re .compile (
60- r"^(\s*)(```+|~~~+)(\w*)\s*\n(.*?)^\s*\2\s*$" ,
61- re .MULTILINE | re .DOTALL ,
58+ r"^(\s*)```(\w*)\s*\n(.*?)^(\s*)```\s*$" , re .MULTILINE | re .DOTALL
6259 )
6360
6461 def run (self , lines : list [str ]) -> list [str ]:
@@ -67,14 +64,14 @@ def run(self, lines: list[str]) -> list[str]:
6764
6865 def replace_fence (match : re .Match [str ]) -> str :
6966 indent = match .group (1 )
70- fence = match .group (2 )
71- language = match .group (3 ) or ""
72- code = match .group (4 )
67+ language = match .group (2 ) or ""
68+ code = match .group (3 )
7369
7470 # Only process if no language is specified
75- if not language and self ._detect_pycon (code ):
76- # Replace with pycon language
77- return f"{ indent } { fence } pycon\n { code } { indent } { fence } "
71+ if not language :
72+ if self ._detect_pycon (code ):
73+ # Replace with pycon language
74+ return f"{ indent } ```pycon\n { code } { indent } ```"
7875
7976 # Return original
8077 return match .group (0 )
@@ -253,10 +250,7 @@ def __init__(
253250 text ,
254251 extensions = _get_extensions (),
255252 extension_configs = _get_extension_configs (),
256- )
257- if html_text is None :
258- html_text = ""
259- html_text = html_text .strip ()
253+ ).strip ()
260254 # replace <p> tags with <span> as HTML doesn't allow nested <div>s in <p>s
261255 html_text = html_text .replace (
262256 "<p>" , '<span class="paragraph">'
0 commit comments