| 1 |
|
| 2 |
e. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
$ |
| 14 |
""" |
| 15 |
An interface for parsing CommonMark input. |
| 16 |
|
| 17 |
Select a locally installed parser from the following 3rd-party |
| 18 |
parser packages: |
| 19 |
|
| 20 |
:pycmark: https://pypi.org/project/pycmark/ |
| 21 |
:myst: https://pypi.org/project/myst-docutils/ |
| 22 |
:recommonmark: https://pypi.org/project/recommonmark/ (deprecated) |
| 23 |
|
| 24 |
The first parser class that can be successfully imported is mapped to |
| 25 |
`commonmark_wrapper.Parser`. |
| 26 |
|
| 27 |
This module is provisional: |
| 28 |
the API is not settled and may change with any minor Docutils version. |
| 29 |
""" |
| 30 |
|
| 31 |
import docutils.parsers |
| 32 |
|
| 33 |
|
| 34 |
commonmark_parser_names = ('pycmark', 'myst', 'recommonmark') |
| 35 |
"""Names of compatible drop-in CommonMark parsers""" |
| 36 |
|
| 37 |
Parser = None |
| 38 |
parser_name = '' |
| 39 |
|
| 40 |
for name in commonmark_parser_names: |
| 41 |
try: |
| 42 |
Parser = docutils.parsers.get_parser_class(name) |
| 43 |
except ImportError: |
| 44 |
continue |
| 45 |
parser_name = name |
| 46 |
break |
| 47 |
|
| 48 |
if Parser is None: |
| 49 |
raise ImportError( |
| 50 |
'Parsing "CommonMark" requires one of the packages\n' |
| 51 |
f'{commonmark_parser_names} available at https://pypi.org') |
| 52 |
|
| 53 |
if parser_name == 'myst': |
| 54 |
if not Parser.settings_defaults: |
| 55 |
Parser.settings_defaults = {} |
| 56 |
Parser.settings_defaults['myst_commonmark_only'] = True |