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 new file mode 100755 index 00000000..b680310c --- /dev/null +++ b/pelican/tests/content/article_using_pygments_source_highlighter.asc @@ -0,0 +1,13 @@ +Test AsciiDoc Syntax Highlight Test +=================================== +:source-highlighter: pygments + +Pelican Pygments Test +--------------------- + +[source,python] +---- +# Source highlighter test +for i in range(10): + print("Hello world.") +---- 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 = ('
\n

Used for' ' pelican test

\n

version 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):