This commit is contained in:
Barakat Soror 2015-08-19 05:14:12 +00:00
commit fc9da0177f
4 changed files with 47 additions and 1 deletions

View file

@ -249,6 +249,7 @@ class MarkdownReader(BaseReader):
if 'meta' not in self.extensions:
self.extensions.append('meta')
self._source_path = None
self.output_format = self.settings['MD_OUTPUT_FORMAT']
def _parse_metadata(self, meta):
"""Return the dict containing document metadata"""
@ -282,7 +283,9 @@ class MarkdownReader(BaseReader):
"""Parse content and metadata of markdown files"""
self._source_path = source_path
self._md = Markdown(extensions=self.extensions)
self._md = Markdown(
extensions=self.extensions,
output_format=self.output_format)
with pelican_open(source_path) as text:
content = self._md.convert(text)

View file

@ -100,6 +100,7 @@ DEFAULT_CONFIG = {
'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
'DATE_FORMATS': {},
'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'],
'MD_OUTPUT_FORMAT' : 'xhtml1',
'JINJA_EXTENSIONS': [],
'JINJA_FILTERS': {},
'LOG_FILTER': [],

View file

@ -0,0 +1,5 @@
Title: Article output format
Some text[^footnote]
[^footnote]: Some footnote

View file

@ -500,6 +500,43 @@ class MdReaderTest(ReaderTest):
}
self.assertDictHasSubset(page.metadata, expected)
def test_article_with_different_output_format(self):
reader = readers.MarkdownReader(settings=get_settings())
# test the default xhtml1 output format
expected = ('<p>Some text<sup id="fnref:footnote"><a class="footnote-re'
'f" href="#fn:footnote" rel="footnote">1</a></sup></p>\n'
'<div class="footnote">\n'
'<hr />\n'
'<ol>\n'
'<li id="fn:footnote">\n'
'<p>Some footnote&#160;<a class="footnote-backref" href="#fn'
'ref:footnote" rev="footnote" title="Jump back to footnote 1'
' in the text">&#8617;</a></p>\n'
'</li>\n'
'</ol>\n'
'</div>')
content, metadata = reader.read(
_path('article_with_different_output_format.md'))
self.assertEqual(content, expected)
# test html5 output format
reader = readers.MarkdownReader(
settings=dict(get_settings(), MD_OUTPUT_FORMAT='html5'))
expected = ('<p>Some text<sup id="fnref-footnote"><a class="footnote-re'
'f" href="#fn-footnote">1</a></sup></p>\n'
'<div class="footnote">\n'
'<hr>\n'
'<ol>\n'
'<li id="fn-footnote">\n'
'<p>Some footnote&#160;<a class="footnote-backref" href="#fn'
'ref-footnote" title="Jump back to footnote 1 in the text">'
'&#8617;</a></p>\n'
'</li>\n'
'</ol>\n'
'</div>')
content, metadata = reader.read(
_path('article_with_different_output_format.md'))
self.assertEqual(content, expected)
class HTMLReaderTest(ReaderTest):
def test_article_with_comments(self):