topmark.presentation.markdown.utils¶
topmark / presentation / markdown / utils
Shared presentation utilities for MARKDOWN.
This module provides helpers to render Markdown fragments.
Scope: - Pure string rendering only (no I/O, no Click/Rich console usage). - Safe to import from any frontend (CLI, API tests, etc.).
The helpers here are intentionally small and composable; command-specific formatting belongs in the command's presentation module.
markdown_code_span ¶
Render text as a Markdown inline code span.
This chooses a backtick fence that is one longer than the longest run of
backticks in text, which safely supports filenames that contain backticks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw text to wrap. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Markdown inline code span. |
Source code in src/topmark/presentation/markdown/utils.py
markdown_escape ¶
Safely render text as backticked str.
Source code in src/topmark/presentation/markdown/utils.py
render_fenced_code_block_markdown ¶
Render a Markdown fenced code block using a collision-safe fence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Code block content. |
required |
language
|
str | None
|
Optional Markdown language identifier. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Markdown fenced code block. |
Source code in src/topmark/presentation/markdown/utils.py
render_markdown_table ¶
Render a GitHub-flavoured Markdown table with padded columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Sequence[str]
|
Column headers. |
required |
rows
|
Sequence[Sequence[str]]
|
Table rows. Each row must have the same number of columns as |
required |
align
|
Mapping[int, str] | None
|
Optional mapping of column index to alignment: |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The Markdown table as a single string, ending with a newline. |
Notes
- Widths are computed from the visible string lengths of headers and cells.
- Alignment uses Markdown syntax:
:---(left),:---:(center),---:(right). - This function is pure string rendering and suitable for reuse in any frontend.
Raises:
| Type | Description |
|---|---|
ValueError
|
If any row has a different number of columns than |
Source code in src/topmark/presentation/markdown/utils.py
render_toml_markdown ¶
Render a Markdown heading followed by a fenced TOML code block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
toml_text
|
str
|
TOML content to place inside the fenced code block. |
required |
heading
|
str | None
|
Optional heading text without the leading '#'. |
required |
heading_level
|
int
|
Heading level (normalized to 1..6). |
2
|
Returns:
| Type | Description |
|---|---|
str
|
A Markdown string ending with a newline. |
Source code in src/topmark/presentation/markdown/utils.py
render_path_display_markdown ¶
Render a short Markdown path label for headings and list items.
This helper formats
get_display_path()
for Markdown and annotates STDIN-backed content with _(via STDIN)_ when a
synthetic filename is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
Processing context containing the path to display. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Short Markdown label for per-file headings and guidance messages. |