summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfacelessuser <faceless.shop@gmail.com>2017-10-07 08:30:55 -0600
committerfacelessuser <faceless.shop@gmail.com>2017-10-07 08:30:55 -0600
commitcfe3376bb1c76688b3ea63698f90052f41639a7b (patch)
tree56d3e8041ef45613cf762e94425e8ba5b592ee35
parent9b43efbca60057eb3400f5d32f287f8e340fbcd8 (diff)
downloadpython-markdown-cfe3376bb1c76688b3ea63698f90052f41639a7b.tar.gz
Prevent raw HTML parsing issue in abbr and footnotes
Peserve abbreviation line when stripping and preserve a line for each footnote block. Footnotes should also accumulate the extraneous padding.
-rw-r--r--markdown/extensions/abbr.py3
-rw-r--r--markdown/extensions/footnotes.py12
-rw-r--r--markdown/preprocessors.py3
-rw-r--r--tests/extensions/extra/raw-html.html37
-rw-r--r--tests/extensions/extra/raw-html.txt43
5 files changed, 93 insertions, 5 deletions
diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py
index 353d126..fc858b6 100644
--- a/markdown/extensions/abbr.py
+++ b/markdown/extensions/abbr.py
@@ -53,6 +53,9 @@ class AbbrPreprocessor(Preprocessor):
title = m.group('title').strip()
self.markdown.inlinePatterns['abbr-%s' % abbr] = \
AbbrPattern(self._generate_pattern(abbr), title)
+ # Preserve the line to prevent raw HTML indexing issue.
+ # https://github.com/Python-Markdown/markdown/issues/584
+ new_text.append('')
else:
new_text.append(line)
return new_text
diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py
index 8bd8595..580dfa0 100644
--- a/markdown/extensions/footnotes.py
+++ b/markdown/extensions/footnotes.py
@@ -233,7 +233,12 @@ class FootnotePreprocessor(Preprocessor):
fn, _i = self.detectTabbed(lines[i+1:])
fn.insert(0, m.group(2))
i += _i-1 # skip past footnote
- self.footnotes.setFootnote(m.group(1), "\n".join(fn))
+ footnote = "\n".join(fn)
+ self.footnotes.setFootnote(m.group(1), footnote)
+ # Preserve a line for each block to prevent raw HTML indexing issue.
+ # https://github.com/Python-Markdown/markdown/issues/584
+ num_blocks = (len(footnote.split('\n\n')) * 2)
+ newlines.extend([''] * (num_blocks))
else:
newlines.append(lines[i])
if len(lines) > i+1:
@@ -285,6 +290,11 @@ class FootnotePreprocessor(Preprocessor):
if lines[j].strip():
next_line = lines[j]
break
+ else:
+ # Include extreaneous padding to prevent raw HTML
+ # parsing issue: https://github.com/Python-Markdown/markdown/issues/584
+ items.append("")
+ i += 1
else:
break # There is no more text; we are done.
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index 810b4c8..1e99afa 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -346,8 +346,7 @@ class ReferencePreprocessor(Preprocessor):
lines.pop(0)
t = tm.group(2) or tm.group(3) or tm.group(4)
self.markdown.references[id] = (link, t)
- # Preserve the line which the reference was on
- # to prevent raw HTML indexing issue.
+ # Preserve the line to prevent raw HTML indexing issue.
# https://github.com/Python-Markdown/markdown/issues/584
new_text.append('')
else:
diff --git a/tests/extensions/extra/raw-html.html b/tests/extensions/extra/raw-html.html
index 78ea203..158e923 100644
--- a/tests/extensions/extra/raw-html.html
+++ b/tests/extensions/extra/raw-html.html
@@ -49,6 +49,41 @@ Raw html blocks may also be nested.
</div>
<div name="issue584">
<div>
-<p><strong>bold</strong></p>
+<p><a href="http://example.com">link</a></p>
</div>
+</div>
+<div name="issue584">
+<div>
+<p><abbr title="Abbreviation">abbr</abbr></p>
+</div>
+</div>
+<div name="issue584">
+<div>
+<p>footnote<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup></p>
+</div>
+</div>
+<div class="footnote">
+<hr />
+<ol>
+<li id="fn:1">
+<ol>
+<li>
+<p>The top couple half figure, contrary sides and hands across with bottom couple,</p>
+<p>Half figure back on your own sides, and turn partner to places,</p>
+<p>Swing partners with right hands into straight line long-ways, as in a reel, and</p>
+<p>Set,</p>
+<p>Hey and return to places,</p>
+<p>The other three couples do the same.</p>
+</li>
+<li>
+<p>Top and bottom couples meet and set,</p>
+<p>Then each gentleman leas the opposite lady to the couple on his left, and set,</p>
+<p>Aach four right and left,</p>
+<p>Swing side couples to places, and turn partners all eight,</p>
+<p>The other two couple o the same.</p>
+</li>
+</ol>
+<p><a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
+</li>
+</ol>
</div> \ No newline at end of file
diff --git a/tests/extensions/extra/raw-html.txt b/tests/extensions/extra/raw-html.txt
index 882a401..7b560a5 100644
--- a/tests/extensions/extra/raw-html.txt
+++ b/tests/extensions/extra/raw-html.txt
@@ -77,7 +77,48 @@ foo bar
[link]: http://example.com
<div markdown="1">
-**bold**
+[link][link]
+</div>
+
+</div>
+
+<div markdown="1" name="issue584">
+
+*[abbr]: Abbreviation
+
+<div markdown="1">
+abbr
+</div>
+
+</div>
+
+<div markdown="1" name="issue584">
+
+[^1]:
+ 1. The top couple half figure, contrary sides and hands across with bottom couple,
+
+ Half figure back on your own sides, and turn partner to places,
+
+ Swing partners with right hands into straight line long-ways, as in a reel, and
+
+ Set,
+
+ Hey and return to places,
+
+ The other three couples do the same.
+
+ 2. Top and bottom couples meet and set,
+
+ Then each gentleman leas the opposite lady to the couple on his left, and set,
+
+ Aach four right and left,
+
+ Swing side couples to places, and turn partners all eight,
+
+ The other two couple o the same.
+
+<div markdown="1">
+footnote[^1]
</div>
</div>