From 64410fae5e8d29fb4a74b7883b83cbbe4ea02d9f Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 20 Nov 2013 13:29:54 -0500 Subject: [PATCH] Extract FencedBlockPreprocessor.format_quote(). (imported from commit 59db5415d624402b37ade7fe5547b16f58ae565f) --- zerver/lib/bugdown/fenced_code.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/zerver/lib/bugdown/fenced_code.py b/zerver/lib/bugdown/fenced_code.py index 0bd138b35f..13d7e4d873 100644 --- a/zerver/lib/bugdown/fenced_code.py +++ b/zerver/lib/bugdown/fenced_code.py @@ -128,18 +128,23 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor): return code + def format_quote(self, text): + paragraphs = text.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 != '')) + return "\n\n".join(quoted_paragraphs) + def process_fence(self, m, text): langclass = '' if 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) + + replacement = self.format_quote(m.group('code')) + return '%s\n%s\n%s'% (text[:m.start()], replacement, text[m.end():]) code = self.format_code(langclass, m.group('lang'), m.group('code'))