當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.new_document方法代碼示例

本文整理匯總了Python中docutils.utils.new_document方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.new_document方法的具體用法?Python utils.new_document怎麽用?Python utils.new_document使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docutils.utils的用法示例。


在下文中一共展示了utils.new_document方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: preload

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def preload(self, filename, encoding='utf-8', errors='strict'):
        '''Preload a rst file to get its toctree and its title.

        The result will be stored in :attr:`toctrees` with the ``filename`` as
        key.
        '''

        with open(filename, 'rb') as fd:
            text = fd.read().decode(encoding, errors)
        # parse the source
        document = utils.new_document('Document', self._settings)
        self._parser.parse(text, document)
        # fill the current document node
        visitor = _ToctreeVisitor(document)
        document.walkabout(visitor)
        self.toctrees[filename] = visitor.toctree
        return text 
開發者ID:BillBillBillBill,項目名稱:Tickeys-linux,代碼行數:19,代碼來源:rst.py

示例2: _load_from_text

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def _load_from_text(self, *largs):
        try:
            # clear the current widgets
            self.content.clear_widgets()
            self.anchors_widgets = []
            self.refs_assoc = {}

            # parse the source
            document = utils.new_document('Document', self._settings)
            text = self.text
            if PY2 and type(text) is str:
                text = text.decode('utf-8')
            self._parser.parse(text, document)

            # fill the current document node
            visitor = _Visitor(self, document)
            document.walkabout(visitor)

            self.title = visitor.title or 'No title'
        except:
            Logger.exception('Rst: error while loading text') 
開發者ID:BillBillBillBill,項目名稱:Tickeys-linux,代碼行數:23,代碼來源:rst.py

示例3: renderList

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def renderList(l, markDownHelp, settings=None):
    """
    Given a list of reStructuredText or MarkDown sections, return a docutils node list
    """
    if len(l) == 0:
        return []
    if markDownHelp:
        return parseMarkDownBlock('\n\n'.join(l) + '\n')
    else:
        if settings is None:
            settings = OptionParser(components=(Parser,)).get_default_values()
        document = new_document(None, settings)
        Parser().parse('\n\n'.join(l) + '\n', document)
        return document.children 
開發者ID:rucio,項目名稱:rucio,代碼行數:16,代碼來源:ext.py

示例4: parse

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def parse(self):
        """Parse `self.input` into a document tree."""
        self.document = document = self.new_document()
        self.parser.parse(self.input, document)
        document.current_source = document.current_line = None 
開發者ID:skarlekar,項目名稱:faces,代碼行數:7,代碼來源:__init__.py

示例5: new_document

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def new_document(self):
        """Create and return a new empty document tree (root node)."""
        document = utils.new_document(self.source.source_path, self.settings)
        return document 
開發者ID:skarlekar,項目名稱:faces,代碼行數:6,代碼來源:__init__.py

示例6: build_row

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def build_row(item):
    """Return nodes.row with property description"""

    prop, propschema, required = item
    row = nodes.row()

    # Property

    row += nodes.entry("", nodes.paragraph(text=prop), classes=["vl-prop"])

    # Type
    str_type = type_description(propschema)
    par_type = nodes.paragraph()

    is_text = True
    for part in reClassDef.split(str_type):
        if part:
            if is_text:
                add_text(par_type, part)
            else:
                add_class_def(par_type, part)
        is_text = not is_text

    # row += nodes.entry('')
    row += nodes.entry("", par_type)  # , classes=["vl-type-def"]

    # Description
    md_parser = CommonMarkParser()
    # str_descr = "***Required.*** " if required else ""
    str_descr = ""
    str_descr += propschema.get("description", " ")
    doc_descr = utils.new_document("schema_description")
    md_parser.parse(str_descr, doc_descr)

    # row += nodes.entry('', *doc_descr.children, classes="vl-decsr")
    row += nodes.entry("", *doc_descr.children, classes=["vl-decsr"])

    return row 
