liara.md

Module Contents

Classes

HeadingLevelFixupProcessor

This processor demotes headings by one level.

ShortcodePreprocessor

A Wordpress-inspired “shortcode” preprocessor which allows calling functions before the markup processing starts.

LiaraMarkdownExtensions

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 a demoted 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 by key=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])
class liara.md.LiaraMarkdownExtensions(node=None)

Bases: markdown.extensions.Extension

Register various markdown extensions.

Initialization

Initiate Extension and set up configs.

set_data(data: Dict[str, Any])
extendMarkdown(md)