How to use the docutils.parsers.rst.directives.unchanged 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 grzegorzmazur / yacas / docs / util / yacasdomain.py View on Github external
# and treat the whole argument list as one argument, discarding the
        # already partially populated paramlist node
        signode += addnodes.desc_parameterlist()
        signode[-1] += addnodes.desc_parameter(arglist, arglist)
    else:
        signode += paramlist


class YacasObject(ObjectDescription):
    """
    Description of a general Yacas object.
    """
    option_spec = {
        'noindex': directives.flag,
        'module': directives.unchanged,
        'annotation': directives.unchanged,
    }

    doc_field_types = [
        Field('parameter', label=_('Arguments'), names=('param')),
        Field('returnvalue', label=_('Returns'), has_arg=False,
              names=('returns', 'return')),
    ]

    def get_signature_prefix(self, sig):
        """May return a prefix to put before the object name in the
        signature.
        """
        return ''

    def needs_arglist(self):
        """May return true if an empty argument list is to be generated even if
github hsnr-gamera / gamera / gamera / gui / gui_util.py View on Github external
# If we don't have docutils, we just wrap the docstring
   # in <pre> tags
   def docstring_to_html(docstring):
      return "<pre>%s</pre>" % docstring
else:
   # Some docstrings may contain SilverCity ".. code::" blocks.
   # Since wx.html.HtmlWindow does not support CSS, it therefore
   # can not properly handle SilverCity's syntax coloring.  So instead,
   # we create a "dummy" code block handler that simply uses <pre>   def code_block(name, arguments, options, content, lineno,
                  content_offset, block_text, state, state_machine ):
      html = '\n<pre>%s</pre>\n' % "\n".join(content)
      raw = docutils.nodes.raw('', html, format = 'html')
      return [raw]
   code_block.arguments = (1,0,0)
   code_block.options = {'language' : docutils.parsers.rst.directives.unchanged }
   code_block.content = 1
   docutils.parsers.rst.directives.register_directive( 'code', code_block )

   def docstring_to_html(docstring):
      try:
         corrected = docstring.replace("*args", "\*args")
         corrected = corrected.replace("**kwargs", "\*\*kwargs")
         html = docutils.core.publish_string(corrected, writer_name="html")
      except Exception, e:
         html = '''<pre>%s</pre><br><font size="1"><pre>%s</pre></font>''' % (docstring, str(e))
      return html.decode("utf-8")
</pre></pre>
github VACUMM / sphinx-fortran / sphinxfortran / fortran_domain.py View on Github external
May return a prefix to put before the object name in the signature.
        """
        return self.objtype + ' '


class FortranField(Directive):
    """
    Directive to describe a change/addition/deprecation in a specific version.
    """

    has_content = True
    required_arguments = 1
    optional_arguments = 0
    final_argument_whitespace = True
    option_spec = {
        'type': directives.unchanged,
        'shape': parse_shape,
        'attrs': directives.unchanged,
    }

    def run(self):
        from docutils import nodes
        node = nodes.paragraph()
        node += addnodes.desc_name(self.arguments[0], self.arguments[0])
        shape = self.options.get('shape')
        if shape:
            #node += nodes.Text(shape, shape)
            add_shape(node, shape)
        type = self.options.get('type')
        attrs = self.options.get('attrs')
        if type or attrs:
            node += nodes.Text(' :: ', ' :: ')
github mdolab / openconcept / docs / _exts / embed_code.py View on Github external
for the class or method desired.

    By default, docstrings will be kept in the embedded code. There is an option
    to the directive to strip the docstrings:

    .. embed-code::
        openmdao.test.whatever.method
        :strip-docstrings:
    """

    # must have at least one directive for this to work
    required_arguments = 1
    has_content = True

    option_spec = {
        'strip-docstrings': unchanged,
        'layout': unchanged,
        'scale': unchanged,
        'align': unchanged,
    }

    def run(self):
        global _plot_count

        allowed_layouts = set(['code', 'output', 'interleave', 'plot'])

        path = self.arguments[0]
        is_script = path.endswith('.py')

        source, indent, module, class_ = get_source_code(path)
        # except Exception as err:
        #     raise SphinxError(str(err))
github RunestoneInteractive / RunestoneComponents / runestone / spreadsheet / spreadsheet.py View on Github external
:fromcsv: path/to/csv/file
        :colwidths: list of column widths
        :coltitles: list of column names
        :mindimensions: mincols, minrows  -- minDimensions:[10,5]

        A1,B1,C1,D1...
        A2,B2,C2,D2...
    """

    required_arguments = 1
    optional_arguments = 5
    has_content = True
    option_spec = RunestoneIdDirective.option_spec.copy()
    option_spec.update(
        {
            "fromcsv": directives.unchanged,
            "colwidths": directives.unchanged,
            "coltitles": directives.unchanged,
            "mindimensions": directives.unchanged,
        }
    )

    def run(self):
        super(SpreadSheet, self).run()
        env = self.state.document.settings.env

        self.options["divid"] = self.arguments[0].strip()

        if "====" in self.content:
            idx = self.content.index("====")
            suffix = self.content[idx + 1 :]
            self.options["asserts"] = suffix
