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.

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-significant characters in untrusted input. Inline characters (``\``…
def markdown_escape(value: Any) -> str

Escape GFM-significant characters in untrusted input.

Inline characters (\, `, *, _, [, ], <) are always backslash-escaped. Block-leading markers (#, >, -, +, ordered-list digits) are escaped only at the start of a line — matching how real GFM parsers interpret them and keeping inline content like dates, version numbers, and prose hyphens unmangled.

Objects implementing the__markdown__protocol bypass escaping.

Parameters
Name Type Description
value Any
Returns
str