How to use the docutils.parsers.rst.directives.register_directive 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 Source-Python-Dev-Team / Source.Python / addons / source-python / packages / site-packages / sphinx / application.py View on Github external
def add_directive(self, name, obj, content=None, arguments=None, **options):
        self.debug('[app] adding directive: %r',
                   (name, obj, content, arguments, options))
        if name in directives._directives:
            self.warn('while setting up extension %s: directive %r is '
                      'already registered, it will be overridden' %
                      (self._setting_up_extension[-1], name),
                      type='app', subtype='add_directive')
        directives.register_directive(
            name, self._directive_helper(obj, content, arguments, **options))
github FelixHenninger / lab.js / docs / _extensions / rst_video.py View on Github external
def setup(app):
    directives.register_directive('youtube', Youtube)
    directives.register_directive('vimeo', Vimeo)

    directives.register_directive('video', RawVideo)
    app.add_config_value('video_files', [], 'html')

    app.connect('builder-inited', on_builder_init)
    app.connect('html-collect-pages', on_html_collect_pages)
github pv / pydocweb / docweb / rst_sphinx.py View on Github external
dd = nodes.definition()
    di += dd
    
    if target:
        dt['ids'] += [rst.make_target_id(target)]

    dl['classes'] += [dirname, 'code-item']
    _nested_parse(state, content, dd)
    
    return [dl]

codeitem_directive.arguments = (1, 0, True)
codeitem_directive.content = True

register_directive('moduleauthor', codeitem_directive)
register_directive('cfunction', codeitem_directive)
register_directive('cmember', codeitem_directive)
register_directive('cmacro', codeitem_directive)
register_directive('ctype', codeitem_directive)
register_directive('cvar', codeitem_directive)
register_directive('data', codeitem_directive)
register_directive('exception', codeitem_directive)
register_directive('function', codeitem_directive)
register_directive('class', codeitem_directive)
register_directive('const', codeitem_directive)
register_directive('attribute', codeitem_directive)
register_directive('method', codeitem_directive)
register_directive('staticmethod', codeitem_directive)
register_directive('opcode', codeitem_directive)
register_directive('cmdoption', codeitem_directive)
register_directive('envvar', codeitem_directive)
github sphinx-doc / sphinx / sphinx / directives / desc.py View on Github external
# Note: the target directive is not registered here, it is used by the
# application when registering additional xref types.

_ = lambda x: x

# Generic cross-reference types; they can be registered in the application;
# the directives are either desc_directive or target_directive.
additional_xref_types = {
    # directive name: (role name, index text, function to parse the desc node)
    'envvar': ('envvar', _('environment variable; %s'), None),
}

del _


directives.register_directive('describe', directive_dwim(DescDirective))

directives.register_directive('function', directive_dwim(ModulelevelDesc))
directives.register_directive('data', directive_dwim(ModulelevelDesc))
directives.register_directive('class', directive_dwim(ClasslikeDesc))
directives.register_directive('exception', directive_dwim(ClasslikeDesc))
directives.register_directive('method', directive_dwim(ClassmemberDesc))
directives.register_directive('classmethod', directive_dwim(ClassmemberDesc))
directives.register_directive('staticmethod', directive_dwim(ClassmemberDesc))
directives.register_directive('attribute', directive_dwim(ClassmemberDesc))

directives.register_directive('cfunction', directive_dwim(CDesc))
directives.register_directive('cmember', directive_dwim(CDesc))
directives.register_directive('cmacro', directive_dwim(CDesc))
directives.register_directive('ctype', directive_dwim(CDesc))
directives.register_directive('cvar', directive_dwim(CDesc))
github renatopp / pyramid-blog / blog / blog / libs / rest / reSTpygments.py View on Github external
try:
        lexer = get_lexer_by_name(arguments[0])
    except ValueError:
        # no lexer found - use the text one instead of an exception
        lexer = TextLexer()
    # take an arbitrary option if more than one is given
    formatter = options and VARIANTS[options.keys()[0]] or DEFAULT
    parsed = highlight(u'\n'.join(content), lexer, formatter)
    parsed = '<div class="codeblock">%s</div>' % parsed
    return [nodes.raw('', parsed, format='html')]

pygments_directive.arguments = (1, 0, 1)
pygments_directive.content = 1
pygments_directive.options = dict([(key, directives.flag) for key in VARIANTS])

directives.register_directive('code-block', pygments_directive)
github pv / pydocweb / docweb / rst_sphinx.py View on Github external
register_directive('versionchanged', blurb_directive(
    lambda d, c: ["    *Changed in version %s*:" % c[0]] + _indent(c[1:])))
register_directive('seealso', blurb_directive(
    lambda d, c: ["    .. admonition:: See also", ""] + _indent(c, 7),
    classes=[(0,0,'seealso')]))
register_directive('rubric', blurb_directive(
    lambda d, c: ["**%s**" % u" ".join(c)]))
register_directive('centered', admonition_directive)
register_directive('glossary', admonition_directive)
register_directive('productionlist', admonition_directive)
register_directive('sectionauthor', admonition_directive)

