本文整理汇总了Python中docutils.nodes.raw方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.raw方法的具体用法?Python nodes.raw怎么用?Python nodes.raw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.raw方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mask_email
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def mask_email(ref, pepno=None):
"""
Mask the email address in `ref` and return a replacement node.
`ref` is returned unchanged if it contains no email address.
For email addresses such as "user@host", mask the address as "user at
host" (text) to thwart simple email address harvesters (except for those
listed in `non_masked_addresses`). If a PEP number (`pepno`) is given,
return a reference including a default email subject.
"""
if ref.hasattr('refuri') and ref['refuri'].startswith('mailto:'):
if ref['refuri'][8:] in non_masked_addresses:
replacement = ref[0]
else:
replacement_text = ref.astext().replace('@', ' at ')
replacement = nodes.raw('', replacement_text, format='html')
if pepno is None:
return replacement
else:
ref['refuri'] += '?subject=PEP%%20%s' % pepno
ref[:] = [replacement]
return ref
else:
return ref
示例2: raw_role
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
if not inliner.document.settings.raw_enabled:
msg = inliner.reporter.warning('raw (and derived) roles disabled')
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
if 'format' not in options:
msg = inliner.reporter.error(
'No format (Writer name) is associated with this role: "%s".\n'
'The "raw" role cannot be used directly.\n'
'Instead, use the "role" directive to create a new role with '
'an associated format.' % role, line=lineno)
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
set_classes(options)
node = nodes.raw(rawtext, utils.unescape(text, 1), **options)
node.source, node.line = inliner.reporter.get_source_and_line(lineno)
return [node], []
示例3: issue_role
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def issue_role(name, rawtext, text, lineno,
inliner, options=None, content=None):
"""Sphinx role for linking to an issue. Must have
`issues_uri` or `issues_github_path` configured in ``conf.py``.
Examples: ::
:issue:`123`
:issue:`42,45`
"""
options = options or {}
content = content or []
issue_nos = [each.strip() for each in utils.unescape(text).split(',')]
config = inliner.document.settings.env.app.config
ret = []
for i, issue_no in enumerate(issue_nos):
node = _make_issue_node(issue_no, config, options=options)
ret.append(node)
if i != len(issue_nos) - 1:
sep = nodes.raw(text=', ', format='html')
ret.append(sep)
return ret, []
示例4: test_setup_inline_svg_is_true
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def test_setup_inline_svg_is_true(self):
directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
text = (".. nwdiag::\n"
"\n"
" network {"
" A"
" B"
" }")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.raw, type(doctree[0]))
self.assertEqual('html', doctree[0]['format'])
self.assertEqual(nodes.Text, type(doctree[0][0]))
self.assertEqual("<?xml version='1.0' encoding='UTF-8'?>\n"
"<!DOCTYPE ", doctree[0][0][:49])
self.assertEqual(0, len(os.listdir(self.tmpdir)))
示例5: test_setup_inline_svg_is_true_and_width_option1
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def test_setup_inline_svg_is_true_and_width_option1(self):
directives.setup(format='SVG', outputdir=self.tmpdir,
nodoctype=True, noviewbox=True, inline_svg=True)
text = (".. nwdiag::\n"
" :width: 100\n"
"\n"
" network {"
" A"
" B"
" }")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.raw, type(doctree[0]))
self.assertEqual(nodes.Text, type(doctree[0][0]))
self.assertRegexpMatches(doctree[0][0],
r'<svg height="\d+" width="100" ')
示例6: test_setup_inline_svg_is_true_and_height_option1
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def test_setup_inline_svg_is_true_and_height_option1(self):
directives.setup(format='SVG', outputdir=self.tmpdir,
nodoctype=True, noviewbox=True, inline_svg=True)
text = (".. nwdiag::\n"
" :height: 100\n"
"\n"
" network {"
" A"
" B"
" }")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.raw, type(doctree[0]))
self.assertEqual(nodes.Text, type(doctree[0][0]))
self.assertRegexpMatches(doctree[0][0],
r'<svg height="100" width="\d+" ')
示例7: test_setup_inline_svg_is_true_and_height_option2
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def test_setup_inline_svg_is_true_and_height_option2(self):
directives.setup(format='SVG', outputdir=self.tmpdir,
nodoctype=True, noviewbox=True, inline_svg=True)
text = (".. nwdiag::\n"
" :height: 10000\n"
"\n"
" network {"
" A"
" B"
" }")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.raw, type(doctree[0]))
self.assertEqual(nodes.Text, type(doctree[0][0]))
self.assertRegexpMatches(doctree[0][0],
r'<svg height="10000" width="\d+" ')
示例8: test_setup_inline_svg_is_true_and_width_and_height_option
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def test_setup_inline_svg_is_true_and_width_and_height_option(self):
directives.setup(format='SVG', outputdir=self.tmpdir,
nodoctype=True, noviewbox=True, inline_svg=True)
text = (".. nwdiag::\n"
" :width: 200\n"
" :height: 100\n"
"\n"
" network {"
" A"
" B"
" }")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.raw, type(doctree[0]))
self.assertEqual(nodes.Text, type(doctree[0][0]))
self.assertRegexpMatches(doctree[0][0],
'<svg height="100" width="200" ')
示例9: get_tokens
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def get_tokens(self, txtnodes):
# A generator that yields ``(texttype, nodetext)`` tuples for a list
# of "Text" nodes (interface to ``smartquotes.educate_tokens()``).
texttype = {True: 'literal', # "literal" text is not changed:
False: 'plain'}
for txtnode in txtnodes:
nodetype = texttype[isinstance(txtnode.parent,
(nodes.literal,
nodes.math,
nodes.image,
nodes.raw,
nodes.problematic))]
yield (nodetype, txtnode.astext())
示例10: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def run(self):
if (not self.state.document.settings.raw_enabled
or (not self.state.document.settings.file_insertion_enabled
and ('file' in self.options
or 'url' in self.options))):
raise self.warning('"%s" directive disabled.' % self.name)
attributes = {'format': ' '.join(self.arguments[0].lower().split())}
encoding = self.options.get(
'encoding', self.state.document.settings.input_encoding)
e_handler=self.state.document.settings.input_encoding_error_handler
if self.content:
if 'file' in self.options or 'url' in self.options:
raise self.error(
'"%s" directive may not both specify an external file '
'and have content.' % self.name)
text = '\n'.join(self.content)
elif 'file' in self.options:
if 'url' in self.options:
raise self.error(
'The "file" and "url" options may not be simultaneously '
'specified for the "%s" directive.' % self.name)
source_dir = os.path.dirname(
os.path.abspath(self.state.document.current_source))
path = os.path.normpath(os.path.join(source_dir,
self.options['file']))
path = utils.relative_path(None, path)
try:
raw_file = io.FileInput(source_path=path,
encoding=encoding,
error_handler=e_handler)
# TODO: currently, raw input files are recorded as
# dependencies even if not used for the chosen output format.
self.state.document.settings.record_dependencies.add(path)
except IOError, error:
raise self.severe(u'Problems with "%s" directive path:\n%s.'
% (self.name, ErrorString(error)))
try:
text = raw_file.read()
except UnicodeError, error:
raise self.severe(u'Problem with "%s" directive:\n%s'
% (self.name, ErrorString(error)))
示例11: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import raw [as 别名]
def run(self):
if micawber is None:
msg = "To use the embed directive, install micawber first."
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
url = " ".join(self.arguments)
html = micawber.parse_text(url, self.get_providers())
return [nodes.raw('', html, format='html')]