=== BEGIN ARTIFACT FEATURE-Indented-Code.md === # FEATURE: Indented Code | Field | Value | |-------------|-------| | Version | 20261014 V1 | | Description | Parse indented code blocks made of chunks of lines indented four or more columns and render them as pre and code elements. | | Depends On | FEATURE-ATX-Headings.md | | Provides | indented code block | | Consumes | block-type registry | ## Questions - None. ## Purpose Implement the Indented code blocks section of the spec as a registered block start rule. ## Rules - A line with four or more columns of indentation (column-aware, tab stop 4), that is not blank and does not continue a paragraph, starts an indented code block. - An indented code block cannot interrupt a paragraph. A non-blank line with fewer than four columns of indentation ends the block immediately. - Chunks are separated by blank lines. Interior blank lines are kept in the content, with any indentation beyond four columns retained. Leading and trailing blank lines are not part of the block. - Content is the literal lines minus four columns of indentation, including trailing spaces, and is HTML-escaped. It is never parsed as Markdown. There is no info string. - It renders as `
...` with a final line ending inside the code element.
## Reads
- Lines handed to the block engine.
## Writes
- Code block nodes in the block tree.
## Programmatic Acceptance
The corpus section examples use lists, so it is gated in the lists story. The checks here are bounded.
=== AC indented-simple-block ===
Intent: Four-space-indented lines render one pre element whose code keeps the extra indentation and content.
import subprocess
first = "a simple"
second = " indented code block"
source = " " + first + "\n " + second + "\n"
result = subprocess.run(["./commonmark"], input=source, capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
assert result.stdout.count("") == 1
assert first in result.stdout
assert second in result.stdout
=== END AC indented-simple-block ===
=== AC indented-cannot-interrupt-paragraph ===
Intent: An indented line directly after paragraph text is a continuation, not a code block.
import subprocess
result = subprocess.run(["./commonmark"], input="Foo\n bar\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 0
assert result.stdout.count("") == 1
=== END AC indented-cannot-interrupt-paragraph ===
=== AC indented-chunks-and-ending ===
Intent: Chunks separated by a blank line form one block, and an unindented line ends it and starts a paragraph.
import subprocess
result = subprocess.run(["./commonmark"], input=" chunk1\n\n chunk2\nbar\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("
") == 1
assert result.stdout.count("") == 1
=== END AC indented-chunks-and-ending ===
=== AC indented-content-escaped-and-literal ===
Intent: Code content is escaped and not parsed as Markdown, so only the four code wrapper tags contribute angle brackets.
import subprocess
result = subprocess.run(["./commonmark"], input=" \n *hi*\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("<") == 4
assert result.stdout.count("") == 0
=== END AC indented-content-escaped-and-literal ===
=== AC indented-tab-indentation ===
Intent: A leading tab counts as four columns of indentation.
import subprocess
result = subprocess.run(["./commonmark"], input="\tfoo\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
=== END AC indented-tab-indentation ===
## User Acceptance
- None.
## Guardrails
- Never let an indented code block interrupt a paragraph.
- Never expand tabs inside code content; only the indentation prefix is column-aware.
- Do not skip, filter or reinterpret corpus examples.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-Fenced-Code.md ===
# FEATURE: Fenced Code
| Field | Value |
|-------------|-------|
| Version | 20261014 V1 |
| Description | Parse fenced code blocks delimited by backtick or tilde fences with info strings and indentation stripping. |
| Depends On | FEATURE-Indented-Code.md |
| Provides | fenced code block |
| Consumes | block-type registry, shared unescape and entity helpers |
## Questions
- None.
## Purpose
Implement the Fenced code blocks section of the spec.
## Rules
- An opening fence is at least three consecutive backticks or tildes, with up to three spaces of indentation. Backtick and tilde fences cannot be mixed. The text after the fence is the info string, trimmed. For a backtick fence the info string must not contain a backtick; otherwise the line is not a fence (it is parsed as a paragraph with a code span).
- Content is all following lines until a closing fence of the same character, at least as long as the opening one, with up to three spaces of indentation and followed only by spaces or tabs. Closing fences have no info string.
- If the opening fence is indented by N spaces, up to N spaces of indentation are removed from each content line.
- An unclosed fence runs to the end of the document or the enclosing container.
- A fenced code block can interrupt a paragraph and needs no blank lines around it.
- The first word of the info string, after backslash unescape and entity decoding, becomes `class="language-WORD"` on the code element. Content is HTML-escaped and never parsed.
## Reads
- Lines handed to the block engine.
## Writes
- Code block nodes in the block tree.
## Programmatic Acceptance
The corpus section examples use quotes, lists and setext headings, so it is gated in the lists story. The checks here are bounded.
=== AC fenced-backtick-and-tilde ===
Intent: Backtick and tilde fences each render one pre element containing the supplied body.
import subprocess
body = "some body text"
for fence in ("```", "~~~"):
source = fence + "\n" + body + "\n" + fence + "\n"
result = subprocess.run(["./commonmark"], input=source, capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
assert body in result.stdout
=== END AC fenced-backtick-and-tilde ===
=== AC fenced-info-string-language-class ===
Intent: The first word of the info string becomes the language class.
import subprocess
language = "ruby"
source = "```" + language + " extra words\ncode\n```\n"
result = subprocess.run(["./commonmark"], input=source, capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert ('class="language-' + language + '"') in result.stdout
=== END AC fenced-info-string-language-class ===
=== AC fenced-closing-fence-rules ===
Intent: A fence of the other character, or a shorter fence, does not close the block.
import subprocess
other = "~~~"
shorter = "```"
source = "````\naaa\n" + other + "\n" + shorter + "\n"
result = subprocess.run(["./commonmark"], input=source, capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
assert other in result.stdout
assert shorter in result.stdout
=== END AC fenced-closing-fence-rules ===
=== AC fenced-unclosed-runs-to-end ===
Intent: An unclosed fence consumes the rest of the document as code.
import subprocess
trailing = "still code"
result = subprocess.run(["./commonmark"], input="```\nfirst\n\n" + trailing + "\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
assert result.stdout.count("") == 0
assert trailing in result.stdout
=== END AC fenced-unclosed-runs-to-end ===
=== AC fenced-interrupts-paragraph ===
Intent: A fence interrupts a paragraph and text after it starts a new paragraph.
import subprocess
result = subprocess.run(["./commonmark"], input="foo\n```\nbar\n```\nbaz\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("
") == 1
assert result.stdout.count("") == 2
=== END AC fenced-interrupts-paragraph ===
=== AC fenced-two-backticks-not-a-fence ===
Intent: Two backticks do not open a fence; they form a code span instead.
import subprocess
result = subprocess.run(["./commonmark"], input="``\nfoo\n``\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("
") == 0
assert result.stdout.count("") == 1
=== END AC fenced-two-backticks-not-a-fence ===
=== AC fenced-indentation-stripped ===
Intent: Content indentation up to the fence indentation is removed, and unindented lines are kept.
import subprocess
result = subprocess.run(["./commonmark"], input=" ```\n aaa\naaa\n```\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert result.stdout.count("") == 1
assert result.stdout.count("aaa") == 2
assert result.stdout.count(" aaa") == 0
=== END AC fenced-indentation-stripped ===
## User Acceptance
- None.
## Guardrails
- Never parse fenced content as Markdown.
- Never let a closing fence carry an info string.
- Do not skip, filter or reinterpret corpus examples.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-HTML-Blocks.md ===
# FEATURE: HTML Blocks
| Field | Value |
|-------------|-------|
| Version | 20261014 V1 |
| Description | Parse the seven kinds of HTML block and emit their lines as raw HTML. |
| Depends On | FEATURE-Fenced-Code.md |
| Provides | HTML block |
| Consumes | block-type registry |
## Questions
- None.
## Purpose
Implement the HTML blocks section of the spec.
## Start and end conditions
After up to three spaces of indentation:
1. Line begins with `` or end of line. Ends at a line containing `
`, ``, `` or `` (case-insensitive, need not match the start tag).
2. Begins with ``.
3. Begins with ``. Ends at a line containing `?>`.
4. Begins with ``.
5. Begins with ``.
6. Begins with `<` or `` and one of the block-level tag names listed in the spec (case-insensitive), followed by a space, tab, end of line, `>` or `/>`. Ends before the next blank line.
7. Begins with a complete open tag (tag name not `pre`, `script`, `style` or `textarea`) or complete closing tag alone on the line, followed only by spaces and tabs. Ends before the next blank line.
## Rules
- If the first line also meets the end condition, the block is that single line. Types 1 to 5 include the line holding the end condition, with anything after the end tag.
- Blocks end at the end of the document or enclosing container if no end condition is met.
- Types 1 to 6 can interrupt a paragraph. Type 7 cannot.
- Lines are emitted unchanged and unescaped, with their original indentation. Content inside the block is never parsed as Markdown, and tags inside it never change parser state.
## Reads
- Lines handed to the block engine.
## Writes
- HTML block nodes in the block tree.
## Programmatic Acceptance
The corpus section has examples that use quotes, lists and indented code, so it is gated in the tabs story. The checks here are bounded.
=== AC htmlblock-type6-raw-lines ===
Intent: A block-level tag block passes through verbatim and its Markdown is not parsed.
import subprocess
block = "\n*foo*\n"
result = subprocess.run(["./commonmark"], input=block + "\n", capture_output=True, text=True)
print(result.stdout)
assert result.returncode == 0
assert block in result.stdout
assert result.stdout.count("") == 0
assert result.stdout.count("") == 0
=== END AC htmlblock-type6-raw-lines ===
=== AC htmlblock-type6-ends-at-blank-line ===
Intent: A type 6 block ends at a blank line and Markdown after it is parsed.
import subprocess
result = subprocess.run(["./commonmark"], input="