|
| 1 | +# Developer Notes: Documentation Architecture |
| 2 | + |
| 3 | +This document explains the documentation build system and why it's set up the way it is. |
| 4 | + |
| 5 | +## The Recursion Problem |
| 6 | + |
| 7 | +The documentation for `markdown-code-runner` uses `markdown-code-runner` itself to generate content. This creates a potential recursion problem: |
| 8 | + |
| 9 | +1. The docs contain **examples** showing how to use the tool (CODE:START, OUTPUT:START markers, etc.) |
| 10 | +2. If these examples were executed by the tool, their OUTPUT sections would be filled with actual output |
| 11 | +3. This would make them useless as examples - users need to see the *template* syntax, not executed results |
| 12 | + |
| 13 | +## How We Solve It |
| 14 | + |
| 15 | +### 1. CODE:SKIP Directive |
| 16 | + |
| 17 | +Use `<!-- CODE:SKIP -->` before example code blocks to prevent them from being executed: |
| 18 | + |
| 19 | +```markdown |
| 20 | +<!-- CODE:SKIP --> <!-- Prevents the next code block from running --> |
| 21 | +```python |
| 22 | +print("This is an example that won't be executed") |
| 23 | +``` |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. PLACEHOLDER Pattern for Templates |
| 27 | + |
| 28 | +OUTPUT sections in the repository contain only placeholder text: |
| 29 | + |
| 30 | +```markdown |
| 31 | +<!-- OUTPUT:START --> |
| 32 | +<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py |
| 33 | +<!-- OUTPUT:END --> |
| 34 | +``` |
| 35 | + |
| 36 | +This placeholder gets replaced with actual content during CI builds, but the generated content is **never committed** back to the repository. |
| 37 | + |
| 38 | +### 3. Nested HTML Comment Escaping |
| 39 | + |
| 40 | +When writing code that references markdown-code-runner markers inside HTML comments, you must escape them to avoid breaking markdown parsing: |
| 41 | + |
| 42 | +```python |
| 43 | +# BAD - nested HTML comments break parsing: |
| 44 | +<!-- content = re.sub(r"<!-- SECTION:START -->.*?<!-- SECTION:END -->", ...) --> |
| 45 | + |
| 46 | +# GOOD - use string concatenation to escape: |
| 47 | +<!-- start_marker = "<!-" + "- SECTION:START -" + "->" --> |
| 48 | +<!-- end_marker = "<!-" + "- SECTION:END -" + "->" --> |
| 49 | +<!-- content = re.sub(start_marker + ".*?" + end_marker, ...) --> |
| 50 | +``` |
| 51 | + |
| 52 | +## Documentation Build Process |
| 53 | + |
| 54 | +1. **Source files** in `docs/` contain CODE blocks that pull content from README.md |
| 55 | +2. **CI runs** `docs/docs_gen.py` which executes `markdown-code-runner` on all doc files |
| 56 | +3. **Generated output** is used to build the documentation site |
| 57 | +4. **Generated content is NOT committed** - only the templates with PLACEHOLDERs exist in the repo |
| 58 | + |
| 59 | +## File Structure |
| 60 | + |
| 61 | +- `docs/docs_gen.py` - Script that processes all markdown files for documentation build |
| 62 | +- `docs/*.md` - Documentation templates with CODE/OUTPUT blocks |
| 63 | +- `README.md` - Source of truth for content (uses SECTION markers) |
| 64 | + |
| 65 | +## Pre-commit Hook |
| 66 | + |
| 67 | +The `Verify docs templates have placeholders` pre-commit hook ensures that OUTPUT sections contain PLACEHOLDER text, preventing accidental commits of generated content. |
| 68 | + |
| 69 | +## Why Not Commit Generated Output? |
| 70 | + |
| 71 | +1. **Copyability**: Users copying examples from the docs get clean templates, not filled-in output |
| 72 | +2. **Recursion avoidance**: Examples remain as examples, not executed results |
| 73 | +3. **Single source of truth**: README.md is the source; docs pull from it |
| 74 | +4. **Cleaner diffs**: No noise from regenerated output in every commit |
0 commit comments