Extract FencedBlockPreprocessor.format_quote().

(imported from commit 59db5415d624402b37ade7fe5547b16f58ae565f)
This commit is contained in:
Steve Howell 2013-11-20 13:29:54 -05:00
parent 9d4b6d0684
commit 64410fae5e
1 changed files with 11 additions and 6 deletions

View File

@ -128,18 +128,23 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
return code 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): def process_fence(self, m, text):
langclass = '' langclass = ''
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'): if m.group('lang') in ('quote', 'quoted'):
paragraphs = m.group('code').split("\n\n")
quoted_paragraphs = [] replacement = self.format_quote(m.group('code'))
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():]) return '%s\n%s\n%s'% (text[:m.start()], replacement, text[m.end():])
code = self.format_code(langclass, m.group('lang'), m.group('code')) code = self.format_code(langclass, m.group('lang'), m.group('code'))