pytwine.parsers.MarkdownParser¶
- class pytwine.parsers.MarkdownParser(file=None, string=None)[source]¶
Bases:
pytwine.parsers.Parser
Parse markdown files into chunks.
Looks for markdown-style fenced code blocks that have “
python
” or “.python
” as their first attribute; e.g.:``` .python someproperty=foo
See <https://spec.commonmark.org/0.30/#fenced-code-blocks>
The closing “fence” must match the opening “fence”: i.e., if we start a code block with backticks, then tildes won’t end it.
(And we can therefore include code like:
mystring=""" ~~~ """
safely inside it.)
Fenced code blocks are only parsed when they appear at the root level – they aren’t recognized if nested inside lists or block-quotes, for example. (But there’s nothing to stop your Python code block from outputting indented content which will be inside a list or block quote.)
- __init__(file=None, string=None)[source]¶
- Keyword Arguments
file – path to a file to be processed
string – a string to be processed
One of either
file
orstring
must be given.
Methods
__init__
([file, string])- keyword file
path to a file to be processed
parse
()Parse the source and return a list of
Chunk
s.- parse() List[pytwine.core.Chunk] ¶
Parse the source and return a list of
Chunk
s.