mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
bugdown: Allow block-level block quotes
It is triggered by specifying the "language" of a code block to
"quote" or "quoted":
Hamlet said:
~~~ quote
To be or **not** to be.
That is the question
~~~
(imported from commit 847a0602e335e9f2955e32d9955adf8ac8de068c)
This commit is contained in:
@@ -107,6 +107,15 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
|
|||||||
if m.group('lang'):
|
if m.group('lang'):
|
||||||
langclass = LANG_TAG % m.group('lang')
|
langclass = LANG_TAG % m.group('lang')
|
||||||
|
|
||||||
|
if m.group('lang') in ('quote', 'quoted'):
|
||||||
|
paragraphs = m.group('code').split("\n\n")
|
||||||
|
quoted_paragraphs = []
|
||||||
|
for paragraph in paragraphs:
|
||||||
|
lines = paragraph.split("\n")
|
||||||
|
quoted_paragraphs.append("\n".join("> " + line for line in lines if line != ''))
|
||||||
|
replacement = "\n\n".join(quoted_paragraphs)
|
||||||
|
return '%s\n%s\n%s'% (text[:m.start()], replacement, text[m.end():])
|
||||||
|
|
||||||
# If config is not empty, then the codehighlite extension
|
# If config is not empty, then the codehighlite extension
|
||||||
# is enabled, so we call it to highlite the code
|
# is enabled, so we call it to highlite the code
|
||||||
if self.codehilite_conf:
|
if self.codehilite_conf:
|
||||||
|
|||||||
@@ -2329,6 +2329,49 @@ def foobar(self):
|
|||||||
</pre></div>"""
|
</pre></div>"""
|
||||||
self.common_bugdown_test(fenced_code, expected_convert)
|
self.common_bugdown_test(fenced_code, expected_convert)
|
||||||
|
|
||||||
|
def test_fenced_quote(self):
|
||||||
|
fenced_quote = \
|
||||||
|
"""Hamlet said:
|
||||||
|
~~~ quote
|
||||||
|
To be or **not** to be.
|
||||||
|
|
||||||
|
That is the question
|
||||||
|
~~~"""
|
||||||
|
|
||||||
|
expected_convert = \
|
||||||
|
"""<p>Hamlet said:</p>
|
||||||
|
<blockquote>
|
||||||
|
<p>To be or <strong>not</strong> to be.</p>
|
||||||
|
<p>That is the question</p>
|
||||||
|
</blockquote>"""
|
||||||
|
self.common_bugdown_test(fenced_quote, expected_convert)
|
||||||
|
|
||||||
|
def test_fenced_nested_quote(self):
|
||||||
|
fenced_quote = \
|
||||||
|
"""Hamlet said:
|
||||||
|
~~~ quote
|
||||||
|
Polonius said:
|
||||||
|
> This above all: to thine ownself be true,
|
||||||
|
And it must follow, as the night the day,
|
||||||
|
Thou canst not then be false to any man.
|
||||||
|
|
||||||
|
What good advice!
|
||||||
|
~~~"""
|
||||||
|
|
||||||
|
expected_convert = \
|
||||||
|
"""<p>Hamlet said:</p>
|
||||||
|
<blockquote>
|
||||||
|
<p>Polonius said:</p>
|
||||||
|
<blockquote>
|
||||||
|
<p>This above all: to thine ownself be true,<br>
|
||||||
|
And it must follow, as the night the day,<br>
|
||||||
|
Thou canst not then be false to any man.</p>
|
||||||
|
</blockquote>
|
||||||
|
<p>What good advice!</p>
|
||||||
|
</blockquote>"""
|
||||||
|
|
||||||
|
self.common_bugdown_test(fenced_quote, expected_convert)
|
||||||
|
|
||||||
def test_dangerous_block(self):
|
def test_dangerous_block(self):
|
||||||
fenced_code = u'xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\n```\
|
fenced_code = u'xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\n```\
|
||||||
"xxxx xxxx\\xxxxx\\xxxxxx"```\n\nxxx xxxx xxxxx:```xx.xxxxxxx(x\'^xxxx$\'\
|
"xxxx xxxx\\xxxxx\\xxxxxx"```\n\nxxx xxxx xxxxx:```xx.xxxxxxx(x\'^xxxx$\'\
|
||||||
|
|||||||
Reference in New Issue
Block a user