How to use the docutils.nodes.inline function in docutils

To help you get started, we’ve selected a few docutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / neutron / doc / source / ext / support_matrix.py View on Github external
def _create_notes_paragraph(self, notes):
        """Constructs a paragraph which represents the implementation notes

        The paragraph consists of text and clickable URL nodes if links were
        given in the notes.
        """
        para = nodes.paragraph()
        para.append(nodes.strong(text="Notes: "))
        # links could start with http:// or https://
        link_idxs = [m.start() for m in re.finditer('https?://', notes)]
        start_idx = 0
        for link_idx in link_idxs:
            # assume the notes start with text (could be empty)
            para.append(nodes.inline(text=notes[start_idx:link_idx]))
            # create a URL node until the next text or the end of the notes
            link_end_idx = notes.find(" ", link_idx)
            if link_end_idx == -1:
                # In case the notes end with a link without a blank
                link_end_idx = len(notes)
            uri = notes[link_idx:link_end_idx + 1]
            para.append(nodes.reference("", uri, refuri=uri))
            start_idx = link_end_idx + 1

        # get all text after the last link (could be empty) or all of the
        # text if no link was given
        para.append(nodes.inline(text=notes[start_idx:]))
        return para
github rst2pdf / rst2pdf / rst2pdf / pygments_code_block_directive.py View on Github external
for cls, value in DocutilsInterface(content, language, options):
        if hl_lines and lineno not in hl_lines:
            cls = "diml"
        if withln and "\n" in value:
            linenumber_cls = 'linenumber'
            if hl_lines and (lineno+1) not in hl_lines: # use lineno+1 as we're on the previous line when we render the next line number
                linenumber_cls = 'pygments-diml'
            # Split on the "\n"s
            values = value.split("\n")
            # The first piece, pass as-is
            code_block += nodes.Text(values[0], values[0])
            # On the second and later pieces, insert \n and linenos
            linenos = range(lineno, lineno + len(values))
            for chunk, ln in list(zip(values, linenos))[1:]:
                if ln <= total_lines:
                    code_block += nodes.inline(fstr % ln, fstr % ln, classes=[linenumber_cls])
                    code_block += nodes.Text(chunk, chunk)
            lineno += len(values) - 1

        elif cls in unstyled_tokens:
            if "\n" in value:
                lineno = lineno + value.count("\n")
            # insert as Text to decrease the verbosity of the output.
            code_block += nodes.Text(value, value)
        else:
            if "\n" in value:
                lineno = lineno + value.count("\n")
            code_block += nodes.inline(value, value, classes=["pygments-" + cls])

    return [code_block]