開發者ID:altair-viz,項目名稱:altair,代碼行數:40,代碼來源:schematable.py

示例7: render

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def render(app, doctree, fromdocname):
    for node in doctree.traverse(YaqlDocNode):
        new_doc = utils.new_document('YAQL', doctree.settings)
        content = generate_doc(node.source)
        rst.Parser().parse(content, new_doc)
        node.replace_self(new_doc.children) 
開發者ID:openstack,項目名稱:yaql,代碼行數:8,代碼來源:yaqlautodoc.py

示例8: get_releases

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def get_releases(self):
        full_path = os.path.join(ROOT_DIR, "CHANGELOG.rst")
        with open(full_path) as f:
            changelog = f.read()
        with mock.patch.object(sys, "stderr"):
            parser = rst.Parser()
            settings = frontend.OptionParser(
                components=(rst.Parser,)).get_default_values()
            document = utils.new_document(changelog, settings)
            parser.parse(changelog, document)
            changelog = document.children
        if len(changelog) != 1:
            self.fail("'%s' file should contain one global section "
                      "with subsections for each release." % full_path)

        releases = []
        for node in changelog[0].children:
            if not isinstance(node, nodes.section):
                continue
            title = node.astext().split("\n", 1)[0]
            result = self.RE_RELEASE.match(title)
            if result:
                releases.append(result.groupdict()["version"])
        if not releases:
            self.fail("'%s' doesn't mention any releases..." % full_path)
        return releases 
開發者ID:openstack,項目名稱:rally-openstack,代碼行數:28,代碼來源:test_docker_readme.py

示例9: _parse_rst

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def _parse_rst(text):
    parser = rst.Parser()
    settings = frontend.OptionParser(
        components=(rst.Parser,)).get_default_values()
    document = utils.new_document(text, settings)
    parser.parse(text, document)
    return document.children 
開發者ID:openstack,項目名稱:rally-openstack,代碼行數:9,代碼來源:test_docstrings.py

示例10: document

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def document(self):
        if self._doc is None:
            # Use the rst parsers document output to do as much of the
            # validation as we can without resorting to custom logic (this
            # parser is what sphinx and others use anyway so it's hopefully
            # mature).
            parser_cls = docutils_parser.get_parser_class("rst")
            parser = parser_cls()
            defaults = {
                "halt_level": 5,
                "report_level": 5,
                "quiet": True,
                "file_insertion_enabled": False,
                "traceback": True,
                # Development use only.
                "dump_settings": False,
                "dump_internals": False,
                "dump_transforms": False,
            }
            opt = frontend.OptionParser(components=[parser], defaults=defaults)
            doc = utils.new_document(
                source_path=self.filename, settings=opt.get_default_values()
            )
            parser.parse(self.contents, doc)
            self._doc = doc
        return self._doc 
開發者ID:PyCQA,項目名稱:doc8,代碼行數:28,代碼來源:parser.py

示例11: assertParses

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def assertParses(self, source, expected, alt=False):  # noqa
        parser = CommonMarkParser()
        parser.parse(dedent(source), new_document('<string>'))
        self.maxDiff = None
        self.assertMultiLineEqual(
            dedent(expected).lstrip(),
            dedent(parser.document.asdom().toprettyxml(indent='  ')),
        ) 
開發者ID:readthedocs,項目名稱:recommonmark,代碼行數:10,代碼來源:test_basic.py

示例12: parse_text

# 需要導入模塊: from docutils import utils [as 別名]
# 或者: from docutils.utils import new_document [as 別名]
def parse_text(text):
    parser = rst.Parser()
    settings = frontend.OptionParser(components=(rst.Parser,)).get_default_values()
    document = utils.new_document(text, settings)
    parser.parse(text, document)
    return document.children 
開發者ID:ovn-org,項目名稱:ovn-scale-test,代碼行數:8,代碼來源:utils.py


注:本文中的docutils.utils.new_document方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。