# markdown_escape

URL: /kida/api/utils/markdown_escape/
Section: utils
Description: 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__).

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/utils/markdown_escape/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Futils%2Fmarkdown_escape%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Futils%2Fmarkdown_escape%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Futils%2Fmarkdown_escape%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Futils%2Fmarkdown_escape%2Findex.txt)

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).

1Class1Function

## 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 of`Markup` 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`
