mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user