Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/docutils/parsers/__init__.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 # $Id: __init__.py 8239 2018-11-21 21:46:00Z milde $ | |
2 # Author: David Goodger <goodger@python.org> | |
3 # Copyright: This module has been placed in the public domain. | |
4 | |
5 """ | |
6 This package contains Docutils parser modules. | |
7 """ | |
8 | |
9 __docformat__ = 'reStructuredText' | |
10 | |
11 import sys | |
12 from docutils import Component | |
13 | |
14 | |
15 class Parser(Component): | |
16 | |
17 component_type = 'parser' | |
18 config_section = 'parsers' | |
19 | |
20 def parse(self, inputstring, document): | |
21 """Override to parse `inputstring` into document tree `document`.""" | |
22 raise NotImplementedError('subclass must override this method') | |
23 | |
24 def setup_parse(self, inputstring, document): | |
25 """Initial parse setup. Call at start of `self.parse()`.""" | |
26 self.inputstring = inputstring | |
27 self.document = document | |
28 document.reporter.attach_observer(document.note_parse_message) | |
29 | |
30 def finish_parse(self): | |
31 """Finalize parse details. Call at end of `self.parse()`.""" | |
32 self.document.reporter.detach_observer( | |
33 self.document.note_parse_message) | |
34 | |
35 | |
36 _parser_aliases = { | |
37 'restructuredtext': 'rst', | |
38 'rest': 'rst', | |
39 'restx': 'rst', | |
40 'rtxt': 'rst',} | |
41 | |
42 def get_parser_class(parser_name): | |
43 """Return the Parser class from the `parser_name` module.""" | |
44 parser_name = parser_name.lower() | |
45 if parser_name in _parser_aliases: | |
46 parser_name = _parser_aliases[parser_name] | |
47 try: | |
48 module = __import__(parser_name, globals(), locals(), level=1) | |
49 except ImportError: | |
50 module = __import__(parser_name, globals(), locals(), level=0) | |
51 return module.Parser |