@@ -41,7 +41,7 @@ def extendMarkdown(self, md):
41
41
class AbbrPreprocessor (BlockProcessor ):
42
42
""" Abbreviation Preprocessor - parse text for abbr references. """
43
43
44
- RE = re .compile (r'^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$' , re .MULTILINE )
44
+ RE = re .compile (r'^[*]\[(?P<abbr>[^\]\^\\ ]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$' , re .MULTILINE )
45
45
46
46
def test (self , parent : etree .Element , block : str ) -> bool :
47
47
return True
@@ -73,18 +73,15 @@ def run(self, parent: etree.Element, blocks: list[str]) -> bool:
73
73
74
74
def _generate_pattern (self , text : str ) -> str :
75
75
"""
76
- Given a string, returns an regex pattern to match that string.
76
+ Given a string, returns a regex pattern to match that string.
77
77
78
- 'HTML' -> r'(?P<abbr>[H][T][M][L])'
78
+ 'HTML' -> r'(?P<abbr>\b [H][T][M][L]\b )'
79
79
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.
82
82
83
83
"""
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)"
88
85
89
86
90
87
class AbbrInlineProcessor (InlineProcessor ):
0 commit comments