当前位置: 首页>>代码示例>>Python>>正文


Python nodes.literal_block方法代码示例

本文整理汇总了Python中docutils.nodes.literal_block方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.literal_block方法的具体用法?Python nodes.literal_block怎么用?Python nodes.literal_block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.nodes的用法示例。


在下文中一共展示了nodes.literal_block方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def apply(self):
        pending = self.startnode
        parent = pending.parent
        child = pending
        while parent:
            # Check for appropriate following siblings:
            for index in range(parent.index(child) + 1, len(parent)):
                element = parent[index]
                if (isinstance(element, nodes.Invisible) or
                    isinstance(element, nodes.system_message)):
                    continue
                element['classes'] += pending.details['class']
                pending.parent.remove(pending)
                return
            else:
                # At end of section or container; apply to sibling
                child = parent
                parent = parent.parent
        error = self.document.reporter.error(
            'No suitable element following "%s" directive'
            % pending.details['directive'],
            nodes.literal_block(pending.rawsource, pending.rawsource),
            line=pending.line)
        pending.replace_self(error) 
开发者ID:skarlekar,项目名称:faces,代码行数:26,代码来源:misc.py

示例2: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def run(self):
        if not self.arguments:
            if '' in roles._roles:
                # restore the "default" default role
                del roles._roles['']
            return []
        role_name = self.arguments[0]
        role, messages = roles.role(role_name, self.state_machine.language,
                                    self.lineno, self.state.reporter)
        if role is None:
            error = self.state.reporter.error(
                'Unknown interpreted text role "%s".' % role_name,
                nodes.literal_block(self.block_text, self.block_text),
                line=self.lineno)
            return messages + [error]
        roles._roles[''] = role
        # @@@ should this be local to the document, not the parser?
        return messages 
开发者ID:skarlekar,项目名称:faces,代码行数:20,代码来源:misc.py

