本文整理汇总了Python中docutils.writers.html4css1.Writer.translator_class方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.translator_class方法的具体用法?Python Writer.translator_class怎么用?Python Writer.translator_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.writers.html4css1.Writer
的用法示例。
在下文中一共展示了Writer.translator_class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rst_to_html
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def rst_to_html(rst_string, settings=None):
"""Convert a string written in reStructuredText to an HTML string.
:param rst_string:
A string that holds the contents of a reStructuredText document.
:param settings:
Optional. A dictionary which overrides the default settings.
For a list of the possible keys and values, see
http://docutils.sourceforge.net/docs/user/config.html.
To log the values used, pass in ``'dump_settings': 'yes'``.
"""
writer = Writer()
writer.translator_class = HTMLTranslator
if settings is None:
settings = {
# Include a time/datestamp in the document footer.
'datestamp': '%Y-%m-%d %H:%M UTC',
# Recognize and link to standalone PEP references (like "PEP 258").
'pep_references': 1,
# Do not report any system messages.
'report_level': 'none',
# Recognize and link to standalone RFC references (like "RFC 822").
'rfc_references': 1,
}
return core.publish_string(rst_string, writer=writer,
settings_overrides=settings)
示例2: index
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def index():
flask.url_for('static', filename='github.css')
flask.url_for('static', filename='semantic-1.2.0/semantic.css')
flask.url_for('static', filename='semantic-1.2.0/semantic.js')
flask.url_for('static', filename='qubes.css')
input_filename = '/home/user/w/qubes-tools/NOTES.rst'
# sys.argv.append('NOTES.rst')
try:
#text = codecs.open(sys.argv[1], 'r', 'utf-8').read()
#with open(input_filename, "r", 'utf-8') as source:
with open(input_filename, "r") as source:
text = source.read().encode('utf-8')
except IOError: # given filename could not be found
return ''
except IndexError: # no filename given
text = sys.stdin.read()
writer = Writer()
writer.translator_class = rest2html.GitHubHTMLTranslator
parts = docutils.core.publish_parts(text, writer=writer,
settings_overrides=rest2html.SETTINGS)
if 'html_body' in parts:
print parts['html_body']
html = flask.Markup(parts['html_body'])
# publish_parts() in python 2.x return dict values as Unicode type
# in py3k Unicode is unavailable and values are of str type
if isinstance(html, str):
return flask.render_template('index.html', html=html)
else:
return flask.render_template('index.html', html=html.encode('utf-8'))
return flask.render_template('index.html', html='')
示例3: rst2html
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def rst2html(rst):
from docutils.core import publish_string
from docutils.writers.html4css1 import Writer,HTMLTranslator
class xia2HTMLTranslator(HTMLTranslator):
def __init__(self, document):
HTMLTranslator.__init__(self, document)
def visit_table(self, node):
self.context.append(self.compact_p)
self.compact_p = True
classes = ' '.join(['docutils', self.settings.table_style]).strip()
self.body.append(
self.starttag(node, 'table', CLASS=classes, border="0"))
def write_colspecs(self):
self.colspecs = []
xia2_root_dir = libtbx.env.find_in_repositories("xia2", optional=False)
args = {
'stylesheet_path': os.path.join(xia2_root_dir, 'css', 'voidspace.css')
}
w = Writer()
w.translator_class = xia2HTMLTranslator
return publish_string(rst, writer=w, settings=None, settings_overrides=args)
示例4: publishPage
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def publishPage(self,key):
src = self.pages[key].rst
pubpath = os.path.join(rootpath,"public",key)
try:
os.makedirs(os.path.split(pubpath)[0])
except:
pass
# Soft reset
traveler.features.reset()
writer = Writer()
writer.translator_class = HTMLTranslatorForLegalResourceRegistry
keylst = key.split("/")
upset = [".."] * (len(keylst)-1)
css = os.path.sep.join(upset + ["screen.css"])
octicons = os.path.sep.join(upset + ["bower_components/octicons/octicons/octicons.css"])
options = {
"stylesheet": octicons + "," + css,
"stylesheet_path": None,
"embed_stylesheet": False,
"footnote_backlinks": True,
"input_encoding": "utf-8"
}
src = src + '\n.. raw:: html\n\n </div>\n'
html = publish_string(src, reader=None, reader_name='standalone', writer=writer, settings_overrides=options)
if self.writePages:
codecs.open(pubpath, "w+", "utf-8").write(html)
示例5: main
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def main():
# Create a writer to deal with the generic element we may have created.
writer = Writer()
writer.translator_class = MyTranslator
description = (
'Generates (X)HTML documents from standalone reStructuredText '
'sources. Be forgiving against unknown elements. '
+ default_description)
# the parser processes the settings too late: we want to decide earlier if
# we are running or testing.
if ('--test-patch' in sys.argv
and not ('-h' in sys.argv or '--help' in sys.argv)):
return test_patch(writer)
else:
# Make docutils lenient.
patch_docutils()
overrides = {
# If Pygments is missing, code-block directives are swallowed
# with Docutils >= 0.9.
'syntax_highlight': 'none',
# not available on Docutils < 0.8 so can't pass as an option
'math_output': 'HTML',
}
publish_cmdline(writer=writer, description=description,
settings_spec=LenientSettingsSpecs, settings_overrides=overrides)
return 0
示例6: main
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def main():
"""
Parses the given ReST file or the redirected string input and returns the
HTML body.
Usage: rest2html < README.rst
rest2html README.rst
"""
try:
text = codecs.open(sys.argv[1], 'r', 'utf-8').read()
except IOError: # given filename could not be found
return ''
except IndexError: # no filename given
text = sys.stdin.read()
writer = Writer()
writer.translator_class = GitHubHTMLTranslator
parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
if 'html_body' in parts:
html = parts['html_body']
# publish_parts() in python 2.x return dict values as Unicode type
# in py3k Unicode is unavailable and values are of str type
if isinstance(html, str):
return html
else:
return html.encode('utf-8')
return ''
示例7: __init__
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def __init__(self):
core.Publisher.__init__(self)
self.set_reader('standalone', None, 'restructuredtext')
writer = Writer()
# we don't want HTML headers in our writer
writer.translator_class = NoHeaderHTMLTranslator
self.writer = writer
# go with the defaults
self.get_settings()
self.settings.xml_declaration = ""
# this is needed, but doesn't seem to do anything
self.settings._destination = ''
# use no stylesheet
self.settings.stylesheet = ''
self.settings.stylesheet_path = ''
self.settings.embed_stylesheet = False
# don't break if we get errors
self.settings.halt_level = 6
# remember warnings
self.warnings = ''
示例8: getPublicCmsReSTWriter
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def getPublicCmsReSTWriter():
global _PublicCmsReSTWriter, _PublicReSTTranslator
if not _PublicCmsReSTWriter:
_PublicCmsReSTWriter = Writer()
_PublicCmsReSTWriter.translator_class = _PublicReSTTranslator
return _PublicCmsReSTWriter
示例9: form_example
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def form_example(self, ctx):
form = formal.Form()
form.addField('restString', formal.String(required=True),
widgetFactory=formal.ReSTTextArea)
if docutilsAvailable:
w = Writer()
w.translator_class = CustomisedHTMLTranslator
form.addField('customRestString', formal.String(required=True),
formal.widgetFactory(formal.ReSTTextArea, restWriter=w))
form.addAction(self.submitted)
return form
示例10: convert_string_fragment
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def convert_string_fragment(string):
""" Converts a string of reST text into an html fragment (ie no <header>,
<body>, etc tags).
"""
html_fragment_writer = Writer()
html_fragment_writer.translator_class = HTMLFragmentTranslator
return core.publish_string(_fix_indent(string),
writer = html_fragment_writer,
# Suppress output of warnings in html
settings_overrides={'report_level':'5'})
示例11: about
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def about(request, template="about.html"):
"""
Convert the README file into HTML.
"""
from docutils.core import publish_string
from docutils.writers.html4css1 import Writer, HTMLTranslator
writer = Writer()
writer.translator_class = HTMLTranslator
with open(join(settings.PROJECT_ROOT, "README.rst"), "r") as f:
about = publish_string(f.read(), writer=writer)
with open(join(settings.PROJECT_ROOT, "LICENSE"), "r") as f:
license = publish_string(f.read(), writer=writer)
context = {"about": about, "license": license}
return render(request, template, context)
示例12: restructured_to_html
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def restructured_to_html(s):
""" Convert RST string to HTML string.
"""
if not s:
return s
html_fragment_writer = Writer()
html_fragment_writer.translator_class = HTMLFragmentTranslator
#html = docutils.core.publish_string(s, writer=html_fragment_writer)
parts = docutils.core.publish_parts(source=s, writer_name='html')
return parts['body_pre_docinfo']+parts['fragment']
示例13: render
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def render(self, request, text, settings_overrides={}):
overrides = {
'halt_level': 6,
'input_encoding': 'unicode',
'output_encoding': 'unicode',
'initial_header_level': 3,
}
overrides.update(settings_overrides)
writer = Writer()
writer.translator_class = Translator
html = docutils.core.publish_string(
text,
writer=writer,
settings_overrides=overrides,
)
return html
示例14: render
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def render(self, text, **kwargs):
settings_overrides = {
"cloak_email_addresses": True,
"file_insertion_enabled": False,
"raw_enabled": False,
"strip_comments": True,
"doctitle_xform": False,
"report_level": 5,
"syntax_highlight": "none",
"math_output": "latex",
"input_encoding": "utf-8",
"output_encoding": "utf-8",
}
writer = Writer()
writer.translator_class = GitHubHTMLTranslator
output = publish_parts(text, writer=writer, settings_overrides=settings_overrides)
if "html_body" in output:
return output["html_body"]
return ""
示例15: main
# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import translator_class [as 别名]
def main():
# Create a writer to deal with the generic element we may have created.
writer = Writer()
writer.translator_class = MyTranslator
description = (
'Generates (X)HTML documents from standalone reStructuredText '
'sources. Be forgiving against unknown elements. '
+ default_description)
# the parser processes the settings too late: we want to decide earlier if
# we are running or testing.
if ('--test-patch' in sys.argv
and not ('-h' in sys.argv or '--help' in sys.argv)):
return test_patch(writer)
else:
# Make docutils lenient.
patch_docutils()
publish_cmdline(writer=writer, description=description,
settings_spec=LenientSettingsSpecs)
return 0