本文整理汇总了Python中asciidocapi.AsciiDocAPI.execute方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiDocAPI.execute方法的具体用法?Python AsciiDocAPI.execute怎么用?Python AsciiDocAPI.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asciidocapi.AsciiDocAPI
的用法示例。
在下文中一共展示了AsciiDocAPI.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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()
示例2: read
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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
示例3: htmlize
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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())
示例4: asciidoc_output
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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()
示例5: asc
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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
示例6: render
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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())
示例7: convert_file_html
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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
示例8: read
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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
示例9: __init__
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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'
示例10: asciidoc
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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")
示例11: asciidoc
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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")
示例12: AsciiDocModule
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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)
示例13: convert_file_xml
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
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
示例14: open
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
#!/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())
示例15: blog
# 需要导入模块: from asciidocapi import AsciiDocAPI [as 别名]
# 或者: from asciidocapi.AsciiDocAPI import execute [as 别名]
def blog(self, page='index'):
asciidoc = AsciiDocAPI()
outfile = StringIO.StringIO()
asciidoc.execute('pages/%s.txt'%page, outfile, backend='html5')
return outfile.getvalue()