Run artifact

workspace/targets/commonmark/blueprint/ARCHITECTURE.md

ARCHITECTURE: CommonMark Parser

FieldValue
Version20261014 V1
DescriptionTwo-phase CommonMark 0.31.2 parser delivered as the stdin-to-stdout executable commonmark, with its module layout and technical decisions.
Depends OnNone
Providesmdparser package, mdparser.blocks, mdparser.inlines, mdparser.refs, mdparser.entities, mdparser.render, mdparser.cli
ConsumesNone

Overview

The product is a single-process CLI. ./commonmark reads UTF-8 Markdown from stdin and writes HTML to stdout. It is implemented in the Python package mdparser and follows the spec Appendix "A parsing strategy" directly.

Technology Stack

Derived from TECHNOLOGY_STACK.md, which remains the decision of record.

TechnologyWhere it applies
Python 3Implementation language for the whole package and the commonmark script.
Python standard libraryThe only runtime dependency set: re, unicodedata, html.entities, sys.
POSIX shellThe supplied sources/full_test.sh scoring entry point; it is staged, never authored.

The Foundation Contract is: source root ./, environment .venv created by uv venv, dependencies in pyproject.toml with a committed uv.lock, and pytest -q as the test command. The executable must also run under plain python3 with no environment activated, because the supplied harness runs ./commonmark directly.

Modules

ModuleResponsibility
commonmark (root script)Shebang entry point; puts its own directory on sys.path and calls mdparser.cli.main.
mdparser.cliByte intake, UTF-8 decoding with replacement, line-ending normalization, U+0000 replacement, output writing.
mdparser.blocksBlock tree, block-type registry (start, continue, close rules), per-line procedure, lazy continuation.
mdparser.refsReference map, link reference definition extraction, normalize_label.
mdparser.inlinesInline scanner, delimiter stack, process_emphasis, look-for-link-or-image.
mdparser.entitiesEntity and numeric character reference decoding, backslash unescape helper.
mdparser.renderHTML rendering, HTML escaping, URL percent-encoding.

Technical Decisions

Persistence, Configuration and Boundaries

BoundaryOwner moduleAllowed low-level APIs
PersistenceNone. The product is stateless.None
ConfigurationNone. No arguments or environment are required.None
File storeNone.None
External servicesNone.None
Process I/Omdparser.clisys.stdin.buffer, sys.stdout.buffer, sys.stderr

Programmatic Acceptance

=== AC foundation-package-imports ===
Intent: The mdparser package and each reserved module import cleanly using only the standard library.

import importlib import os import sys

sys.path.insert(0, os.getcwd())

importlib.import_module("mdparser") for name in ["blocks", "inlines", "refs", "entities", "render", "cli"]: full = "mdparser." + name module = importlib.import_module(full) assert module.name == full === END AC foundation-package-imports ===

User Acceptance

Guardrails