Python docutils.utils.new_document() Examples
The following are 30
code examples of docutils.utils.new_document().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.utils
, or try the search function
.
Example #1
Source File: rst.py From Tickeys-linux with MIT License | 6 votes |
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')
Example #2
Source File: rst.py From Tickeys-linux with MIT License | 6 votes |
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
Example #3
Source File: rst.py From Tickeys-linux with MIT License | 6 votes |
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')
Example #4
Source File: rst.py From Tickeys-linux with MIT License | 6 votes |
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
Example #5
Source File: ext.py From rucio with Apache License 2.0 | 5 votes |
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
Example #6
Source File: __init__.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #7
Source File: __init__.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #8
Source File: __init__.py From blackmamba with MIT License | 5 votes |
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
Example #9
Source File: __init__.py From blackmamba with MIT License | 5 votes |
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
Example #10
Source File: __init__.py From aws-extender with MIT License | 5 votes |
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
Example #11
Source File: __init__.py From aws-extender with MIT License | 5 votes |
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
Example #12
Source File: parser.py From doc8 with Apache License 2.0 | 5 votes |
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
Example #13
Source File: test_basic.py From recommonmark with MIT License | 5 votes |
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=' ')), )
Example #14
Source File: utils.py From ovn-scale-test with Apache License 2.0 | 5 votes |
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
Example #15
Source File: __init__.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
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
Example #16
Source File: __init__.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
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
Example #17
Source File: renderers.py From sphinx-js with MIT License | 5 votes |
def rst_nodes(self): """Render into RST nodes a thing shaped like a function, having a name and arguments. Fill in args, docstrings, and info fields from stored JSDoc output. """ try: # Get the relevant documentation together: doclet, full_path = self._app._sphinxjs_doclets_by_path.get_with_path(self._partial_path) except SuffixNotFound as exc: raise SphinxError('No JSDoc documentation was found for object "%s" or any path ending with that.' % ''.join(exc.segments)) except SuffixAmbiguous as exc: raise SphinxError('More than one JS object matches the path suffix "%s". Candidate paths have these segments in front: %s' % (''.join(exc.segments), exc.next_possible_keys)) else: rst = self.rst(self._partial_path, full_path, doclet, use_short_name='short-name' in self._options) # Parse the RST into docutils nodes with a fresh doc, and return # them. # # Not sure if passing the settings from the "real" doc is the right # thing to do here: meta = doclet['meta'] doc = new_document('%s:%s(%s)' % (meta['filename'], doclet['longname'], meta['lineno']), settings=self._directive.state.document.settings) RstParser().parse(rst, doc) return doc.children return []
Example #18
Source File: yaqlautodoc.py From yaql with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #20
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #21
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #22
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #23
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
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
Example #24
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
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
Example #25
Source File: schematable.py From altair with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #26
Source File: __init__.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #27
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
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
Example #28
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
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
Example #29
Source File: test_docker_readme.py From rally-openstack with Apache License 2.0 | 5 votes |
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
Example #30
Source File: test_docstrings.py From rally-openstack with Apache License 2.0 | 5 votes |
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