Esempio n. 1
0
    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.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
Esempio n. 2
0
def run(content):
    infile = StringIO.StringIO(content)
    outfile = StringIO.StringIO()
    asciidoc = AsciiDocAPI()
    asciidoc.options('--no-header-footer')
    asciidoc.execute(infile, outfile, backend='html4')
    return outfile.getvalue()
Esempio n. 3
0
def asciidoc(value):
    output = value

    asciidoc = AsciiDocAPI()
    asciidoc.options('--no-header-footer')
    result = StringIO.StringIO()
    asciidoc.execute(StringIO.StringIO(output.encode('utf-8')),
        result, backend='html5')

    return unicode(result.getvalue(), "utf-8")
Esempio n. 4
0
	def asciidoc_output(self,asciidoc_markup,backend='xhtml11',attributes=[],options=['--no-header-footer'],debug=False):
		infile = StringIO.StringIO(asciidoc_markup)
		outfile = StringIO.StringIO()
		asciidoc = AsciiDocAPI('../../../asciidoc.py')
		for option in options:
			asciidoc.options(option)
		for attribute in attributes:
			asciidoc.attributes[attribute] = 1
		asciidoc.execute(infile, outfile,backend)
		if debug: print asciidoc.messages
		return outfile.getvalue()
Esempio n. 5
0
def asc(text):
    if not asciidoc:
        _logger.error("Unable to import asciidocapi.py")
        return text
    inp = StringIO(text)
    out = StringIO()
    ad = AsciiDocAPI()
    ad.execute(inp, out, backend="html4")
    html = out.getvalue()
    print(html)
    return html
Esempio n. 6
0
 def _configure(self):
     self._asciidoc = AsciiDocAPI()
     self._asciidoc.attributes['root'] = self._conf['destdir']
     self._asciidoc.attributes['source-highlighter'] = 'pygments'
     self._asciidoc.attributes['caption'] = ''
     self._asciidoc.attributes['iconsdir'] = '/usr/share/asciidoc/icons/'
     self._asciidoc.attributes['confdir'] = os.path.join(
         self._conf['maindir'], 'asciidoc')
     conf_file = os.path.join(self._asciidoc.attributes['confdir'],
                              'asciidoc-devyco.conf')
     self._asciidoc.options('--conf-file', conf_file)
     self._asciidoc.options('--no-header-footer')
     self.processed_files = []
Esempio n. 7
0
 def render(self, context):
     output = self.nodelist.render(context)
     try:
         from asciidocapi import AsciiDocAPI
     except ImportError:
         print u"Requires AsciiDoc library to use AsciiDoc tag."
         raise
     asciidoc = AsciiDocAPI()
     asciidoc.options('--no-header-footer')
     result = StringIO.StringIO()
     asciidoc.execute(StringIO.StringIO(output.encode('utf-8')), result,
                      'html4')
     return safestring.mark_safe(result.getvalue())
Esempio n. 8
0
 def __init__(self,asciidocpath):
     adfile = open(asciidocpath,'r')
     outfile = StringIO.StringIO()
     asciidoc = AsciiDocAPI()
     asciidoc.options('--no-header-footer')
     asciidoc.execute(adfile, outfile, backend='html4')
     attributes = asciidoc.asciidoc.document.attributes #.attributes.values
     #print attributes
     self.file = os.path.basename(asciidocpath[:asciidocpath.find('.asciidoc')]) + '.html'
     self.date = attributes['date']
     self.title = attributes['doctitle']
     self.summary = attributes['summary']
     self.author = attributes['author']
     self.author_site = attributes['author_site']
     self.body = outfile.getvalue().decode('utf-8','replace').replace('<pre>','<pre><code class="cpp">').replace('</pre>','</code></pre>')
     self.type = 'asciidoc'
Esempio n. 9
0
File: jinja.py Progetto: jiivan/hyde
def asciidoc(env, value):
    """
    (simple) Asciidoc filter
    """
    try:
        from asciidocapi import AsciiDocAPI
    except ImportError:
        print("Requires AsciiDoc library to use AsciiDoc tag.")
        raise

    output = value

    asciidoc = AsciiDocAPI()
    asciidoc.options('--no-header-footer')
    result = StringIO()
    asciidoc.execute(StringIO(output.encode('utf-8')), result, backend='html4')
    return str(result.getvalue(), "utf-8")
Esempio n. 10
0
#!/usr/bin/env python

import sys
import yaml
from jinja2 import Template
from asciidocapi import AsciiDocAPI
from StringIO import StringIO

t_content = ""
with open(sys.argv[1], 'r') as f:
    t_content = f.read().decode('utf8')
template = Template(t_content)
obj = yaml.load(sys.stdin)
sys.stderr.write(str(obj))

in_data = StringIO(template.render(obj).encode('utf8'))
out_data = StringIO()
asciidoc = AsciiDocAPI()
asciidoc.options('--no-header-footer')
asciidoc.execute(in_data, out_data, backend='xhtml11')
sys.stdout.write(out_data.getvalue())