github pulp / pulpcore / docs / sphinx / _extensions / rest_api.py View on Github external
however, is optional.

    Example: 409,if a repository with the given ID already exists
    """

    parts = text.split(',', 1)

    code = parts[0].strip()
    n1 = nodes.strong(text=code)

    created_nodes = [n1]

    if len(parts) > 1:
        description = ' '.join(parts[1:]).strip()
        description = _format_description(description)
        n2 = nodes.inline(text=' - ' + description)
        created_nodes.append(n2)

    return created_nodes, []
github coq / coq / doc / tools / coqrst / coqdomain.py View on Github external
def colorize_str(self, raw):
        """Parse raw (an ANSI-colored output string from Coqtop) into Sphinx nodes."""
        last_end = 0
        for match in AnsiColorsParser.COLOR_PATTERN.finditer(raw):
            self._add_text(raw, last_end, match.start())
            last_end = match.end()
            classes = ansicolors.parse_ansi(match.group(1))
            if 'ansi-reset' in classes:
                self._finalize_pending_nodes()
            else:
                node = nodes.inline()
                self.pending_nodes.append(node)
                node['classes'].extend(classes)
        self._add_text(raw, last_end, len(raw))
        self._finalize_pending_nodes()
        return self.new_nodes
github timonwong / OmniMarkupPreviewer / OmniMarkupLib / Renderers / libs / python2 / docutils / parsers / rst / directives / body.py View on Github external
except ValueError:
                raise self.error(':number-lines: with non-integer start value')
            endline = startline + len(self.content)
            # add linenumber filter:
            tokens = NumberLines(tokens, startline, endline)

        node = nodes.literal_block('\n'.join(self.content), classes=classes)
        self.add_name(node)
        # if called from "include", set the source
        if 'source' in self.options:
            node.attributes['source'] = self.options['source']
        # analyze content and add nodes for every token
        for classes, value in tokens:
            # print (classes, value)
            if classes:
                node += nodes.inline(value, value, classes=classes)
            else:
                # insert as Text to decrease the verbosity of the output
                node += nodes.Text(value, value)

        return [node]
github openstack / nova-powervm / doc / ext / support_matrix.py View on Github external
status = feature.status
            if feature.group is not None:
                status += "(" + feature.group + ")"

            # The hypervisor target name linked from summary table
            id = re.sub("[^a-zA-Z0-9_]", "_",
                        feature.key)

            # Highlight the feature title name
            item.append(nodes.strong(text=feature.title,
                                     ids=[id]))

            para = nodes.paragraph()
            para.append(nodes.strong(text="Status: " + status + ". "))
            if feature.notes is not None:
                para.append(nodes.inline(text=feature.notes))
            item.append(para)

            if feature.cli:
                item.append(self._create_cli_paragraph(feature))

            para_divers = nodes.paragraph()
            para_divers.append(nodes.strong(text="drivers:"))
            # A sub-list giving details of each hypervisor target
            impls = nodes.bullet_list()
            for key in feature.implementations:
                target = matrix.targets[key]
                impl = feature.implementations[key]
                subitem = nodes.list_item()

                id = re.sub("[^a-zA-Z0-9_]", "_",
                            feature.key + "_" + key)
github delfick / harpoon / harpoon / sphinx / show_specs.py View on Github external
def nodes_for_signature(self, spec, para):
        tokens = []
        if isinstance(spec, sb.create_spec):
            para += nodes.Text("  ")
        elif isinstance(spec, sb.optional_spec):
            colord = nodes.inline(classes=["blue-text"])
            emphasis = nodes.emphasis()
            emphasis += nodes.Text(" (optional) ")
            colord += emphasis
            para += colord
            self.nodes_for_signature(spec.spec, para)
        elif isinstance(spec, sb.defaulted):
            colord = nodes.inline(classes=["green-text"])
            emphasis = nodes.emphasis()
            dflt = spec.default(None)
            if isinstance(dflt, six.string_types):
                dflt = '"{0}"'.format(dflt)
            emphasis += nodes.Text(" (default={0}) ".format(dflt))
            colord += emphasis
            para += colord
            self.nodes_for_signature(spec.spec, para)
        elif isinstance(spec, sb.required):
            colord = nodes.inline(classes=["red-text"])
            strong = nodes.strong()
            strong += nodes.Text(" (required) ")
            colord += strong
            para += colord
            self.nodes_for_signature(spec.spec, para)
        elif isinstance(spec, sb.listof):
github veegee / amqpy / docs / source / conf.py View on Github external
def generic_span_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """
    :param name: role name used in the document
    :param rawtext: entire markup snippet, with role
    :param text: text marked with the role
    :param lineno: line number where rawtext appears in the input
    :param inliner: inliner instance that called us
    :param options: directive options for customization
    :param content: directive content for customization
    :return: list, list
    :rtype: list, list
    """
    node = nodes.inline(rawtext, text)
    node['classes'] = [name]
    return [node], []
github Anomareh / mynt / mynt / parsers / docutils.py View on Github external
classes.append(language)

    try:
        highlight = inliner.document.settings.syntax_highlight
        tokens = Lexer(utils.unescape(string, 1), language, highlight)
    except LexerError as error:
        message = inliner.reporter.warning(error)
        problem = inliner.problematic(raw, raw, message)

        return [problem], [message]

    node = nodes.literal(raw, '', classes=classes)

    for classes, value in tokens:
        if classes:
            node += nodes.inline(value, value, classes=classes)
        else:
            node += nodes.Text(value, value)

    return ([node], [])
github sphinx-doc / sphinx / sphinx / builders / _epub_base.py View on Github external
return doc, doc.index(rub) + 1

        if show_urls == 'no':
            return
        if show_urls == 'footnote':
            doc = tree.traverse(nodes.document)[0]
            fn_spot, fn_idx = footnote_spot(tree)
            nr = 1
        for node in tree.traverse(nodes.reference):
            uri = node.get('refuri', '')
            if (uri.startswith('http:') or uri.startswith('https:') or
                    uri.startswith('ftp:')) and uri not in node.astext():
                idx = node.parent.index(node) + 1
                if show_urls == 'inline':
                    uri = self.link_target_template % {'uri': uri}
                    link = nodes.inline(uri, uri)
                    link['classes'].append(self.css_link_target_class)
                    node.parent.insert(idx, link)
                elif show_urls == 'footnote':
                    label = FOOTNOTE_LABEL_TEMPLATE % nr
                    nr += 1
                    footnote_ref = make_footnote_ref(doc, label)
                    node.parent.insert(idx, footnote_ref)
                    footnote = make_footnote(doc, label, uri)
                    fn_spot.insert(fn_idx, footnote)
                    footnote_ref['refid'] = footnote['ids'][0]
                    footnote.add_backref(footnote_ref['ids'][0])
                    fn_idx += 1