From 22eed8f81cf1aebce4e438abc2642578fa31678d Mon Sep 17 00:00:00 2001
From: Matt Jesson
Date: Mon, 28 Apr 2014 14:08:17 +0100
Subject: [PATCH] Fix #947
The missing files for fix #947. Source hightlighting with Pygments in AsciiDoc.
---
pelican/readers.py | 12 +++++++-
...icle_using_pygments_source_highlighter.asc | 0
pelican/tests/test_readers.py | 29 +++++++++++++++----
3 files changed, 35 insertions(+), 6 deletions(-)
mode change 100644 => 100755 pelican/readers.py
mode change 100644 => 100755 pelican/tests/content/article_using_pygments_source_highlighter.asc
mode change 100644 => 100755 pelican/tests/test_readers.py
diff --git a/pelican/readers.py b/pelican/readers.py
old mode 100644
new mode 100755
index c63b8981..9ec0c725
--- a/pelican/readers.py
+++ b/pelican/readers.py
@@ -370,7 +370,17 @@ class AsciiDocReader(BaseReader):
for o in options:
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()
metadata = {}
diff --git a/pelican/tests/content/article_using_pygments_source_highlighter.asc b/pelican/tests/content/article_using_pygments_source_highlighter.asc
old mode 100644
new mode 100755
diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py
old mode 100644
new mode 100755
index fd30e9b9..29c50ef1
--- a/pelican/tests/test_readers.py
+++ b/pelican/tests/test_readers.py
@@ -331,10 +331,12 @@ class AdReaderTest(ReaderTest):
# Ensure the asc extension is being processed by the correct reader
page = self.read_file(
path='article_with_asc_extension.asc')
- expected = ('
\n'
- 'Used for pelican test
\n'
- 'The quick brown fox jumped over'
- ' the lazy dog’s back.
\n')
+ expected = ('\n'
+ '
Used for pelican test
\n'
+ '
\n'
+ '
The quick brown fox jumped over the lazy dog’s back.
\n'
+ '
\n'
+ '
\n')
self.assertEqual(page.content, expected)
expected = {
'category': 'Blog',
@@ -351,7 +353,7 @@ class AdReaderTest(ReaderTest):
def test_article_with_asc_options(self):
# test to ensure the ASCIIDOC_OPTIONS is being used
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'))
expected = ('
\nUsed for'
' pelican test
\nversion 1.0.42
\n'
@@ -359,6 +361,23 @@ class AdReaderTest(ReaderTest):
' dog’s back.
\n')
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 = ('\n'
+ '
Pelican Pygments Test
\n'
+ '
\n'
+ '
\n'
+ '
# Source highlighter test\n'
+ 'for i in range(10):\n'
+ ' print("Hello world.")\n'
+ '\n'
+ '
\n'
+ '
\n')
+ self.assertEqual(page.content, expected)
+
class HTMLReaderTest(ReaderTest):
def test_article_with_comments(self):