register_directive('literalinclude', lit_admonition_directive)
register_directive('code-block', blurb_directive(
    lambda d, c: ["::", ""] + _indent(c[1:], 4)))
register_directive('sourcecode', blurb_directive(
    lambda d, c: ["::", ""] + _indent(c[1:], 4)))
register_directive('doctest', blurb_directive(
    lambda d, c: ["::", ""] + _indent(c[1:], 4)))

#------------------------------------------------------------------------------
# class:: etc.
#------------------------------------------------------------------------------

_CALLABLE_RE = re.compile(r"^(?P<pre>.*?)(?P[a-zA-Z0-9_.]*?)(?P[a-zA-Z0-9_]+)\s*\((?P.*?)\)(?P\s*-&gt;.*?)?$")
_OTHER_RE = re.compile(r"^(?P<pre>.*?)(?P[a-zA-Z0-9_.]*?)(?P[a-zA-Z0-9_]+)\s*$")

def codeitem_directive(dirname, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):
    if not content:
        content = [u""]
</pre></pre>
github fasterthanlime / ooc-docs / sphinx_ooc / desc.py View on Github external
return name
            if modname and add_modules:
                return _('%s (%s/%s field)') % (attrname, modname, clsname)
            else:
                return _('%s (%s field)') % (attrname, clsname)
        else:
            return ''

    def before_content(self):
        OOCDesc.before_content(self)
        if self.names and self.names[-1][1] and not self.env.currclass:
            self.env.currclass = self.names[-1][1].strip('/ ')
            self.clsname_set = True


directives.register_directive('describe', directive_dwim(DescDirective))

directives.register_directive('function', directive_dwim(ModulelevelDesc))
directives.register_directive('var', directive_dwim(ModulelevelDesc))
directives.register_directive('class', directive_dwim(ClasslikeDesc))
directives.register_directive('cover', directive_dwim(ClasslikeDesc))

directives.register_directive('method', directive_dwim(ClassmemberDesc))
directives.register_directive('staticmethod', directive_dwim(ClassmemberDesc))
directives.register_directive('field', directive_dwim(ClassmemberDesc))
github mosra / m.css / plugins / m / components.py View on Github external
rst.directives.register_directive('block-info', InfoBlock)
    rst.directives.register_directive('block-dim', DimBlock)
    rst.directives.register_directive('block-flat', FlatBlock)

    rst.directives.register_directive('frame', Frame)
    rst.directives.register_directive('code-figure', CodeFigure)
    rst.directives.register_directive('console-figure', ConsoleFigure)
    rst.directives.register_directive('math-figure', MathFigure)
    rst.directives.register_directive('graph-figure', GraphFigure)

    rst.directives.register_directive('text-default', DefaultText)
    rst.directives.register_directive('text-primary', PrimaryText)
    rst.directives.register_directive('text-success', SuccessText)
    rst.directives.register_directive('text-warning', WarningText)
    rst.directives.register_directive('text-danger', DangerText)
    rst.directives.register_directive('text-info', InfoText)
    rst.directives.register_directive('text-dim', DimText)

    rst.directives.register_directive('button-default', DefaultButton)
    rst.directives.register_directive('button-primary', PrimaryButton)
    rst.directives.register_directive('button-success', SuccessButton)
    rst.directives.register_directive('button-warning', WarningButton)
    rst.directives.register_directive('button-danger', DangerButton)
    rst.directives.register_directive('button-info', InfoButton)
    rst.directives.register_directive('button-dim', DimButton)
    rst.directives.register_directive('button-flat', FlatButton)

    rst.roles.register_canonical_role('label-default', label_default)
    rst.roles.register_canonical_role('label-primary', label_primary)
    rst.roles.register_canonical_role('label-success', label_success)
    rst.roles.register_canonical_role('label-warning', label_warning)
    rst.roles.register_canonical_role('label-danger', label_danger)
github Anomareh / mynt / mynt / parsers / docutils.py View on Github external
code = nodes.literal(classes=classes)
        code.attributes['data-lang'] = language
        self.add_name(pre)
        self.add_name(code)

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

        pre += code

        return [pre]

directives.register_directive('code', _CodeBlock)


class _Translator(HTMLTranslator):
    def set_first_last(self, node):
        pass

    def visit_bullet_list(self, node):
        attributes = {}
        self.context.append((self.compact_simple, self.compact_p))
        self.compact_p = None
        self.compact_simple = self.is_compactable(node)
        self.body.append(self.starttag(node, 'ul', '', **attributes))

    def visit_definition(self, node):
        self.body.append('')
        self.body.append(self.starttag(node, 'dd', ''))
github pv / pydocweb / moin-rst-latex / moin_rst_latex.py View on Github external
math_directive.arguments = (
    1, # number of required arguments
    1, # number of optional arguments
    False # whether final argument can contain whitespace
)
math_directive.options = {
}
math_directive.arguments = (
    0, # number of required arguments
    0, # number of optional arguments
    False # whether final argument can contain whitespace
)
math_directive.options = {}
math_directive.content = True # whether content is allowed

docutils.parsers.rst.directives.register_directive('math', math_directive)
docutils.parsers.rst.roles.register_local_role('math', math_role)