示例3: get_column_widths

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def get_column_widths(self, max_cols):
        if type(self.widths) == list:
            if len(self.widths) != max_cols:
                error = self.state_machine.reporter.error(
                    '"%s" widths do not match the number of columns in table '
                    '(%s).' % (self.name, max_cols), nodes.literal_block(
                    self.block_text, self.block_text), line=self.lineno)
                raise SystemMessagePropagation(error)
            col_widths = self.widths
        elif max_cols:
            col_widths = [100 // max_cols] * max_cols
        else:
            error = self.state_machine.reporter.error(
                'No table data detected in CSV file.', nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            raise SystemMessagePropagation(error)
        if self.widths == 'auto':
            widths = 'auto'
        elif self.widths: # "grid" or list of integers
            widths = 'given'
        else:
            widths = self.widths
        return widths, col_widths 
开发者ID:skarlekar,项目名称:faces,代码行数:25,代码来源:tables.py

示例4: paragraph

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def paragraph(self, lines, lineno):
        """
        Return a list (paragraph & messages) & a boolean: literal_block next?
        """
        data = '\n'.join(lines).rstrip()
        if re.search(r'(?<!\\)(\\\\)*::$', data):
            if len(data) == 2:
                return [], 1
            elif data[-3] in ' \n':
                text = data[:-3].rstrip()
            else:
                text = data[:-1]
            literalnext = 1
        else:
            text = data
            literalnext = 0
        textnodes, messages = self.inline_text(text, lineno)
        p = nodes.paragraph(data, '', *textnodes)
        p.source, p.line = self.state_machine.get_source_and_line(lineno)
        return [p] + messages, literalnext 
开发者ID:skarlekar,项目名称:faces,代码行数:22,代码来源:states.py

示例5: line

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def line(self, match, context, next_state):
        """Section title overline or transition marker."""
        if self.state_machine.match_titles:
            return [match.string], 'Line', []
        elif match.string.strip() == '::':
            raise statemachine.TransitionCorrection('text')
        elif len(match.string.strip()) < 4:
            msg = self.reporter.info(
                'Unexpected possible title overline or transition.\n'
                "Treating it as ordinary text because it's so short.",
                line=self.state_machine.abs_line_number())
            self.parent += msg
            raise statemachine.TransitionCorrection('text')
        else:
            blocktext = self.state_machine.line
            msg = self.reporter.severe(
                  'Unexpected section title or transition.',
                  nodes.literal_block(blocktext, blocktext),
                  line=self.state_machine.abs_line_number())
            self.parent += msg
            return [], next_state, [] 
开发者ID:skarlekar,项目名称:faces,代码行数:23,代码来源:states.py

示例6: eof

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def eof(self, context):
        if context:
            src, srcline = self.state_machine.get_source_and_line(
                                                        self.initial_lineno)
            text = '\n'.join(context)
            literal_block = nodes.literal_block(text, text)
            literal_block.source = src
            literal_block.line = srcline
            self.parent += literal_block
        else:
            self.parent += self.reporter.warning(
                'Literal block expected; none found.',
                line=self.state_machine.abs_line_number())
                # src not available, because statemachine.input_lines is empty
            self.state_machine.previous_line()
        self.parent += self.messages
        return [] 
开发者ID:skarlekar,项目名称:faces,代码行数:19,代码来源:states.py

示例7: visit_literal

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def visit_literal(self, node):
        # special case: "code" role
        classes = node.get('classes', [])
        if 'code' in classes:
            # filter 'code' from class arguments
            node['classes'] = [cls for cls in classes if cls != 'code']
            self.body.append(self.starttag(node, 'code', ''))
            return
        self.body.append(
            self.starttag(node, 'span', '', CLASS='docutils literal'))
        text = node.astext()
        # remove hard line breaks (except if in a parsed-literal block)
        if not isinstance(node.parent, nodes.literal_block):
            text = text.replace('\n', ' ')
        # Protect text like ``--an-option`` and the regular expression
        # ``[+]?(\d+(\.\d*)?|\.\d+)`` from bad line wrapping
        for token in self.words_and_spaces.findall(text):
            if token.strip() and self.sollbruchstelle.search(token):
                self.body.append('<span class="pre">%s</span>'
                                    % self.encode(token))
            else:
                self.body.append(self.encode(token))
        self.body.append('</span>')
        # Content already processed:
        raise nodes.SkipNode 
开发者ID:skarlekar,项目名称:faces,代码行数:27,代码来源:_html_base.py

示例8: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def run(self):
        if not self.content:
            error = self.state_machine.reporter.error(
                'The "%s" directive is empty; content required.' % self.name,
                nodes.literal_block(self.block_text, self.block_text),
                line=self.lineno)
            return [error]
        title, messages = self.make_title()
        node = nodes.Element()          # anonymous container for parsing
        self.state.nested_parse(self.content, self.content_offset, node)
        try:
            num_cols, widths, col_widths = self.check_list_content(node)
            table_data = [[item.children for item in row_list[0]]
                          for row_list in node[0]]
            header_rows = self.options.get('header-rows', 0)
            stub_columns = self.options.get('stub-columns', 0)
            self.check_table_dimensions(table_data, header_rows, stub_columns)
        except SystemMessagePropagation, detail:
            return [detail.args[0]] 
开发者ID:skarlekar,项目名称:faces,代码行数:21,代码来源:tables.py

示例9: is_pycode

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def is_pycode(node: nodes.literal_block) -> bool:
        """Checks if the node is literal block of python"""
        if node.rawsource != node.astext():
            return False  # skip parsed-literal node

        language = node.get("language")
        if language in ("py", "py3", "python", "python3", "default"):
            return True
        elif language == "guess":
            # noinspection PyBroadException
            try:
                lexer = guess_lexer(node.rawsource)
                return isinstance(lexer, (PythonLexer, Python3Lexer))
            except Exception:  # pylint: disable=broad-except
                pass

        return False 
开发者ID:apache,项目名称:airflow,代码行数:19,代码来源:removemarktransform.py

示例10: get_column_widths

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def get_column_widths(self, max_cols):
        if type(self.widths) == list:
            if len(self.widths) != max_cols:
                error = self.state_machine.reporter.error(
                    '"%s" widths do not match the number of columns in table '
                    '(%s).' % (self.name, max_cols), nodes.literal_block(
                    self.block_text, self.block_text), line=self.lineno)
                raise SystemMessagePropagation(error)
            col_widths = self.widths
        elif max_cols:
            col_widths = [100 // max_cols] * max_cols
        else:
            error = self.state_machine.reporter.error(
                'No table data detected in CSV file.', nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            raise SystemMessagePropagation(error)
        return col_widths 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:tables.py

示例11: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def run(self):
        document = self.state.document
        env = document.settings.env
        _ , wd = env.relfn2path(example_dir)
        prog = self.arguments[0]
        out = subprocess.check_output(['python3', '-u', prog], cwd=wd, 
                                      stderr=subprocess.STDOUT,
                                      universal_newlines=True)
        out = '$ python {}\n{}'.format(prog, out)
        ret = [nodes.literal_block(out, out)]
        return ret 
开发者ID:myhdl,项目名称:myhdl,代码行数:13,代码来源:myhdldoctools.py

示例12: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def run(self):
        env = self.state.document.settings.env

        targetid = "pdvega-plot-{0}".format(env.new_serialno('pdvega-plot'))
        targetnode = nodes.target('', '', ids=[targetid])

        code = '\n'.join(self.content)

        # Here we cache the code for use in later setup
        if not hasattr(env, 'pdvega_plot_setup'):
            env.pdvega_plot_setup = []
        env.pdvega_plot_setup.append({
            'docname': env.docname,
            'lineno': self.lineno,
            'code': code,
            'target': targetnode,
        })

        result = [targetnode]

        if 'show' in self.options:
            source_literal = nodes.literal_block(code, code)
            source_literal['language'] = 'python'
            result.append(source_literal)

        return result 
开发者ID:altair-viz,项目名称:pdvega,代码行数:28,代码来源:pdvegaplot.py

示例13: parsemeta

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def parsemeta(self, match):
        name = self.parse_field_marker(match)
        indented, indent, line_offset, blank_finish = \
              self.state_machine.get_first_known_indented(match.end())
        node = self.meta()
        pending = nodes.pending(components.Filter,
                                {'component': 'writer',
                                 'format': 'html',
                                 'nodes': [node]})
        node['content'] = ' '.join(indented)
        if not indented:
            line = self.state_machine.line
            msg = self.reporter.info(
                  'No content for meta tag "%s".' % name,
                  nodes.literal_block(line, line))
            return msg, blank_finish
        tokens = name.split()
        try:
            attname, val = utils.extract_name_value(tokens[0])[0]
            node[attname.lower()] = val
        except utils.NameValueError:
            node['name'] = tokens[0]
        for token in tokens[1:]:
            try:
                attname, val = utils.extract_name_value(token)[0]
                node[attname.lower()] = val
            except utils.NameValueError as detail:
                line = self.state_machine.line
                msg = self.reporter.error(
                      'Error parsing meta tag attribute "%s": %s.'
                      % (token, detail), nodes.literal_block(line, line))
                return msg, blank_finish
        self.document.note_pending(pending)
        return pending, blank_finish 
开发者ID:skarlekar,项目名称:faces,代码行数:36,代码来源:html.py

示例14: check_table_dimensions

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def check_table_dimensions(self, rows, header_rows, stub_columns):
        if len(rows) < header_rows:
            error = self.state_machine.reporter.error(
                '%s header row(s) specified but only %s row(s) of data '
                'supplied ("%s" directive).'
                % (header_rows, len(rows), self.name), nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            raise SystemMessagePropagation(error)
        if len(rows) == header_rows > 0:
            error = self.state_machine.reporter.error(
                'Insufficient data supplied (%s row(s)); no data remaining '
                'for table body, required by "%s" directive.'
                % (len(rows), self.name), nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            raise SystemMessagePropagation(error)
        for row in rows:
            if len(row) < stub_columns:
                error = self.state_machine.reporter.error(
                    '%s stub column(s) specified but only %s columns(s) of '
                    'data supplied ("%s" directive).' %
                    (stub_columns, len(row), self.name), nodes.literal_block(
                    self.block_text, self.block_text), line=self.lineno)
                raise SystemMessagePropagation(error)
            if len(row) == stub_columns > 0:
                error = self.state_machine.reporter.error(
                    'Insufficient data supplied (%s columns(s)); no data remaining '
                    'for table body, required by "%s" directive.'
                    % (len(row), self.name), nodes.literal_block(
                    self.block_text, self.block_text), line=self.lineno)
                raise SystemMessagePropagation(error) 
开发者ID:skarlekar,项目名称:faces,代码行数:32,代码来源:tables.py

示例15: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal_block [as 别名]
def run(self):
        if not self.content:
            warning = self.state_machine.reporter.warning(
                'Content block expected for the "%s" directive; none found.'
                % self.name, nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            return [warning]
        title, messages = self.make_title()
        node = nodes.Element()          # anonymous container for parsing
        self.state.nested_parse(self.content, self.content_offset, node)
        if len(node) != 1 or not isinstance(node[0], nodes.table):
            error = self.state_machine.reporter.error(
                'Error parsing content block for the "%s" directive: exactly '
                'one table expected.' % self.name, nodes.literal_block(
                self.block_text, self.block_text), line=self.lineno)
            return [error]
        table_node = node[0]
        table_node['classes'] += self.options.get('class', [])
        if 'align' in self.options:
            table_node['align'] = self.options.get('align')
        tgroup = table_node[0]
        if type(self.widths) == list:
            colspecs = [child for child in tgroup.children
                        if child.tagname == 'colspec']
            for colspec, col_width in zip(colspecs, self.widths):
                colspec['colwidth'] = col_width
        # @@@ the colwidths argument for <tgroup> is not part of the
        # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm)
        # and hence violates the docutils.dtd.
        if self.widths == 'auto':
            table_node['classes'] += ['colwidths-auto']
        elif self.widths: # "grid" or list of integers
            table_node['classes'] += ['colwidths-given']
        self.add_name(table_node)
        if title:
            table_node.insert(0, title)
        return [table_node] + messages 
开发者ID:skarlekar,项目名称:faces,代码行数:39,代码来源:tables.py


注:本文中的docutils.nodes.literal_block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。