How to use the docutils.utils 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 ros-infrastructure / rep / docutils_transforms_reps.py View on Github external
refuri=(self.document.settings.rep_base_url
                                + self.rep_url % repno)))
                    newbody.append(space)
                para[:] = newbody[:-1]  # drop trailing space
            elif name == 'last-modified':
                utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
                if repo_url:
                    date = para.astext()
                    para[:] = [nodes.reference('', date, refuri=repo_url)]
            elif name == 'content-type':
                rep_type = para.astext()
                uri = (self.document.settings.rep_base_url + self.rep_url
                       % self.rep_rst_nr)
                para[:] = [nodes.reference('', rep_type, refuri=uri)]
            elif name == 'version' and len(body):
                utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
github Sylius / Sylius / docs / _exts / sensio / sphinx / phpcode.py View on Github external
def php_method_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
    text = utils.unescape(text)
    env = inliner.document.settings.env
    base_url = env.app.config.api_url
    has_explicit_title, title, class_and_method = split_explicit_title(text)

    ns = class_and_method.rfind('::')
    full_class = class_and_method[:ns]
    method = class_and_method[ns+2:]

    try:
        full_url = base_url % full_class.replace('\\', '/') + '.html' + '#method_' + method
    except (TypeError, ValueError):
        env.warn(env.docname, 'unable to expand %s api_url with base '
                 'URL %r, please make sure the base contains \'%%s\' '
                 'exactly once' % (typ, base_url))
        full_url = base_url + utils.escape(full_class)
    if not has_explicit_title:
github stevearc / pypicloud / doc / extensions / github.py View on Github external
def make_node(rawtext, app, type_, slug, options):
    """ Create a github link """
    if app.config.github_user is None:
        raise ValueError("Configuration value for 'github_user' is not set.")
    base_url = "https://github.com/%s/%s/" % (
        app.config.github_user,
        app.config.project,
    )
    relative = "%s/%s" % (type_, slug)
    full_ref = urljoin(base_url, relative)
    set_classes(options)
    if type_ == "issues":
        type_ = "issue"
    node = nodes.reference(
        rawtext, type_ + " " + utils.unescape(slug), refuri=full_ref, **options
    )
    return node
github django-recurrence / django-recurrence / docs / github.py View on Github external
:param app: Sphinx application context
    :param slug: ID of the thing to link to
    :param options: Options dictionary passed to role func.
    """
    #
    try:
        base = app.config.github_project_url
        if not base:
            raise AttributeError
    except AttributeError as err:
        raise ValueError('github_project_url configuration value is not set (%s)' % str(err))

    slash = '/' if base[-1] != '/' else ''
    ref = base + slash +  'issues/' + slug + '/'
    set_classes(options)
    node = nodes.reference(rawtext, '#' + utils.unescape(slug), refuri=ref,
                           **options)
    return node
github pinax / pinax / site-packages / docutils-0.4 / docutils / parsers / rst / directives / misc.py View on Github external
'"%s" directive may not both specify an external file and '
                  'have content.' % name,
                  nodes.literal_block(block_text, block_text), line=lineno)
            return [error]
        text = '\n'.join(content)
    elif options.has_key('file'):
        if options.has_key('url'):
            error = state_machine.reporter.error(
                  'The "file" and "url" options may not be simultaneously '
                  'specified for the "%s" directive.' % name,
                  nodes.literal_block(block_text, block_text), line=lineno)
            return [error]
        source_dir = os.path.dirname(
            os.path.abspath(state.document.current_source))
        path = os.path.normpath(os.path.join(source_dir, options['file']))
        path = utils.relative_path(None, path)
        try:
            state.document.settings.record_dependencies.add(path)
            raw_file = io.FileInput(
                source_path=path, encoding=encoding,
                error_handler=state.document.settings.input_encoding_error_handler,
                handle_io_errors=None)
        except IOError, error:
            severe = state_machine.reporter.severe(
                  'Problems with "%s" directive path:\n%s.' % (name, error),
                  nodes.literal_block(block_text, block_text), line=lineno)
            return [severe]
        try:
            text = raw_file.read()
        except UnicodeError, error:
            severe = state_machine.reporter.severe(
                  'Problem with "%s" directive:\n%s: %s'
github rst2pdf / rst2pdf / rst2pdf / genelements.py View on Github external
def __init__(self, document):
        docutils.nodes.SparseNodeVisitor.__init__(self, document)
        self.toc = None
        # For some reason, when called via sphinx,
        # .. contents:: ends up trying to call
        # visitor.document.reporter.debug
        # so we need a valid document here.
        self.document=docutils.utils.new_document('')
github Kurento / doc-kurento / source / extensions / wikipedia.py View on Github external
def role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
        has_explicit, title, other = split_explicit_title(utils.unescape(text))
        args = [other]
        if use_explicit:
            args.append(has_explicit)
        result = func(*args)
        if isinstance(result, (list, tuple)):
            url, title = result
        else:
            url = result
        node = nodes.raw("", u"<a href="{url}">{title}</a>".format(title=title, url=html_escape(url)), format="html")
        return [node], []
github naftaliharris / tauthon / Doc / tools / sphinxext / pyspecific.py View on Github external
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
    issue = utils.unescape(text)
    text = 'issue ' + issue
    refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
    return [refnode], []
github leo-editor / leo-editor / leo / extensions / docutils / core.py View on Github external
def report_Exception(self, error):
        if isinstance(error, utils.SystemMessage):
            self.report_SystemMessage(error)
        elif isinstance(error, UnicodeEncodeError):
            self.report_UnicodeError(error)
        elif isinstance(error, io.InputError):
            self._stderr.write(u'Unable to open source file for reading:\n'
                               u'  %s\n' % ErrorString(error))
        elif isinstance(error, io.OutputError):
            self._stderr.write(
                u'Unable to open destination file for writing:\n'
                u'  %s\n' % ErrorString(error))
        else:
            print(u'%s' % ErrorString(error), file=self._stderr)
            print(("""\
Exiting due to error.  Use "--traceback" to diagnose.
Please report errors to .
Include "--traceback" output, Docutils version (%s [%s]),
github pinax / pinax / site-packages / docutils-0.4 / docutils / transforms / peps.py View on Github external
refpep, refpep,
                        refuri=(self.document.settings.pep_base_url
                                + self.pep_url % pepno)))
                    newbody.append(space)
                para[:] = newbody[:-1] # drop trailing space
            elif name == 'last-modified':
                utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
                if cvs_url:
                    date = para.astext()
                    para[:] = [nodes.reference('', date, refuri=cvs_url)]
            elif name == 'content-type':
                pep_type = para.astext()
                uri = self.document.settings.pep_base_url + self.pep_url % 12
                para[:] = [nodes.reference('', pep_type, refuri=uri)]
            elif name == 'version' and len(body):
                utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)