@@ -41,7 +41,7 @@ def extendMarkdown(self, md):
4141class AbbrPreprocessor (BlockProcessor ):
4242 """ Abbreviation Preprocessor - parse text for abbr references. """
4343
44- RE = re .compile (r'^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$' , re .MULTILINE )
44+ RE = re .compile (r'^[*]\[(?P<abbr>[^\]\^\\ ]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$' , re .MULTILINE )
4545
4646 def test (self , parent : etree .Element , block : str ) -> bool :
4747 return True
@@ -73,18 +73,15 @@ def run(self, parent: etree.Element, blocks: list[str]) -> bool:
7373
7474 def _generate_pattern (self , text : str ) -> str :
7575 """
76- Given a string, returns an regex pattern to match that string.
76+ Given a string, returns a regex pattern to match that string.
7777
78- 'HTML' -> r'(?P<abbr>[H][T][M][L])'
78+ 'HTML' -> r'(?P<abbr>\b [H][T][M][L]\b )'
7979
80- Note: we force each char as a literal match (in brackets) as we don't
81- know what they will be beforehand.
80+ Note: we force each char as a literal match via a character set (in brackets)
81+ as we don't know what they will be beforehand.
8282
8383 """
84- chars = list (text )
85- for i in range (len (chars )):
86- chars [i ] = r'[%s]' % chars [i ]
87- return r'(?P<abbr>\b%s\b)' % (r'' .join (chars ))
84+ return f"(?P<abbr>\\ b{ '' .join (f'[{ c } ]' for c in text ) } \\ b)"
8885
8986
9087class AbbrInlineProcessor (InlineProcessor ):
0 commit comments