Skip to content

Commit 16a8d67

Browse files
cscheidclaude
andcommitted
tooling: add CommonMark spec lookup scaffolding
Durable lookup helpers under claude-notes/research/commonmark-spec/ for the 9,800-line external-sources/commonmark/spec.txt: - index.md — section TOC with line ranges - examples-index.md — one line per numbered example with section + range - scripts/spec-section.sh — print a section by title fragment or line number - scripts/spec-example.sh — print an example by its number - README.md — usage + a note that this project does not promise CommonMark compliance (reference, not contract) Originated while triaging issue #173 (bd-v1qc); landed on main directly so the PR for that bug stays scoped to the writer fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cd0c60d commit 16a8d67

5 files changed

Lines changed: 932 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# CommonMark Spec — Reference Scaffolding
2+
3+
The CommonMark specification (v0.31.2) is checked in at
4+
`external-sources/commonmark/spec.txt` — 9811 lines, ~200 KB. Reading
5+
it in full is wasteful for almost any concrete question. This directory
6+
provides indexes and small lookup scripts so an agent (or human) can
7+
fetch just the relevant section or example.
8+
9+
**Caveat on conformance.** This project does *not* promise CommonMark
10+
compliance. Quarto Markdown (qmd) is its own dialect. Use this spec as
11+
a reference for "expected behavior unless we have a documented reason
12+
to differ" — not as a contract. When qmd intentionally diverges (e.g.
13+
no reference-style links), that divergence is the source of truth, not
14+
the spec.
15+
16+
## Contents
17+
18+
- `index.md` — section table of contents with line ranges. Skim this
19+
first to find the right area.
20+
- `examples-index.md` — every numbered example (655 total) with its
21+
section and line range. Search this when chasing a specific behavior.
22+
- `scripts/spec-section.sh` — print one section's text.
23+
- `scripts/spec-example.sh` — print one numbered example.
24+
25+
## Typical commands
26+
27+
From the repo root (or anywhere — the scripts resolve their own paths):
28+
29+
```bash
30+
# Look up by section title (case-insensitive substring)
31+
claude-notes/research/commonmark-spec/scripts/spec-section.sh "fenced code blocks"
32+
33+
# Look up by line number (prints the enclosing section)
34+
claude-notes/research/commonmark-spec/scripts/spec-section.sh 1934
35+
36+
# Print a specific numbered example (input + expected HTML, with fences)
37+
claude-notes/research/commonmark-spec/scripts/spec-example.sh 95
38+
```
39+
40+
For ad-hoc reads, the `Read` tool with an explicit `offset`/`limit`
41+
from `index.md` is also fine — but prefer the scripts for whole-section
42+
lookups since they handle the next-heading boundary correctly.
43+
44+
## Workflow for diagnosing a parser-behavior question
45+
46+
1. Identify the construct (e.g. "list item lazy continuation").
47+
2. Open `index.md`, find the section (e.g. §5.2 List items, lines
48+
4119–5237).
49+
3. Run `spec-section.sh "list items"` to read just that section.
50+
4. Grep `examples-index.md` for related examples and pull them with
51+
`spec-example.sh <N>`.
52+
5. Cross-check qmd behavior against the examples; document any
53+
intentional divergence in the relevant `claude-notes/` plan or
54+
code comment.
55+
56+
## Maintenance
57+
58+
- Do not edit `external-sources/commonmark/spec.txt` (it is an
59+
external reference).
60+
- If the spec is bumped to a new version, regenerate `index.md` and
61+
`examples-index.md`. The awk one-liners that produced them are in
62+
git history for this directory.
63+
- The scripts assume the heading style and 32-backtick fence
64+
convention. Both have been stable across CommonMark versions; if a
65+
future spec breaks them, fix the script rather than working around
66+
it.

0 commit comments

Comments
 (0)