Extension
Tip
Reference for the Python-Markdown extension can be found here.
rst_in_md.RestructuredTextInMarkdown
Bases: Extension
Extension to convert restructured text to html in markdown.
Source code in rst_in_md/extension.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
extendMarkdown(md)
Register the RestructuredTextInMarkdownPreProcessor.
Register the RestructuredTextInMarkdownPreProcessor with the markdown instance. This allows the preprocessor to be used when markdown is rendered to html.
The priority of the preprocessor is set to 27
. This is higher than
the fenced_code_block
preprocessor, so that rst
blocks are processed beforehand. But it is
lower than normalize_whitespace
so that the rst blocks can be processed in a similar manner to code blocks.
Also register the
RestructuredTextInMarkdownAutoConfigurator
if pymdownx.superfences
is installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md |
Markdown
|
The Markdown instance. |
required |
Source code in rst_in_md/extension.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
rst_in_md.RestructuredTextInMarkdownPreProcessor
Bases: Preprocessor
Preprocessor to convert restructured text to html in markdown.
Source code in rst_in_md/processor.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
run(lines)
Strip restuctured text from markdown and replace it with converted html.
This method will look for fenced code blocks in markdown that are marked as
restructured text (rst
, rest
, restructuredtext
) and convert them to html.
It leverages the same regex as the FencedBlockPreprocessor
to find the blocks.
You can also ignore a block from being converted by rst-in-md
adding
rst-in-md=false
to the attributes: ```{.rst rst-in-md=false}
. You can see an
example of this here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines |
list[str]
|
List of lines in markdown. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of lines in markdown with rst replaced with html. |
Source code in rst_in_md/processor.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|