Literate Markdown & Ontology Export
Forma treats Markdown (.md, .forma.md, .markdown) as a first-class authoring and ontology projection format alongside .lisp. You can write prose, tables, diagrams, and executable Forma definitions in the same document, check and format them with exact .md line/column diagnostics, and round-trip them cleanly through the content-addressed transactional store.
Fenced Block Rules
Forma extracts executable code strictly from fenced code blocks whose language tag is forma or lisp (case-insensitive). Both backtick (```) and tilde (~~~) fences of three or more characters are supported.
| Fence header | Extracted & checked? | Notes |
|---|---|---|
```forma / ```lisp | Yes | Concatenated in document order with exact source-span mapping. |
~~~forma / ~~~lisp | Yes | Equivalent to backtick fences. |
```forma ignore | No | Opt-out tokens ignore, no-check, and skip exclude the block. |
```json, ```ts, ```sh | No | Non-Forma fences are left untouched. |
Untyped ``` or prose | No | Ignored semantically and preserved verbatim. |
An ontology document can mix YAML frontmatter, narrative prose, reference payloads, and executable Forma blocks:
---
id: hr
version: 0.1.0
---
# HR Ontology
Candidate and offer definitions for recruiting workflows.
```forma
(entity Candidate {:name String :email (Option String) :status String})
(entity Offer {:title String :status String :candidate (Option (Id Candidate))})
```
Example webhook payload (ignored by Forma):
```json
{"event": "offer.accepted", "candidate": "candidate:taylor"}
```
Draft scratchpad (opted out of checking):
```forma ignore
(define (wip-experiment x) x)
```
```forma
(query active-offers :from Offer :select [title status candidate])
```CLI, Modules & Exact .md Diagnostics
All core CLI commands accept .md and .forma.md files natively:
forma check ontology.md
forma run ontology.md
forma test ontology.md
forma fmt ontology.md- Exact
.mdcoordinates: Parse, typecheck, and form-hook diagnostics across multiple fenced blocks are remapped back to the exact 1-basedline:collocation inside the.mdfile. The language server remaps diagnostics, hover ranges, and formatting edits the same way. - Lossless formatting:
forma fmt ontology.mdformats only the executableforma/lispblocks and splices them back into place without modifying surrounding prose, headings, frontmatter, or non-Forma fences. - Module imports: Relative imports resolve
.mdmodules alongside.lispfiles, extracting their executable fences and remapping any module diagnostics to the imported.mdfile.
Transactional Store & Markdown Ontology Export
The content-addressed store (forma store) supports Markdown as a primary human- and agent-reviewable projection format:
# Initialize a store from .md or .lisp files
forma store init ontology.md
# Export the current snapshot to reviewable Markdown documents
forma store export --out ./exported --format md
# Re-import edited Markdown files as a minimal semantic transaction
forma store import ./exported --branch mainGenerated Markdown Structure
When exporting a fresh snapshot with --format md (or exportSnapshotToMarkdown), each module is projected with:
- YAML metadata frontmatter (optional, enabled by default): records
forma_ontology: true,branch,snapshot,policies, anddefinitions. - Semantic section headings: groups definitions in canonical order under
## Entities,## Types,## Errors,## Services,## Queries,## Workflow Models,## Definitions, and## Tests(omitting empty sections). - Docstrings as prose: preserves definition docstrings above clean
```formablocks.
Prose-Invariant Round-Trips & Surgical Updates
Semantic identity in the store (DefHash) depends only on the canonical meaning of definitions inside executable fences:
- Prose edits produce zero semantic operations. Rewriting Markdown paragraphs, headings, tables, non-Forma fences, or
ignorefences leaves everyDefHashunchanged, soimportMarkdownAsTransactionreturns an empty operation list. - Surgical updates preserve human prose. Passing
originalMarkdowntoexportSnapshotToMarkdownupdates only changed, renamed, added, or removed definitions inside their existing fenced blocks. Unchanged modules are returned byte-for-byte verbatim, and surrounding prose, custom frontmatter, and non-Forma fences are preserved intact. - Requirement vs. implementation classification. Editing a
test, refinement contract (refine/:where), orlawinside a.mdfence is automatically classified asrequirement-edit(requiring explicit approval when enforced by branch policy), while normal implementation edits classify asimpl-edit.
Programmatic API
Both the Markdown extractor and store projection helpers are browser-safe (zero node:* imports) and exported from @forma-language/forma:
- Markdown source extraction & remapping:
isMarkdownPath,extractMarkdownBlocks,extractMarkdownProgram,remapMarkdownSpan,remapMarkdownDiagnostics,spliceMarkdownBlocks. - Store Markdown projection:
exportSnapshotToMarkdown,importMarkdownAsTransaction,moduleIdToMarkdownPath.