github bogdanvuk / bdp / bdp / sphinxext / bdpfigure.py View on Github external
from docutils.parsers.rst.directives.images import Figure
from sphinx.util.osutil import ensuredir
from subprocess import Popen, PIPE
import os, os.path, tempfile, shutil
from bdp.render import render
from hashlib import sha1 as sha
from shutil import copyfile

class BdpFigureDirective(Figure):

    required_arguments = 0
    optional_arguments = 1
    has_content = True

    option_spec = Figure.option_spec.copy()
    option_spec['caption'] = directives.unchanged

    def run(self):

        print('Here!')
        print(self.arguments)
        
        text = '\n'.join(self.content)
        try:
            filename = self.arguments[0]
        except:
            filename = None
        
        self.arguments = ['']
        
        try:
            self.content[0] = self.options['caption']
github trini / u-boot / doc / sphinx / kfigure.py View on Github external
*figure*  directive, plus option ``caption``.  If ``caption`` has a
    value, a figure node with the *caption* is inserted. If not, a image node is
    inserted.

    The KernelRender directive wraps the text of the directive into a
    literal_block node and wraps it into a kernel_render node. See
    ``visit_kernel_render``.
    """
    has_content = True
    required_arguments = 1
    optional_arguments = 0
    final_argument_whitespace = False

    # earn options from 'figure'
    option_spec = Figure.option_spec.copy()
    option_spec['caption'] = directives.unchanged

    def run(self):
        return [self.build_node()]

    def build_node(self):

        srclang = self.arguments[0].strip()
        if srclang not in RENDER_MARKUP_EXT.keys():
            return [self.state_machine.reporter.warning(
                'Unknown source language "%s", use one of: %s.' % (
                    srclang, ",".join(RENDER_MARKUP_EXT.keys())),
                line=self.lineno)]

        code = '\n'.join(self.content)
        if not code.strip():
            return [self.state_machine.reporter.warning(
github Abjad / abjad / abjad / ext / sphinx.py View on Github external
def setup_sphinx(cls, app):
        app.add_node(
            cls.lilypond_block,
            html=[cls.visit_block_html, None],
            latex=[cls.visit_block_latex, None],
            text=[cls.visit_block_text, cls.depart_block_text],
        )
        cls.add_option("lilypond/no-stylesheet", directives.flag)
        cls.add_option("lilypond/no-trim", directives.flag)
        cls.add_option("lilypond/pages", directives.unchanged)
        cls.add_option("lilypond/stylesheet", directives.unchanged)
        cls.add_option("lilypond/with-columns", int)
github aquavitae / rst2pdf-py3-dev / rst2pdf / pygments_code_block_directive.py View on Github external
return [code_block]


# Register Directive
# ------------------
# ::

code_block_directive.arguments = (1, 0, 1)
code_block_directive.content = 1
code_block_directive.options = {'include': directives.unchanged_required,
                                'start-at': directives.unchanged_required,
                                'end-at': directives.unchanged_required,
                                'start-after': directives.unchanged_required,
                                'end-before': directives.unchanged_required,
                                'linenos': directives.unchanged,
                                }

directives.register_directive('code-block', code_block_directive)


# .. _doctutils: http://docutils.sf.net/
# .. _pygments: http://pygments.org/
# .. _Using Pygments in ReST documents: http://pygments.org/docs/rstdirective/
# .. _proof of concept:
#      http://article.gmane.org/gmane.text.docutils.user/3689
#
# Test output
# -----------
#
# If called from the command line, call the docutils publisher to render the
# input::