goweb is a literate programming tool that brings noweb-style chunk syntax to GitHub Flavored Markdown. Write documentation and code in a single .md file, then tangle to extract source files, weave to generate clean markdown, or sync to apply edits back from the generated code.
This codebase was written with DeepSeek and Grok 4.6 (xAI). See SPEC.md for the full language and architecture contract (for humans and agents).
- Noweb-style chunks —
<<name>>=defines a chunk,>>ends it - Out-of-order definitions — chunks can appear in any order; references are resolved after parsing
- Cross-file references —
<<import "file.md">>loads chunks from other files - Chunk overriding —
<<name>>= overridereplaces previous definitions - Override imports —
<<override "file.md">>loads chunks that replace any existing - Conditional blocks —
<<if var>>/<<elif var>>/<<else>>/<<end>>controlled by--varflags - Inline variables —
{{var}}substitution inside chunk bodies - Code execution —
exec:attribute runs chunk body through an interpreter, stdout replaces content - Session-based execution —
session:attribute shares interpreter state across chunks - Pipe commands —
pipe:attribute pipes chunk content through external commands (e.g.,gofmt) - File output —
file:attribute on a chunk writes to a specific path - Chunk metadata —
tags:attribute for categorization and filtering --output-dir— base directory for all tangled/weave output files- Source line directives —
--line-directivesinserts//line/#linecomments pointing to the.mdsource - Bidirectional sync —
goweb syncreads#linedirectives to apply source edits back to the.md - Watch mode —
--watchre-tangles automatically when the source file changes - Language auto-detect — infers fenced-block language from
file:extension - Escape
\>>— literal>>inside chunk bodies - Topological sorting — chunks are emitted in dependency order
- Cycle detection — circular references are caught and reported
- Weave — clean markdown; prose
<<name>>becomes in-document chunk links - Render — HTML (lit-lang.org palette, no underlines) via
goweb render - Cross-reference index —
goweb indexprints a table of all chunks and their references - Dependency diagrams —
goweb graphoutputs Graphviz DOT (--clusterby output file) - Tags —
tags:shelves;goweb tangle --matchextracts one shelf (good LLM context withindex/graph) - Source → literate —
goweb reverseconverts files or a folder into.mdchunks - Project scaffolding —
goweb initcreates a new literate program skeleton - YAML frontmatter —
--- key: value ---config at the top of.mdfiles - AI holes —
ai:open→goweb fill→ai:filled→goweb seal→ai:sealed
go install github.com/xyzzyapps/goweb/cmd/goweb@latestOr build from source:
git clone https://github.com/xyzzyapps/goweb
cd goweb
go build -o goweb ./cmd/goweb<<name>>= file: output.go pipe: gofmt
code body
spans multiple lines
>>
Attributes:
| Attribute | Description |
|---|---|
file: path |
Write resolved chunk to this file path |
pipe: cmd |
Pipe resolved content through an external command |
exec: cmd |
Run the body; stdout replaces the chunk |
session: name |
Share an exec process across chunks |
tags: a,b |
Labels; goweb tangle --match filters by tag |
override |
Replace any earlier chunk of the same name |
ai:open / filled / sealed |
Hole for goweb fill / goweb seal |
Chunks can appear inside fenced code blocks or directly in markdown.
<<name>>
References are expanded recursively during tangling.
<<if debug>>
content for debug mode
<<elif verbose>>
content for verbose mode
<<else>>
content for other cases
<<end>>
Conditions are evaluated using --var flags. Supported expressions:
name— true if the variable is set to a truthy value (not empty,"false","0", or"no")name==value— true if equality holdsname!=value— true if inequality holds
<<import "other.md">>
Loads all chunks from other.md. Paths are resolved relative to the importing file.
# Tangle all chunks with file: attributes
goweb tangle --var debug=true program.md
# Tangle a specific chunk to stdout
goweb tangle program.md main > main.go
# Dry run (show what would be written)
goweb tangle --dry-run program.md
# Set pipe working directory
goweb tangle --pipe-dir ./scripts program.md# Output clean markdown to stdout (chunk bodies wrapped in fenced code blocks)
goweb weave program.md
# Write to file
goweb weave program.md -o README.md
# With variables
goweb weave --var debug=false program.md# Generate HTML with the built-in light documentation theme
goweb render program.md > docs.html
# With custom template
goweb render program.md --template custom.tmpl > docs.html
# With variables (expands {{var}} placeholders, controls <<if>> blocks)
goweb render program.md --var APP_NAME="My App" --var debug=true > docs.html
# Site mode — render a directory of .md files
goweb render --site docs/ --output-dir site/Tags (tags: component) are shelves. goweb tangle --match component writes only that shelf. The graph is who points at whom — useful for humans and as compact context for an LLM (map first, then one chunk).
# Text table: each chunk, where it is defined, who references it
goweb index program.md
# Graphviz DOT — boxes and arrows (A → B means A contains <<B>>)
goweb graph program.md | dot -Tsvg -o deps.svg
goweb graph --cluster program.md | dot -Tpng -o deps.png--cluster groups chunks by the file they tangle into.
Only chunks with ai:open are fill candidates. Tangle never calls a model. Fill never sets ai:sealed.
<<add>>= file: add.js ai:open
function add() {}
>>
goweb fill --dry-run program.md # list holes; no HTTP, no writes
goweb fill --mock program.md # mock/<chunk>.txt
goweb fill --model grok-4.5 program.md # OpenAI-compatible Chat Completions
goweb seal program.md # ai:filled → ai:sealedKeys from OPENAI_API_KEY / XAI_API_KEY / GOWEB_API_KEY (and matching *_BASE_URL / *_MODEL).
goweb reverse main.go lib.go > program.md
goweb reverse src/ -o program.mdThe default theme follows lit-lang.org:
- System UI fonts, amber
#ffcd42primary, dark footer, no link underlines - Hard offset shadows on tables, asides, and code blocks
- Centered header +
main(max 800px) - SEO (Open Graph, Twitter, canonical) and AEO (JSON-LD, semantic article)
- Unset
AUTHOR/EMAIL/REPOcome fromgit config
source.md
│
▼
┌─────────────────────┐
│ Preprocessor │ resolves <<import>>, <<if>>/<<elif>>/<<else>>/<<end>>
│ (pkg/preproc) │ using --var flags, produces filtered lines
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Parser │ identifies fenced code blocks, extracts <<name>>=..>>
│ (pkg/parser) │ chunk definitions, collects <<ref>> references
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Dependency Graph │ builds dependency graph, topological sort, cycle detect
│ (pkg/graph) │
└─────────┬───────────┘
│
├──► Tangle ──► output files
│ (pkg/tangle) (resolves refs, applies pipes; never calls a model)
│
├──► Weave ──► clean markdown
│ (pkg/weave)
│
├──► Render ──► HTML documentation
│ (cmd/goweb)
│
└──► Fill / seal ──► rewrite ai:* chunks in the .md
(pkg/fill)
There is a single example: a Preact + htm TODO app (examples/preact-todo/) that runs in the browser with no bundler.
It demonstrates:
<<chunk>>=definitions withfile:→ outputs tosrc/*.js,package.json,index.html, etc.<<import "file.md">>— cross-file references across 4 source files<<if debug>>/<<end>>— conditional console.log for debug modetags:— shelves such ascomponent,config,debug;goweb tangle --matchandgoweb graph/goweb indexfor maps and LLM context--var— configurableAPP_NAME,AUTHOR, anddebugvariables{{var}}substitution — variables inpackage.json,index.html, LICENSE<<override>>— replace components easily- Multiple sub-components (App, TodoList, TodoItem, AddTodo)
- Static ES modules + import map (serve the folder; do not open
file://)
cd examples/preact-todo
goweb tangle --var APP_NAME="My Todo" --var debug=true main.md
python -m http.server 8080Render the documentation to HTML with the light theme:
goweb render main.md --var APP_NAME="Todo App" --var debug=true -o docs.htmlThe rendered HTML is published on GitHub Pages (gh-pages) with SEO and AEO metadata.
cmd/goweb/ CLI (cobra): tangle, weave, render, index, graph, reverse, fill, seal, sync, lsp, init
pkg/parser/ Chunk, Document, markdown/noweb parser
pkg/preproc/ Imports, conditionals, frontmatter
pkg/graph/ Dependency graph, topological sort
pkg/tangle/ Reference expansion, pipes, exec, file output
pkg/fill/ AI holes: fill (mock or HTTP) and seal
pkg/weave/ Strip goweb syntax → clean markdown
examples/preact-todo/ Single example (Preact + htm, no bundler)
SPEC.md Language and architecture spec (agents + humans)
.agents/skills/goweb/ Agent skill for using this tool
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0). See LICENSE.