The missing files for fix #947. Source hightlighting with Pygments in AsciiDoc.
This commit is contained in:
Matt Jesson 2014-04-28 14:08:17 +01:00
commit 22eed8f81c
3 changed files with 35 additions and 6 deletions

12
pelican/readers.py Normal file → Executable file
View file

@ -370,7 +370,17 @@ class AsciiDocReader(BaseReader):
for o in options: for o in options:
ad.options(*o.split()) ad.options(*o.split())
ad.execute(text, content, backend="html4") # set the backend option for ad.execute() if the backend options has been set in 'ASCIIDOC_OPTIONS'
# (at the time of writing, asciidoc.py seems to have trouble with options of the form: "--setting=value",
# which is why we have to extract and pass the value manually)
backend_values = [m.group(1) for o in options for m in [re.match(r"^--backend=(\w+)$", o), re.match(r"^-b\s+(\w+)$", o)] if m]
try:
backend_option = backend_values[0]
except IndexError:
# default to HTML5
backend_option = "html5"
ad.execute(text, content, backend=backend_option)
content = content.getvalue() content = content.getvalue()
metadata = {} metadata = {}

View file

29
pelican/tests/test_readers.py Normal file → Executable file
View file

@ -331,10 +331,12 @@ class AdReaderTest(ReaderTest):
# Ensure the asc extension is being processed by the correct reader # Ensure the asc extension is being processed by the correct reader
page = self.read_file( page = self.read_file(
path='article_with_asc_extension.asc') path='article_with_asc_extension.asc')
expected = ('<hr>\n<h2><a name="_used_for_pelican_test">' expected = ('<div class="sect1">\n'
'</a>Used for pelican test</h2>\n' '<h2 id="_used_for_pelican_test">Used for pelican test</h2>\n'
'<p>The quick brown fox jumped over' '<div class="sectionbody">\n'
' the lazy dog&#8217;s back.</p>\n') '<div class="paragraph"><p>The quick brown fox jumped over the lazy dog&#8217;s back.</p></div>\n'
'</div>\n'
'</div>\n')
self.assertEqual(page.content, expected) self.assertEqual(page.content, expected)
expected = { expected = {
'category': 'Blog', 'category': 'Blog',
@ -351,7 +353,7 @@ class AdReaderTest(ReaderTest):
def test_article_with_asc_options(self): def test_article_with_asc_options(self):
# test to ensure the ASCIIDOC_OPTIONS is being used # test to ensure the ASCIIDOC_OPTIONS is being used
reader = readers.AsciiDocReader( reader = readers.AsciiDocReader(
dict(ASCIIDOC_OPTIONS=["-a revision=1.0.42"])) dict(ASCIIDOC_OPTIONS=["-a revision=1.0.42", "--backend=html4"]))
content, metadata = reader.read(_path('article_with_asc_options.asc')) content, metadata = reader.read(_path('article_with_asc_options.asc'))
expected = ('<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for' expected = ('<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for'
' pelican test</h2>\n<p>version 1.0.42</p>\n' ' pelican test</h2>\n<p>version 1.0.42</p>\n'
@ -359,6 +361,23 @@ class AdReaderTest(ReaderTest):
' dog&#8217;s back.</p>\n') ' dog&#8217;s back.</p>\n')
self.assertEqual(content, expected) self.assertEqual(content, expected)
@unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")
def test_article_with_pygments_syntax_highlighting(self):
# test to ensure ASCIIDOC is performing syntax highlighting with Pygments
page = self.read_file(
path='article_using_pygments_source_highlighter.asc')
expected = ('<div class="sect1">\n'
'<h2 id="_pelican_pygments_test">Pelican Pygments Test</h2>\n'
'<div class="sectionbody">\n'
'<div class="listingblock">\n'
'<div class="content"><div class="highlight"><pre><span class="c"># Source highlighter test</span>\n'
'<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>\n'
' <span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello world.&quot;</span><span class="p">)</span>\n'
'</pre></div></div></div>\n'
'</div>\n'
'</div>\n')
self.assertEqual(page.content, expected)
class HTMLReaderTest(ReaderTest): class HTMLReaderTest(ReaderTest):
def test_article_with_comments(self): def test_article_with_comments(self):