Skip to content

topmark.toml.render

topmark / toml / render

Render and normalize TopMark TOML documents.

This module contains small TOML-format helpers for: - rendering a TomlTable to TOML text - normalizing TOML text by round-tripping through tomlkit

TOML has no null value, so None entries must be omitted during rendering. See topmark.toml.utils for small TOML-table building and normalization helpers used during rendering.

render_toml_table

render_toml_table(toml_dict)

Render a TOML table to TOML text.

Parameters:

Name Type Description Default
toml_dict TomlTable

TOML table to render.

required

Returns:

Type Description
str

The rendered TOML document as a string.

Source code in src/topmark/toml/render.py
def render_toml_table(toml_dict: TomlTable) -> str:
    """Render a TOML table to TOML text.

    Args:
        toml_dict: TOML table to render.

    Returns:
        The rendered TOML document as a string.
    """
    return _tomlkit_dumps(toml_dict)

clean_toml_text

clean_toml_text(text)

Normalize TOML text by round-tripping through tomlkit.

This helper parses the input, unwraps it to plain Python data, and renders it again. Comments and formatting noise are dropped during the round-trip.

Parameters:

Name Type Description Default
text str

Raw TOML content.

required

Returns:

Type Description
str

A normalized TOML string produced by round-tripping.

Source code in src/topmark/toml/render.py
def clean_toml_text(text: str) -> str:
    """Normalize TOML text by round-tripping through `tomlkit`.

    This helper parses the input, unwraps it to plain Python data, and renders
    it again. Comments and formatting noise are dropped during the round-trip.

    Args:
        text: Raw TOML content.

    Returns:
        A normalized TOML string produced by round-tripping.
    """
    # Parse -> unwrap -> normalize -> re-render, yielding a canonicalized TOML
    # text form without original comments or formatting details.
    doc: tomlkit.TOMLDocument = tomlkit.parse(text)
    unwrapped: dict[str, object] = doc.unwrap()
    data: TomlTable = toml_table_from_mapping(as_object_dict(unwrapped))
    return _tomlkit_dumps(data)