def emph_literal_role(typ,
                      rawtext,
                      text,
                      lineno,
                      inliner,
                      options={},
                      content=[]):
    """replacement for sphinx's ``:samp:`` role handler.
    this is a bit stricter in it's parsing, and allows escaping of literal
    ``{`` and ``}`` characters.
    """
    def make_error(pos, value):
        value = "%s at char %d of %s" % (value, pos, rawtext)
        msg = inliner.reporter.error(value, line=lineno)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]

    text = utils.unescape(text)
    retnode = nodes.literal(role=typ.lower(), classes=[typ])
    buffer = u("")  # contains text being accumulated for next node
    in_escape = False  # True if next char is part of escape sequence
    in_var = False  # True if parsing variable section instead of plain text
    var_start = None  # marks start of var section if in_var is True
    i = 0
    for c in text:
        i += 1
        if in_escape:
            # parse escape sequence
            if c in ru("{}\\"):
                buffer += c
                in_escape = False
            else:
                return make_error(i - 2,
                                  "unknown samp-escape '\\\\%s'" % (c, ))
        elif c == ru("\\"):
            # begin escape sequence
            in_escape = True
            i += 1  # account for extra escape char in rawtext
        elif in_var:
            # parsing variable section
            if c == u("{"):
                return make_error(i, "unescaped '{'")
            elif c == u("}"):
                # finalize variable section, return to plaintext
                if not buffer:
                    return make_error(i - 1, "empty variable section")
                retnode += nodes.emphasis(buffer, buffer)
                buffer = u("")
                in_var = False
            else:
                buffer += c
        else:
            # parsing plaintext section
            if c == u("{"):
                # finalize plaintext section, start variable section
                if buffer:
                    retnode += nodes.Text(buffer, buffer)
                buffer = u("")
                in_var = True
                var_start = i
            elif c == u("}"):
                return make_error(i, "unescaped '}'")
            else:
                buffer += c
    if in_escape:
        return make_error(i, "unterminated samp-escape sequence")
    elif in_var:
        return make_error(var_start, "unterminated variable section")
    elif buffer:
        retnode += nodes.Text(buffer, buffer)
    return [retnode], []
예제 #2
0
def emph_literal_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
    """replacement for sphinx's ``:samp:`` role handler.
    this is a bit stricter in it's parsing, and allows escaping of literal
    ``{`` and ``}`` characters.
    """

    def make_error(pos, value):
        value = "%s at char %d of %s" % (value, pos, rawtext)
        msg = inliner.reporter.error(value, line=lineno)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]

    text = utils.unescape(text)
    retnode = nodes.literal(role=typ.lower(), classes=[typ])
    buffer = u("")  # contains text being accumulated for next node
    in_escape = False  # True if next char is part of escape sequence
    in_var = False  # True if parsing variable section instead of plain text
    var_start = None  # marks start of var section if in_var is True
    i = 0
    for c in text:
        i += 1
        if in_escape:
            # parse escape sequence
            if c in ru("{}\\"):
                buffer += c
                in_escape = False
            else:
                return make_error(i - 2, "unknown samp-escape '\\\\%s'" % (c,))
        elif c == ru("\\"):
            # begin escape sequence
            in_escape = True
            i += 1  # account for extra escape char in rawtext
        elif in_var:
            # parsing variable section
            if c == u("{"):
                return make_error(i, "unescaped '{'")
            elif c == u("}"):
                # finalize variable section, return to plaintext
                if not buffer:
                    return make_error(i - 1, "empty variable section")
                retnode += nodes.emphasis(buffer, buffer)
                buffer = u("")
                in_var = False
            else:
                buffer += c
        else:
            # parsing plaintext section
            if c == u("{"):
                # finalize plaintext section, start variable section
                if buffer:
                    retnode += nodes.Text(buffer, buffer)
                buffer = u("")
                in_var = True
                var_start = i
            elif c == u("}"):
                return make_error(i, "unescaped '}'")
            else:
                buffer += c
    if in_escape:
        return make_error(i, "unterminated samp-escape sequence")
    elif in_var:
        return make_error(var_start, "unterminated variable section")
    elif buffer:
        retnode += nodes.Text(buffer, buffer)
    return [retnode], []
예제 #3
0
파일: conf.py 프로젝트: yyccxx1991/pymaclab
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix of source filenames.
source_suffix = '.rst'

# The encoding of source files.
source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'contents'
index_doc = 'index'

# General information about the project.
project = u("PyMacLab")
author = u('Eric M. Scheffel')
copyright = u('2010-2012, ') + author

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# version: The short X.Y version.
# release: The full version, including alpha/beta/rc tags.
from cloud_sptheme import __version__ as release
release = "0.95.9"
version = "0.95.9"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
예제 #4
0
파일: conf.py 프로젝트: 1zinnur9/pymaclab
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix of source filenames.
source_suffix = '.rst'

# The encoding of source files.
source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'contents'
index_doc = 'index'

# General information about the project.
project = u("PyMacLab")
author = u('Eric M. Scheffel')
copyright = u('2010-2012, ') + author

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# version: The short X.Y version.
# release: The full version, including alpha/beta/rc tags.
from cloud_sptheme import __version__ as release
release = "0.95.9"
version = "0.95.9"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.