当前位置: 首页>>代码示例>>Python>>正文


Python asciidocapi.AsciiDocAPI类代码示例

本文整理汇总了Python中asciidocapi.AsciiDocAPI的典型用法代码示例。如果您正苦于以下问题:Python AsciiDocAPI类的具体用法?Python AsciiDocAPI怎么用?Python AsciiDocAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsciiDocAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

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()
开发者ID:Alsivkov,项目名称:ofSite,代码行数:7,代码来源:__init__.py

示例2: read

    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
开发者ID:AndreLesa,项目名称:pelican,代码行数:25,代码来源:readers.py

示例3: htmlize

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())
开发者ID:martina-if,项目名称:pywi,代码行数:7,代码来源:htmlize.py

示例4: asc

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
开发者ID:brugerer,项目名称:pyblue,代码行数:11,代码来源:utils.py

示例5: convert_file_html

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
开发者ID:mnunberg,项目名称:pycbc-docs,代码行数:12,代码来源:process.py

示例6: render

 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())
开发者ID:andrulik,项目名称:hyde,代码行数:12,代码来源:aym.py

示例7: __init__

 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'
开发者ID:kpasko,项目名称:ofSite,代码行数:16,代码来源:tutorials.py

示例8: asciidoc

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")
开发者ID:hyde,项目名称:hyde,代码行数:17,代码来源:jinja.py

示例9: asciidoc

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")
开发者ID:DaveRichmond,项目名称:hyde,代码行数:18,代码来源:jinja.py

示例10: convert_file_xml

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
开发者ID:mnunberg,项目名称:pycbc-docs,代码行数:19,代码来源:process.py

示例11: _configure

 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 = []
开发者ID:Yubico,项目名称:developers.yubico.com,代码行数:11,代码来源:asciidoc.py

示例12: read

 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
开发者ID:jedahu,项目名称:pelican,代码行数:13,代码来源:readers.py

示例13: asciidoc_output

	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()
开发者ID:Ailenswpu,项目名称:external,代码行数:11,代码来源:slidy2_UnitTest.py

示例14: AsciiDocModule

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)
开发者ID:Yubico,项目名称:developers.yubico.com,代码行数:43,代码来源:asciidoc.py

示例15: open

#!/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())
开发者ID:man0xff,项目名称:asciidoc-yaml2any,代码行数:21,代码来源:yaml2any.py


注:本文中的asciidocapi.AsciiDocAPI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。