diff options
| author | Charles de Beauchesne <charles.de.beauchesne@gmail.com> | 2021-07-27 22:14:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-27 16:14:58 -0400 |
| commit | 4b20c168bc4afa0a3775080d803e38694fac17b3 (patch) | |
| tree | 3ac23f815fe29aa4d3db96478c28d7d3ddab0817 /markdown/extensions | |
| parent | 6f024f5be53d348b17a5da2c3e9c32c37013efd7 (diff) | |
| download | python-markdown-4b20c168bc4afa0a3775080d803e38694fac17b3.tar.gz | |
Better toc detection
Fixes #1160.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/toc.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 965ba4a..e4dc378 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -195,7 +195,12 @@ class TocTreeprocessor(Treeprocessor): # To keep the output from screwing up the # validation by putting a <div> inside of a <p> # we actually replace the <p> in its entirety. - if c.text and c.text.strip() == self.marker: + + # The <p> element may contain more than a single text content + # (nl2br can introduce a <br>). In this situation, c.text returns + # the very first content, ignore children contents or tail content. + # len(c) == 0 is here to ensure there is only text in the <p>. + if c.text and c.text.strip() == self.marker and len(c) == 0: for i in range(len(p)): if p[i] == c: p[i] = elem |
