Skip to content

topmark.core.formats

topmark / core / formats

Shared output format definitions used across TopMark frontends.

This module centralizes the OutputFormat enum so CLI commands, machine emitters, and other frontends can agree on the same format vocabulary without introducing Click or console dependencies.

Machine-readable formats (JSON, NDJSON) are intended to be stable and colorless

OutputFormat

Bases: str, Enum

Output format for CLI rendering.

Attributes:

Name Type Description
TEXT

Human-friendly text output; may include ANSI color if enabled.

MARKDOWN

A Markdown document.

JSON

A single JSON document (machine-readable). See the Machine-readable output developer docs for the schema.

NDJSON

One JSON object per line (newline-delimited JSON; machine-readable).

Notes

is_machine_format

is_machine_format(fmt)

Return True for formats intended for machine consumption.

Parameters:

Name Type Description Default
fmt OutputFormat | None

the output format to be checked.

required

Returns:

Type Description
bool

True if the format provided is a machine-readable format, else False.

Source code in src/topmark/core/formats.py
def is_machine_format(fmt: OutputFormat | None) -> bool:
    """Return True for formats intended for machine consumption.

    Args:
        fmt: the output format to be checked.

    Returns:
        `True` if the format provided is a machine-readable format, else `False`.
    """
    return fmt in {OutputFormat.JSON, OutputFormat.NDJSON}