liara.md
¶
Module Contents¶
Classes¶
This processor demotes headings by one level. |
|
A Wordpress-inspired “shortcode” preprocessor which allows calling functions before the markup processing starts. |
|
Register various markdown extensions. |
API¶
- class liara.md.HeadingLevelFixupProcessor(md: markdown.Markdown | None = None)¶
Bases:
markdown.treeprocessors.Treeprocessor
This processor demotes headings by one level.
By default, Markdown starts headings with
<h1>
, but in general the title will be provided by a template. This processor replaces each heading with the next-lower heading, and adds ademoted
class.Initialization
- run(root)¶
- exception liara.md.ShortcodeException(error_message, line_number, line_offset: Optional[int] = None)¶
Bases:
Exception
- with_line_offset(offset)¶
- class liara.md.ShortcodePreprocessor(md=None, node=None)¶
Bases:
markdown.preprocessors.Preprocessor
A Wordpress-inspired “shortcode” preprocessor which allows calling functions before the markup processing starts.
Shortcodes are delimited by
<%
and/%>
. The content must start with the function name, followed bykey=value
pairs. The values are passed as strings, the calling function must do the type conversion.Values without quotation marks must consist of alphanumeric characters and
-
,_
only.Note
Freestanding keys are not supported as it’s ambiguous whether this should be a considered a plain argument (i.e. passed as a non-named argument) or a defaulted argument (i.e. named, but set to
True
or some other value.) For example, you can’t write a shortcode like this:<% alert message="This is important" blink /%>
Instead, you’ll have to use something like:
<% alert message="This is important" blink=yes /%>
Initialization
- set_data(data: Dict[str, Any])¶
Set the data context.
@versionadded 2.6.2
- register(name: str, function)¶
Register a new Markdown shortcode function.
Shortcode function calls must accept all arguments as named arguments. Names (both function names and argument names) starting with
$
are reserved for built-in functions.Shortcode handlers must accept a final
**kwargs
argument to handle any context Liara may pass in. Liara context variables will be prefixed with$
which is disallowed as an parameter name otherwise.
- run(lines: list[str])¶