Module

utils.markdown_escape

Markdown escape utilities for Kida template engine.

Provides GFM-safe escaping and the Marked safe-string class for markdown mode. Analogous to terminal_escape.py's ansi_sanitize/Styled but for GitHub-flavored markdown output.

Escapes special markdown characters via str.translate() with backslash prefixes. Objects implementing markdown() bypass escaping (like terminal/html).

Classes

Marked 10
A string subclass marking content as already safe for markdown output. The Marked class implements…

A string subclass marking content as already safe for markdown output.

The Marked class implements the__markdown__protocol used by the template engine to identify pre-escaped markdown content. When combined with regular strings via operators like+, the non-Marked strings are automatically escaped.

This is the markdown-mode analogue ofMarkup for HTML and Styled for terminal mode.

Methods

format 2 Self
def format(self, *args: Any, **kwargs: Any) -> Self
Parameters
Name Type Description
*args
**kwargs
Returns
Self
join 1 Self
def join(self, seq: Iterable[str]) -> Self
Parameters
Name Type Description
seq
Returns
Self
Internal Methods 8
__new__ 1 Self
def __new__(cls, value: Any = '') -> Self
Parameters
Name Type Description
value Default:''
Returns
Self
__markdown__ 0 Self
Return self -- already safe content.
def __markdown__(self) -> Self
Returns
Self
__repr__ 0 str
def __repr__(self) -> str
Returns
str
__add__ 1 Self
def __add__(self, other: str) -> Self
Parameters
Name Type Description
other
Returns
Self
__radd__ 1 Self
def __radd__(self, other: str) -> Self
Parameters
Name Type Description
other
Returns
Self
__mul__ 1 Self
def __mul__(self, n: SupportsIndex) -> Self
Parameters
Name Type Description
n
Returns
Self
__mod__ 1 Self
def __mod__(self, args: Any) -> Self
Parameters
Name Type Description
args
Returns
Self
__format__ 1 Self
def __format__(self, format_spec: str) -> Self
Parameters
Name Type Description
format_spec
Returns
Self

Functions

markdown_escape 1 str
Escape GFM special characters in untrusted input. Checks the ``__markdown__`` …
def markdown_escape(value: Any) -> str

Escape GFM special characters in untrusted input.

Checks the__markdown__protocol first — objects that implement it are considered pre-escaped and returned as-is (like__html__for Markup or__terminal__for Styled).

Parameters
Name Type Description
value Any

Value to escape (will be converted to string).

Returns
str