Python docutils.nodes.raw() Examples
The following are 30
code examples of docutils.nodes.raw().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: sphinx_issues.py From scikit-sports with MIT License | 6 votes |
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, []
Example #2
Source File: peps.py From deepWordBug with Apache License 2.0 | 6 votes |
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
Example #3
Source File: sphinx_issues.py From scikit-multiflow with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, []
Example #4
Source File: roles.py From bash-lambda-layer with MIT License | 6 votes |
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], []
Example #5
Source File: peps.py From faces with GNU General Public License v2.0 | 6 votes |
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
Example #6
Source File: roles.py From faces with GNU General Public License v2.0 | 6 votes |
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], []
Example #7
Source File: roles.py From deepWordBug with Apache License 2.0 | 6 votes |
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], []
Example #8
Source File: peps.py From bash-lambda-layer with MIT License | 6 votes |
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
Example #9
Source File: peps.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #10
Source File: roles.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
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], []
Example #11
Source File: peps.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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
Example #12
Source File: roles.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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], []
Example #13
Source File: peps.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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
Example #14
Source File: peps.py From blackmamba with MIT License | 6 votes |
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
Example #15
Source File: peps.py From faces with GNU General Public License v2.0 | 6 votes |
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
Example #16
Source File: sphinx_issues.py From chainladder-python with Mozilla Public License 2.0 | 6 votes |
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, []
Example #17
Source File: sphinx_issues.py From ramp-workflow with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, []
Example #18
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
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" ')
Example #19
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
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+" ')
Example #20
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
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+" ')
Example #21
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
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" ')
Example #22
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
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)))
Example #23
Source File: roles.py From aws-extender with MIT License | 6 votes |
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], []
Example #24
Source File: peps.py From aws-extender with MIT License | 6 votes |
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
Example #25
Source File: roles.py From blackmamba with MIT License | 6 votes |
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], []
Example #26
Source File: roles.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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], []
Example #27
Source File: directives.py From blockdiag with Apache License 2.0 | 5 votes |
def node2image_inline_svg(self, node, diagram): fontmap = self.create_fontmap() if hasattr(node, 'to_drawer'): drawer = node.to_drawer('SVG', None, fontmap, **self.global_options) else: drawer = self.processor.drawer.DiagramDraw('svg', diagram, None, fontmap=fontmap, **self.global_options) drawer.draw() size = drawer.pagesize().resize(**node['options']).to_integer_point() content = drawer.save(size) return nodes.raw('', content, format='html')
Example #28
Source File: test_blockdiag_directives.py From blockdiag with Apache License 2.0 | 5 votes |
def test_setup_inline_svg_is_true(self): directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True) text = (".. blockdiag::\n" "\n" " 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)))
Example #29
Source File: conf.py From tbot with GNU General Public License v3.0 | 5 votes |
def run(self) -> typing.List[nodes.Node]: self.assert_has_content() text = "\n".join(self.content) gen = [] # Add html version html_text = '<div class="highlight">\n' + text + "\n</div>" gen.append(nodes.raw(text, html_text, format="html")) # Add latex version latex_text = "\\begin{sphinxVerbatim}[commandchars=\\\\\\{\\}]\n" transformed = text transformed = transformed.replace("\\", "\\textbackslash{}") transformed = self.pat_pre.sub("", transformed) transformed = self.pat_color.sub(r"\\textcolor[HTML]{\1}{\2}", transformed) transformed = self.pat_bold.sub(r"\\textbf{\1}", transformed) transformed = transformed.replace("<", "<") transformed = transformed.replace(">", ">") transformed = transformed.replace("'", r"\textsc{\char39}") transformed = transformed.replace(""", '"') latex_text += transformed latex_text += "\n\\end{sphinxVerbatim}" gen.append(nodes.raw(text, latex_text, format="latex")) return gen # }}} # -- Fix instance variables being cross-referenced --------------------------- {{{
Example #30
Source File: universal.py From faces with GNU General Public License v2.0 | 5 votes |
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())