Esempio n. 1
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. 2
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. 3
0
def htmlize(filename):
	asciidoc = AsciiDocAPI('../asciidoc/asciidoc.py')
	outfile = StringIO.StringIO()
	asciidoc.options('--no-header-footer')
	#asciidoc.options.append('--attribute', 'linkcss=untroubled.css')
	asciidoc.execute(filename, outfile) #, backend='html5')
	return str(outfile.getvalue())
Esempio n. 4
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. 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
File: aym.py Progetto: andrulik/hyde
 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. 7
0
def convert_file_html(fname):
    target = "html/" + fname.replace(".asciidoc", ".html")
    ai = AsciiDocAPI()
    ai.attributes.update({
            'data-uri' : True,
            'toc' : True,
            'icons' : True,
            'iconsdir' : '/etc/asciidoc/images/icons'
            })
    ai.execute(fname, target)
    for m in ai.messages:
        print m
Esempio n. 8
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. 9
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')
     self.type = 'asciidoc'
Esempio n. 10
0
File: jinja.py Progetto: hyde/hyde
def asciidoc(env, value):
    """
    (simple) Asciidoc filter
    """
    try:
        from asciidocapi import AsciiDocAPI
    except ImportError:
        print(u"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. 11
0
def asciidoc(env, value):
    """
    (simple) Asciidoc filter
    """
    try:
        from asciidocapi import AsciiDocAPI
    except ImportError:
        print u"Requires AsciiDoc library to use AsciiDoc tag."
        raise

    import StringIO
    output = value

    asciidoc = AsciiDocAPI()
    asciidoc.options('--no-header-footer')
    result = StringIO.StringIO()
    asciidoc.execute(StringIO.StringIO(output.encode('utf-8')), result, backend='html4')
    return unicode(result.getvalue(), "utf-8")
Esempio n. 12
0
def convert_file_xml(fname):
    outbuf = StringIO()
    target = "xml/" + fname.replace(".asciidoc", ".xml")

    ai = AsciiDocAPI()
    ai.options.append('--doctype', 'book')
    ai.execute(fname, outfile = outbuf, backend="docbook")

    fp = open(target, "w")
    fp.write(XML_DECL)

    outbuf.seek(0)
    xml = etree.fromstring(outbuf.read())
    chapters = xml.xpath("//chapter")
    for ch in chapters:
        fp.write(etree.tostring(ch))
    
    for m in ai.messages:
        print m
Esempio n. 13
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. 14
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. 15
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. 16
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. 17
0
 def read(self, filename):
   """Parse content and metadata of asciidoc files"""
   ad = AsciiDocAPI()
   ad.options('--no-header-footer')
   ad.attributes['pygments'] = 'pygments'
   if self.settings['ASCIIDOC_CONF']:
     ad.attributes['conf-files'] = self.settings['ASCIIDOC_CONF']
   buf = StringIO.StringIO()
   ad.execute(filename, buf, 'html5')
   content = buf.getvalue()
   buf.close()
   meta = self.read_meta(filename)
   return content, meta
Esempio n. 18
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. 19
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. 20
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. 21
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. 22
0
class AsciiDocModule(Module):
    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 = []

    def _run(self):
        for item in self.list_files(['*.adoc', '*.asciidoc', '*.txt']):
            target = noext(item) + '.partial'
            self._convert(item, target)
            self._post_process(target)

    def _convert(self, source, target):
        try:
            self._asciidoc.execute(source, target)
            for message in self._asciidoc.messages:
                sys.stderr.write('Error parsing Asciidoc file %s: %s\n' %
                                 (source, message))
            self.processed_files.append(source)
        except AsciiDocError as e:
            sys.stderr.write("Error parsing AsciiDoc in file: %s\n" % source)
            sys.stderr.write("%s\n" % e.message)

    def _post_process(self, target):
        with codecs.open(target, 'r', encoding='utf8') as f:
            soup = BeautifulSoup(f)
        for link in soup.find_all('a', href=ADOC_LINK):
            link['href'] = noext(link['href']) + '.html'

        with open(target, 'w') as f:
            f.write(soup.encode('utf-8'))

    def cleanup(self, context):
        for f in self.processed_files:
            os.remove(f)
Esempio n. 23
0
class AsciiDocModule(Module):

    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 = []

    def _run(self):
        for item in self.list_files(['*.adoc', '*.asciidoc', '*.txt']):
            target = noext(item) + '.partial'
            self._convert(item, target)
            self._post_process(target)

    def _convert(self, source, target):
        try:
            self._asciidoc.execute(source, target)
            for message in self._asciidoc.messages:
                sys.stderr.write('Error parsing Asciidoc file %s: %s\n' %
                                 (source, message))
            self.processed_files.append(source)
        except AsciiDocError as e:
            sys.stderr.write("Error parsing AsciiDoc in file: %s\n" % source)
            sys.stderr.write("%s\n" % e.message)

    def _post_process(self, target):
        with codecs.open(target,'r',encoding='utf8') as f:
            soup = BeautifulSoup(f, 'html.parser')
        for link in soup.find_all('a', href=ADOC_LINK):
            link['href'] = noext(link['href']) + '.html'

        with open(target, 'w') as f:
            f.write(soup.encode('utf-8'))

    def cleanup(self, context):
        for f in self.processed_files:
            os.remove(f)
Esempio n. 24
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())
Esempio n. 25
0
from flask import render_template
from app import app, db
from app.models import Post
import StringIO
from sqlalchemy import desc
from asciidocapi import AsciiDocAPI
asciidoc = AsciiDocAPI()
asciidoc.options('--no-header-footer')
import os

def run_asciidoc(p):
  outfile = StringIO.StringIO()
  asciidoc.execute(str(p.body), outfile, backend = 'html4')
  return outfile.getvalue()

@app.route('/')
@app.route('/index')
@app.route('/index/<int:page>')
def index(page = 1):
  posts = Post.query.order_by(desc(Post.timestamp)).paginate(page, 1, False)
  for p in posts.items:
    p.body = run_asciidoc(p)
  return render_template("index.html", posts = posts)

@app.route('/about')
def about():
  return render_template("about.html")

@app.route('/news')
def news():
  return render_template("news.html")
Esempio n. 26
0
 def blog(self, page='index'):
     asciidoc = AsciiDocAPI()
     outfile = StringIO.StringIO()
     asciidoc.execute('pages/%s.txt'%page, outfile, backend='html5')
     return outfile.getvalue()
Esempio n. 27
0
#!/usr/bin/env python3

import os
from pathlib import PurePath
from asciidocapi import AsciiDocAPI

man_pages = [
    'man/gnome-shell.1',
    'subprojects/extensions-tool/man/gnome-extensions.1',
]

sourceroot = os.environ.get('MESON_SOURCE_ROOT')
distroot = os.environ.get('MESON_DIST_ROOT')

asciidoc = AsciiDocAPI()

for man_page in man_pages:
    page_path = PurePath(man_page)
    src = PurePath(sourceroot, page_path.with_suffix('.txt'))
    dst = PurePath(distroot, page_path)
    stylesheet = src.with_name('stylesheet.xsl')

    asciidoc.options('--xsl-file', os.fspath(stylesheet))
    asciidoc.execute(os.fspath(src), outfile=os.fspath(dst))