diff --git a/markdown/extensions/headeranchor.py b/markdown/extensions/headeranchor.py index 6c15111c..a17c75dc 100644 --- a/markdown/extensions/headeranchor.py +++ b/markdown/extensions/headeranchor.py @@ -40,13 +40,10 @@ def run(self, root): id = stashedHTML2text(''.join(itertext(tag)), self.md) id = unique(slugify(id, self.config.get('sep')), used_ids) tag.set('id', id) - text = self.markdown.htmlStash.store( + tag.text = self.markdown.htmlStash.store( LINK % {"id": id}, safe=True - ) - if tag.text is not None: - text + tag.text - tag.text = text + ) + tag.text if tag.text is not None else '' return root