我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用docutils.parsers.rst.Parser()。
def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" source_path = StringIO() parser = Parser() settings = frontend.OptionParser().get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) document.note_source(source_path, -1) try: parser.parse(data, document) except AttributeError: reporter.messages.append((-1, 'Could not finish the parsing.', '', {})) return reporter.messages
def parse_article(filename, destination=None): settings = OptionParser(components=(Parser,)).get_default_values() pub = core.Publisher(None, None, None, settings=settings) pub.set_components('standalone', 'restructuredtext', 'html') pub.writer = Writer() pub.set_source(None, filename) if destination is not None: pub.set_destination(None, destination) else: pub.destination_class = io.NullOutput pub.set_destination(None, None) pub.process_programmatic_settings(None, None, None) try: pub.publish() except SystemExit as e: article = pub.writer.visitor.article with open(filename) as f: article.original_source = f.read() return pub.writer.visitor.article
def parse_thread(filename, destination=None): settings = OptionParser(components=(Parser,)).get_default_values() pub = core.Publisher(None, None, None, settings=settings) pub.set_components('standalone', 'restructuredtext', 'html') pub.writer = ThreadWriter() pub.set_source(None, filename) if destination is not None: pub.set_destination(None, destination) else: pub.destination_class = io.NullOutput pub.set_destination(None, None) pub.process_programmatic_settings(None, None, None) try: pub.publish() except SystemExit as e: pass return pub.writer.visitor.uuid, pub.writer.visitor.comments
def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" source_path = StringIO() parser = Parser() settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) document.note_source(source_path, -1) try: parser.parse(data, document) except AttributeError as e: reporter.messages.append( (-1, 'Could not finish the parsing: %s.' % e, '', {})) return reporter.messages
def _check_rst_data(self, data): """Return warnings when the provided data has syntax errors.""" source_path = StringIO() parser = Parser() settings = frontend.OptionParser().get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) document.note_source(source_path, -1) try: parser.parse(data, document) except AttributeError: reporter.messages.append((-1, 'Could not finish the parsing.', '', {})) return reporter.messages
def __init__(self): self.publishers = { '': Struct(components=(pep.Reader, rst.Parser, pep_html.Writer, SettingsSpec)), '.txt': Struct(components=(rst.Parser, standalone.Reader, html5_polyglot.Writer, SettingsSpec), reader_name='standalone', writer_name='html5'), 'PEPs': Struct(components=(rst.Parser, pep.Reader, pep_html.Writer, SettingsSpec), reader_name='pep', writer_name='pep_html')} """Publisher-specific settings. Key '' is for the front-end script itself. ``self.publishers[''].components`` must contain a superset of all components used by individual publishers.""" self.setup_publishers()
def validate_rest(text): components=(docutils.parsers.rst.Parser,) settings = docutils.frontend.OptionParser(components).get_default_values() document = docutils.utils.new_document('', settings) rst.Parser().parse(text, document) try: document.walk(ReSTValidatorVisitor(document)) return False, None except InvalidReSTError as e: return e.args[0], e.args[1]
def __init__(self, parser=None, parser_name=None): """`parser` should be ``None``.""" if parser is None: parser = rst.Parser(rfc2822=True, inliner=self.inliner_class()) standalone.Reader.__init__(self, parser, '')
def parse_rst(text: str) -> str: """Parse reStructuredText into a tree of nodes.""" directives.register_directive("linotype", LinotypeDirective) option_parser = OptionParser(components=(Parser,)) settings = option_parser.get_default_values() parser = Parser() document = new_document("test", settings) parser.parse(text, document) return document.pformat()
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
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