How monapdx/modular-markup-language works
Purpose and Entry Points
Modular Markup Language (MML) is a meaning-first plain-text markup language. It parses MML source into a structured document tree, semantically validates that tree, and compiles it to HTML.
Primary programmatic entry point: src/index.js. Browser demo entry point: index.html. The public language contract is documented in DOCS/SPEC.md, with registered semantics and nesting rules in DOCS/TAGS.md and DOCS/DEPENDENCIES.md.
Language Grammar and Normalization
src/grammar.js is the authoritative recognition layer for tags, shorthand aliases, attributes, and inline quoted values. It determines whether an input line is markup or must remain literal text, preserving the “text wins” boundary.
Relevant paths:
• src/grammar.js
• DOCS/SHORTHAND.md
• DOCS/TAGS.md
Parse Stage: Source to AST
src/parser.js converts line-oriented MML into an AST. It supports opening-tag-only authoring, explicit optional close tags, inferred/implicit closure when later tags or content change context, merged consecutive text, and ignored blank content lines.
The parser consumes grammar-normalized tag information and produces the tree consumed by validation and compilation; it should not be conflated with semantic enforcement.
Relevant paths:
• src/parser.js
• src/grammar.js
• src/index.js
Semantic Validation Stage
src/validator.js validates parent/child eligibility, required children, and cross-node schema invariants after parsing. It covers core semantic models such as arguments/claims/evidence, timelines and date ranges, calendars and event-day validity, comparison variants, shared-trait groups, media, and ebook structure.
Validation is a distinct boundary: syntactically parseable input may still be semantically invalid.
Relevant paths:
• src/validator.js
• DOCS/DEPENDENCIES.md
• DOCS/SPEC.md
HTML Compilation and Specialized Rendering
src/compiler.js transforms valid AST nodes into HTML, emitting explicit closing tags and rendering specialized output such as calendar tables, heading IDs, and generated tables of contents. It is the primary output-target layer and owns presentation-oriented HTML generation rather than the parser or validator.
Relevant paths:
• src/compiler.js
• src/index.js
• index.html
Ebook Schema and TOC Generation
Ebook support is a specialized schema layered on the common AST: an ebook requires content and can declare metadata, cover media, TOC, styles, and JavaScript. toc is declarative; headings within ebook content drive generated navigation. Web-only style/script tags are relevant to HTML export but not plain-text export.
Relevant paths:
• src/ebook-schema.js
• src/ebook.js
• src/compiler.js
Runtime, Delivery, and Documentation Export
The implementation is JavaScript/Node.js, with npm-based test execution (package.json, tests/run-tests.js). The root HTML file provides a browser-facing parser/validator/compiler demo. Documentation is maintained as source Markdown under DOCS/ and has checked-in HTML output under export/; Node scripts support that documentation export and local serving workflow.
Relevant paths:
• package.json
• index.html
• scripts/build-notes-html.mjs
• scripts/notes-server.mjs
• export/index.html
Main entry points: grammar.js Grammar normalization · validator.js Semantic validator · index.js Public API · compiler.js HTML compiler
Components 20
Language contract
- Language specification · Public MML language contract.
DOCS/SPEC.md - Tag semantics · Registered tags and nesting rules.
DOCS/TAGS.md - Shorthand rules
DOCS/SHORTHAND.md - Semantic dependencies · Required-child and cross-node semantic rules.
DOCS/DEPENDENCIES.md
MML processing pipeline
- MML source · Line-oriented meaning-first markup.
- Public API · Programmatic parse, validation, and compilation entry point.
src/index.js - Grammar normalization · Recognizes tags, aliases, attributes, and literal-text boundary.
src/grammar.js - AST parser · Builds a tree with inferred closure and merged text.
src/parser.js - Document AST · Common representation shared by validation and output.
- Semantic validator · Enforces nesting, required children, and cross-node invariants.
src/validator.js - Valid AST
- HTML compiler · Generates HTML, closing tags, heading IDs, tables, and TOCs.
src/compiler.js - HTML output
Ebook rendering
- Ebook schema · Defines ebook content, metadata, cover, TOC, styles, and scripts.
src/ebook-schema.js - Ebook support · Uses ebook headings to supply declarative TOC navigation.
src/ebook.js
Delivery and docs
- Browser demo · Interactive parser, validator, and compiler delivery.
index.html - Node/npm runtime · Runs implementation, tests, and documentation scripts.
package.json - Documentation export · Builds checked-in HTML from Markdown documentation.
scripts/build-notes-html.mjs - Documentation server · Serves local documentation workflow.
scripts/notes-server.mjs - Exported documentation
export/index.html
Connections 21
- MML source → Public API: submitted to
- Public API → Grammar normalization: normalizes lines
- Grammar normalization → AST parser: recognized tags
- AST parser → Document AST: produces
- Document AST → Semantic validator: validates
- Semantic validator → Valid AST: accepts
- Valid AST → HTML compiler: compiles
- HTML compiler → HTML output: emits
- Language specification → Grammar normalization: defines syntax
- Tag semantics → Grammar normalization: defines tags
- Shorthand rules → Grammar normalization: defines aliases
- Semantic dependencies → Semantic validator: defines constraints
- Tag semantics → Semantic validator: defines nesting
- Ebook schema → Semantic validator: extends validation
- Ebook schema → Ebook support: defines model
- Ebook support → HTML compiler: supplies TOC rendering
- Browser demo → Public API: uses
- Node/npm runtime → Documentation export: runs
- Node/npm runtime → Documentation server: runs
- Documentation export → Exported documentation: generates
- Documentation server → Exported documentation: serves