Superfence
Tip
Reference for PyMdown Extensions Superfences can be found here.
rst_in_md.superfence_formatter(source, language, css_class, options, md, **kwargs)
Convert superfenced reStructuredText to html.
This function will convert the reStructuredText to html using the same method as the standard python markdown extension.
Unused Arguments
This function is passed a few arguments that are not used. It must adhere to
the required signature
set by pymdownx.superfences
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str
|
Language of the superfence. |
required |
language |
str
|
Language of the superfence (required, but not used). |
required |
css_class |
str
|
CSS class of the superfence (required, but not used). |
required |
options |
dict
|
Options of the superfence (required, but not used). |
required |
md |
Markdown
|
The markdown instance (required, but not used). |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The converted html. |
Source code in rst_in_md/superfence.py
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 |
|
rst_in_md.superfence_validator(language, inputs, options, attrs, md)
Validate that the superfence should be processed.
This function will validate that the superfence should be processed by rst-in-md
.
This includes:
- Checking if the language is supported.
- Checking if the
rst-in-md
attribute is set tofalse
or not. - Checking if any options or attributes are passed.
Unused Arguments
md
is passed to this function but is not used. It must adhere to
the required signature
set by pymdownx.superfences
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language |
str
|
Language of the superfence. |
required |
inputs |
dict
|
All the parsed options/attributes of the superfence. |
required |
options |
dict
|
A dictionary to which all valid options should be assigned to. |
required |
attrs |
dict
|
A dictionary to which all valid attributes should be assigned to. |
required |
md |
Markdown
|
the markdown instance (required, but not used). |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
If the superfence should be processed or not. |
Source code in rst_in_md/superfence.py
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
rst_in_md.RestructuredTextInMarkdownAutoConfigurator
Bases: Preprocessor
Preprocessor to adapt rst-in-md
to work with pymdownx.superfences
.
Source code in rst_in_md/superfence.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
construct_fence_config(language)
staticmethod
Create a fence configuration dictionary for pymdownx.superfences
.
Create a fence configuration for pymdownx.superfences
with the given language,
in the given structure.
This configuration will be read by pymdownx.superfences
to determine how to
process the superfence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language |
str
|
Language of the superfence. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Dictionary of the fence configuration. |
Source code in rst_in_md/superfence.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
construct_superfence(language)
staticmethod
Create a superfence dictionary for pymdownx.superfences
.
Create a superfence dict for pymdownx.superfences
with the given language,
in the given structure.
This dictionary will be appended to SuperFencesCodeExtension().superfences
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language |
str
|
Language of the superfence. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Dictionary of the superfence for |
Raises:
Type | Description |
---|---|
ImportError
|
pymdown-extensions is not properly installed. |
Source code in rst_in_md/superfence.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
inject_custom_configs()
Add custom fence configs to pymdownx.superfences
, if not already present.
Raises:
Type | Description |
---|---|
ImportError
|
pymdown-extensions is not properly installed. |
ValueError
|
SuperFencesCodeExtension not found. |
Source code in rst_in_md/superfence.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
run(lines)
Auto-configure pymdownx.superfences
if installed.
This method will check if pymdownx.superfences
is installed. If it is, it will
deregister rst-in-md
, since pymdownx.superfences
will handle the fenced code
blocks. It will also provide the custom fence configurations needed for
pymdownx.superfences
to properly process the fenced code.
Why is this a preprocessor?
This preprocessor will not actually process any markdown, even if it is called for each markdown file. It much be run after all extensions have been initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines |
list[str]
|
Input lines (required, but not used). |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: Identical as the input lines. |
Source code in rst_in_md/superfence.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
superfences_installed()
Check if the pymdownx.superfences
extension is installed.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
If the extension is installed or not. |
Source code in rst_in_md/superfence.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|