Repository: getpelican/pelican

Issue:
Split asciidoc into a plugin
I don't think it belongs in the core since it depends on non-python dependencies and it's not often used. This is exactly what plugins are for.



Discussion:
I agree.

PS: I'm willing to work on this, if it's decided.

I believe we have consensus on this topic.

@avaris: Please feel free to get started. Thank you for volunteering to help out with this!

I'll submit a PR that removes AsciiDocReader from core soon, but how shall we deal with AsciiDoc in the documentation? Remove it completely or leave a single note (probably in `Installing Pelican/Optional Packages` section) pointing to plugins repo?


Resolving patch:
diff --git a/pelican/readers.py b/pelican/readers.py
--- a/pelican/readers.py
+++ b/pelican/readers.py
@@ -17,11 +17,6 @@
     from markdown import Markdown
 except ImportError:
     Markdown = False  # NOQA
-try:
-    from asciidocapi import AsciiDocAPI
-    asciidoc = True
-except ImportError:
-    asciidoc = False
 try:
     from html import escape
 except ImportError:
@@ -349,40 +344,6 @@ def read(self, filename):
         return parser.body, metadata
 
 
-class AsciiDocReader(BaseReader):
-    """Reader for AsciiDoc files"""
-
-    enabled = bool(asciidoc)
-    file_extensions = ['asc', 'adoc', 'asciidoc']
-    default_options = ["--no-header-footer", "-a newline=\\n"]
-
-    def read(self, source_path):
-        """Parse content and metadata of asciidoc files"""
-        from cStringIO import StringIO
-        with pelican_open(source_path) as source:
-            text = StringIO(source)
-        content = StringIO()
-        ad = AsciiDocAPI()
-
-        options = self.settings['ASCIIDOC_OPTIONS']
-        if isinstance(options, (str, unicode)):
-            options = [m.strip() for m in options.split(',')]
-        options = self.default_options + options
-        for o in options:
-            ad.options(*o.split())
-
-        ad.execute(text, content, backend="html4")
-        content = content.getvalue()
-
-        metadata = {}
-        for name, value in ad.asciidoc.document.attributes.items():
-            name = name.lower()
-            metadata[name] = self.process_metadata(name, value)
-        if 'doctitle' in metadata:
-            metadata['title'] = metadata['doctitle']
-        return content, metadata
-
-
 class Readers(FileStampDataCacher):
     """Interface for all readers.
 
diff --git a/pelican/settings.py b/pelican/settings.py
--- a/pelican/settings.py
+++ b/pelican/settings.py
@@ -98,7 +98,6 @@
     'PELICAN_CLASS': 'pelican.Pelican',
     'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
     'DATE_FORMATS': {},
-    'ASCIIDOC_OPTIONS': [],
     'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'],
     'JINJA_EXTENSIONS': [],
     'JINJA_FILTERS': {},


Test patch:
diff --git a/pelican/tests/content/article_with_asc_extension.asc b/pelican/tests/content/article_with_asc_extension.asc
deleted file mode 100644
--- a/pelican/tests/content/article_with_asc_extension.asc
+++ /dev/null
@@ -1,12 +0,0 @@
-Test AsciiDoc File Header
-=========================
-:Author: Author O. Article
-:Email: <author@nowhere.com>
-:Date: 2011-09-15 09:05
-:Category: Blog
-:Tags: Linux, Python, Pelican
-
-Used for pelican test
----------------------
-
-The quick brown fox jumped over the lazy dog's back.
diff --git a/pelican/tests/content/article_with_asc_options.asc b/pelican/tests/content/article_with_asc_options.asc
deleted file mode 100644
--- a/pelican/tests/content/article_with_asc_options.asc
+++ /dev/null
@@ -1,9 +0,0 @@
-Test AsciiDoc File Header
-=========================
-
-Used for pelican test
----------------------
-
-version {revision}
-
-The quick brown fox jumped over the lazy dog's back.
diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py
--- a/pelican/tests/test_readers.py
+++ b/pelican/tests/test_readers.py
@@ -333,42 +333,6 @@ def test_article_with_filename_metadata(self):
             self.assertEqual(value, page.metadata[key], key)
 
 
-class AdReaderTest(ReaderTest):
-
-    @unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")
-    def test_article_with_asc_extension(self):
-        # Ensure the asc extension is being processed by the correct reader
-        page = self.read_file(
-            path='article_with_asc_extension.asc')
-        expected = ('<hr>\n<h2><a name="_used_for_pelican_test">'
-                    '</a>Used for pelican test</h2>\n'
-                    '<p>The quick brown fox jumped over'
-                    ' the lazy dog&#8217;s back.</p>\n')
-        self.assertEqual(page.content, expected)
-        expected = {
-            'category': 'Blog',
-            'author': 'Author O. Article',
-            'title': 'Test AsciiDoc File Header',
-            'date': datetime.datetime(2011, 9, 15, 9, 5),
-            'tags': ['Linux', 'Python', 'Pelican'],
-        }
-
-        for key, value in expected.items():
-            self.assertEqual(value, page.metadata[key], key)
-
-    @unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")
-    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"]))
-        content, metadata = reader.read(_path('article_with_asc_options.asc'))
-        expected = ('<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for'
-                    ' pelican test</h2>\n<p>version 1.0.42</p>\n'
-                    '<p>The quick brown fox jumped over the lazy'
-                    ' dog&#8217;s back.</p>\n')
-        self.assertEqual(content, expected)
-
-
 class HTMLReaderTest(ReaderTest):
     def test_article_with_comments(self):
         page = self.read_file(path='article_with_comments.html')