mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add asciidoc reader support
http://www.methods.co.nz/asciidoc/index.html Processes files ending in .asc with asciidoc. Extra arguments can be passed by using the ASCIIDOC_OPTIONS config setting
This commit is contained in:
parent
f9e7c86a1a
commit
49f481e399
9 changed files with 114 additions and 6 deletions
|
|
@ -13,6 +13,11 @@ try:
|
|||
from markdown import Markdown
|
||||
except ImportError:
|
||||
Markdown = False # NOQA
|
||||
try:
|
||||
from asciidocapi import AsciiDocAPI
|
||||
asciidoc = True
|
||||
except ImportError:
|
||||
asciidoc = False
|
||||
import re
|
||||
|
||||
from pelican.contents import Category, Tag, Author
|
||||
|
|
@ -162,6 +167,37 @@ class HtmlReader(Reader):
|
|||
return content, metadata
|
||||
|
||||
|
||||
class AsciiDocReader(Reader):
|
||||
enabled = bool(asciidoc)
|
||||
file_extensions = ['asc']
|
||||
default_options = ["--no-header-footer", "-a newline=\\n"]
|
||||
|
||||
def read(self, filename):
|
||||
"""Parse content and metadata of asciidoc files"""
|
||||
from cStringIO import StringIO
|
||||
text = StringIO(pelican_open(filename))
|
||||
content = StringIO()
|
||||
ad = AsciiDocAPI()
|
||||
|
||||
options = self.settings.get('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
|
||||
|
||||
|
||||
_EXTENSIONS = {}
|
||||
|
||||
for cls in Reader.__subclasses__():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue