Skip to content

Parser

parser

parse_mkdocs_output(output)

Classify mkdocs build --strict log output into gate findings.

Pure function: iterates the lines of output, keeps only WARNING/ERROR lines that reference a documentation problem, and maps each to a :class:DocGateFinding. The referenced target and source page are recovered from the single-quoted tokens mkdocs emits (Doc file 'PAGE' ... 'TARGET').

Deterministic and free of I/O: the same output always yields the same list, and empty or clean output yields [].

Source code in packages/axm-audit/src/axm_audit/doc_gate/parser.py
Python
def parse_mkdocs_output(output: str) -> list[DocGateFinding]:
    """Classify ``mkdocs build --strict`` log output into gate findings.

    Pure function: iterates the lines of ``output``, keeps only WARNING/ERROR
    lines that reference a documentation problem, and maps each to a
    :class:`DocGateFinding`. The referenced target and source page are recovered
    from the single-quoted tokens mkdocs emits (``Doc file 'PAGE' ... 'TARGET'``).

    Deterministic and free of I/O: the same ``output`` always yields the same
    list, and empty or clean output yields ``[]``.
    """
    findings: list[DocGateFinding] = []
    for raw in output.splitlines():
        line = raw.strip()
        if _DIAGNOSTIC.match(line) is None:
            continue
        kind = _classify(line.lower())
        if kind is None:
            continue
        quoted = _QUOTED.findall(line)
        source_page = quoted[0] if quoted else ""
        target = quoted[1] if len(quoted) > 1 else ""
        findings.append(
            DocGateFinding(kind=kind, target=target, source_page=source_page)
        )
    return findings