Fix code block auto-closing.

Trac #1162

The process_fence method replaces code blocks with placeholders, so
indexes stored before the replacement are incorrect. However, because
the closed code blocks have been replaced, we can simply search the
whole string for any remaining opening code block markers.

(imported from commit 6a9e6924840f8f3ca5175da7c52a905e27c1fabd)
This commit is contained in:
Kevin Mehall
2013-10-15 15:14:51 -04:00
parent b134c90b6b
commit 71decdbe7a
2 changed files with 3 additions and 3 deletions

View File

@@ -147,17 +147,15 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
self.checked_for_codehilite = True
text = "\n".join(lines)
end = 0
while 1:
m = FENCED_BLOCK_RE.search(text)
if m:
end = m.end()
text = self.process_fence(m, text)
else:
break
fence = FENCE_RE.search(text, end)
fence = FENCE_RE.search(text)
if fence:
# If we found a starting fence but no ending fence,
# then we add a closing fence before the two newlines that

View File

@@ -2747,6 +2747,7 @@ u"""<div class="codehilite"><pre>fenced code
~~~~
def speak(self):
x = 1
# Comment to make this code block longer to test Trac #1162
~~~~
Then he mentioned ````y = 4 + x**2```` and
@@ -2758,6 +2759,7 @@ def foobar(self):
"""<p>Hamlet said:</p>
<div class="codehilite"><pre>def speak(self):
x = 1
# Comment to make this code block longer to test Trac #1162
</pre></div>