diff --git a/docs/changelog.md b/docs/changelog.md index c1b8c9264..72563268d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,8 @@ See the [Contributing Guide](contributing.md) for details. ### Fixed +* An empty attribute list written with a colon, such as `{: }`, is left as text + like `{ }`, instead of adding an attribute named `:` (#1734). * Fix a doubled `mailto:` in automatic email links which write the scheme in upper or mixed case, such as `` (#1733). * Fix cubic processing time in the `legacy_attrs` extension for text with many diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py index 060e4761f..fbc58e964 100644 --- a/markdown/extensions/attr_list.py +++ b/markdown/extensions/attr_list.py @@ -113,7 +113,7 @@ def sanitize_name(name: str) -> str: class AttrListTreeprocessor(Treeprocessor): - BASE_RE = r'\{\:?[ ]*([^\}\n ][^\n]*)\}' + BASE_RE = r'\{(?!\:[ ]*\})\:?[ ]*([^\}\n ][^\n]*)\}' HEADER_RE = re.compile(r'[ ]+{}[ ]*$'.format(BASE_RE)) BLOCK_RE = re.compile(r'\n[ ]*{}[ ]*$'.format(BASE_RE)) INLINE_RE = re.compile(r'^{}'.format(BASE_RE)) diff --git a/tests/test_syntax/extensions/test_attr_list.py b/tests/test_syntax/extensions/test_attr_list.py index 73c77969e..7c672d4cb 100644 --- a/tests/test_syntax/extensions/test_attr_list.py +++ b/tests/test_syntax/extensions/test_attr_list.py @@ -301,3 +301,9 @@ def test_key_without_value(self): 'Key without *value*{ foo= }', '

Key without value

' ) + + def test_empty_list_with_colon(self): + self.assertMarkdownRenders( + '# Heading {: }\n\n*text*{:}', + '

Heading {: }

\n

text{:}

' + )