Markdown-Linked Data — Human-friendly knowledge graph authoring.
Write semantic data in natural Markdown, parse to RDF quads, build deterministic state machines.
MD-LD is not just another RDF syntax. It's a universal semantic writing interface that removes the intermediary between human text and machine-readable graphs.
Traditional systems require:
Human → UI → App Logic → Hidden Database → APIs → Exports
MD-LD enables:
Human text → Graph immediately
Core value: Author and maintain knowledge graphs as plain text with deterministic round-trip safety. No platforms, databases, or proprietary SaaS mediation required.
[ex] <http://example.org/>
# Document {=ex:doc .Article label}
[Alice] {=ex:alice ?ex:author .prov:Person ex:firstName label}
[Smith] {ex:lastName}Generates RDF quads that work with n3.js, rdflib, and any RDF/JS-compatible library.
pnpm install mdld-parseimport { parse, generate, merge } from 'mdld-parse';
// Parse MDLD to RDF quads
const result = parse({ text: mdldString });
console.log(result.quads); // RDF/JS quads
console.log(result.primary); // Primary metadata (subject, type, label, comment)
console.log(result.statements); // Elevated statements
console.log(result.origin); // Provenance tracking
// Generate MDLD from quads
const { text } = generate({ quads: result.quads });
// Merge multiple documents (CRDT-style)
const merged = merge([doc1, doc2, doc3]);Most software today uses graphs internally but hides them behind UIs:
- Notion, Slack, Google Docs — Human interfaces over hidden graphs
- CRMs, task apps, note apps — Proprietary data silos
- Social networks — Platform-controlled knowledge prisons
Users cannot access the graph directly. Semantics are hidden. Data is locked in products.
MD-LD removes the intermediary. Writing becomes publishing. Publishing becomes graph construction.
Key benefits:
- Graph sovereignty — You own text, graph, provenance, execution, history
- No central platform required — Works offline, in browsers, on servers
- Universal semantic substrate — Agents can read, reason, write, execute, validate
- Continuous semantic narrative — Unifies chat, tasks, notes, emails, calendar, files
- Native time dimension — Every action, statement, correction becomes part of the graph
- Decentralized authority — RFC 4151 tag: URIs enable self-sovereign identity without central registries
[alice] <tag:alice@example.com,2026:>
# Meeting Notes {=alice:meeting-2024-01-15 .alice:Meeting}
Attendees:
- **Alice** {+alice:alice ?alice:attendee label}
- **Bob** {+alice:bob ?alice:attendee label}
Action items:
- **Review proposal** {+alice:task-1 ?alice:actionItem label}# API Endpoint {=api:/users/:id .api:Endpoint}
[GET] {api:method}
[/users/:id] {api:path}# Paper {=alice:paper-semantic-markdown .alice:ScholarlyArticle}
[Semantic Web] {label}
[Alice Johnson] {=alice:alice-johnson ?alice:author}
[2024-01] {alice:datePublished ^^xsd:gYear}# Understanding MD-LD {=blog:post-mdld .blog:Post}
[MD-LD] {blog:emphasized label} allows you to embed RDF directly in Markdown.- 📖 Documentation — Complete documentation with guides and references
- 🎯 Examples — Real-world MD-LD examples and use cases
- 📋 Specification — Formal specification and test suite
- 🔄 Diff Generation — Automatic diff document generation for CRDT workflows
- 🔗 Prefix folding — Build hierarchical namespaces with CURIE-based IRI authoring
- 📍 Subject declarations —
{=IRI}and{=#fragment}for context setting - 🎯 Object IRIs —
{+IRI}and{+#fragment}for temporary object declarations - 🔄 Three predicate forms —
p(S→L),?p(S→O),!p(O→S) - 🏷️ Type declarations —
.Classfor rdf:type triples - 📅 Datatypes & language —
^^xsd:dateand@ensupport - 🧩 Fragments — Document structuring with
{=#fragment} - ⚡ Polarity system — Sophisticated diff authoring with
+and-prefixes - 📍 Origin tracking — Complete provenance with lean quad-to-source mapping
- 🎯 Elevated statements — Automatic rdf:Statement pattern detection
- 🏷️ Primary metadata quartet — Subject, type, label, comment for document identity
- 🔄 Round-trip safety — Deterministic parse ↔ generate cycles
pnpm install mdld-parseimport { parse, generate, merge } from 'mdld-parse';
const mdld = `[ex] <http://example.org/>
# Document {=ex:doc .Article label}
[Alice] {=ex:alice ?ex:author .prov:Person ex:firstName label}
[Smith] {ex:lastName}`;
const result = parse({ text: mdld });
console.log(result.quads); // RDF/JS quads
console.log(result.primary); // { subject, type, label, comment }
console.log(result.statements); // Elevated statements<script type="module">
import { parse } from 'https://cdn.jsdelivr.net/npm/mdld-parse/+esm';
const result = parse('[ex] <http://example.org/>\n\n# Hello {=ex:hello label}');
</script>Bundle size: 84KB unminified, 19KB gzipped
MD-LD encodes a directed labeled multigraph where three nodes may be in scope:
- S — current subject (IRI)
- O — object resource (IRI from link/image)
- L — literal value (string + optional datatype/language)
Each predicate form determines the graph edge:
| Form | Edge | Example | Meaning |
|---|---|---|---|
p |
S → L | [Alice] {label} |
literal property |
?p |
S → O | [NASA] {=ex:nasa ?org} |
object property |
!p |
O → S | [Parent] {=ex:p !hasPart} |
reverse object |
Set current subject (emits no quads):
## Apollo 11 {=ex:apollo11}Emit rdf:type triple:
## Apollo 11 {=ex:apollo11 .SpaceMission .Event}Inline value carriers emit literal properties:
# Mission {=ex:apollo11}
[Neil Armstrong] {ex:commander}
[1969] {ex:year ^^xsd:gYear}
[Historic mission] {ex:description @en}Links create relationships (use ? prefix):
# Mission {=ex:apollo11}
[NASA] {=ex:nasa ?ex:organizer}Declare resources inline with {+iri}:
# Mission {=ex:apollo11}
[Neil Armstrong] {+ex:armstrong ?ex:commander .Person}Use + and - for retractions:
# Update value
[Person] {=ex:person}
[Alice] {-ex:name}
[Bob] {ex:name}
# Remove triple
[Person] {=ex:person}
[Alice] {-ex:friend}Parse MDLD to RDF quads with lean origin tracking.
Parameters:
text(string, required) — MDLD formatted textcontext(object, optional) — Prefix mappingsdataFactory(object, optional) — Custom RDF/JS DataFactorygraph(string, optional) — Named graph IRI
Returns: { quads, remove, statements, origin, context, primarySubject, primary, md }
quads— RDF/JS Quads (final resolved graph state)remove— RDF/JS Quads (external retractions for diff workflows)statements— Elevated SPO quads from rdf:Statement patternsorigin— Lean origin tracking for UI navigationcontext— Final context with prefixesprimarySubject— String IRI or null (canonical append identity)primary— Primary metadata quartet:{ subject, type, label, comment }md— Clean Markdown with annotations stripped
Merge multiple MDLD documents with diff polarity resolution.
Parameters:
docs(array) — Array of markdown strings or ParseResult objectsoptions(object, optional):context(object) — Prefix mappings
Returns: { quads, remove, statements, origin, context, primarySubjects, primary }
quads— RDF/JS Quads (final resolved graph state)remove— RDF/JS Quads (external retractions)statements— Elevated statements from all documentsorigin— Merge origin with document trackingcontext— Final context with prefixesprimarySubjects— Array of string IRIs (canonical identities)primary— Array of primary metadata objects
Use case: CRDT-style state management with append-only documents.
Generate deterministic MDLD from RDF quads.
Parameters:
quads(array, required) — RDF/JS Quads to convertcontext(object, optional) — Prefix mappingsprimarySubject(string, optional) — IRI to place first in outputcompactInline(boolean, optional) — Inline type/label compaction (default:false)renderReverse(boolean, optional) — Reverse connections as!p(default:false)remove(array, optional) — RDF/JS Quads to retract (for diff generation)
Returns: { text, context, compactStats }
text— Generated MDLD textcontext— Full context with prefixescompactStats— Compaction metrics
Features: Visual styling, label-in-heading, round-trip safe, diff generation.
Generate node-centric MDLD for a specific IRI.
Parameters:
quads(array, required) — RDF/JS Quads to searchfocusIRI(string, required) — IRI to center view oncontext(object, optional) — Prefix mappingscompactInline(boolean, optional) — Inline compaction (default:true)renderReverse(boolean, optional) — Reverse connections (default:true)
Returns: { text, context, compactStats }
Safety: Returns empty text if focusIRI not found (prevents accidental full database rendering).
Update carrier text of a literal quad in MDLD text.
Parameters:
text(string) — Original MDLD textquad(object) — Quad to updatevalue(string) — New carrier textorigin(object, optional) — ParseResult.origin
Returns: Updated MDLD text (fail-safe)
Use case: Editor applications updating literal values.
Locate quad origin entry for UI navigation.
Returns: { blockId, range, valueRange, carrierType, ... } or null
import {
DEFAULT_CONTEXT, // Default prefix mappings
DataFactory, // RDF/JS DataFactory
hash, // String hashing
expandIRI, // IRI expansion
shortenIRI, // IRI shortening
parseSemanticBlock // Semantic block parsing
} from 'mdld-parse';- Zero dependencies — Pure JavaScript, 84KB unminified (19KB gzipped)
- Streaming-first — Single-pass parsing, O(n) complexity
- Character-based tokenization — 20-28% faster than regex-based approaches
- Standards-compliant — RDF/JS data model, W3C CURIE 1.0 syntax
- Deterministic — Same input always produces same output
- Explicit semantics — No guessing, inference, or heuristics
- Real-time (60fps): Up to 4,527 quads per frame
- Batch processing: Up to 225,059 quads per second
- Memory efficient: ~640 bytes per quad retained after GC
- Streaming-friendly: Full document never in memory
Quads work with:
n3.js— Turtle/N-Triples serializationrdflib.js— RDF storessparqljs— SPARQL queriesrdf-ext— RDF utilities
- RDF 1.1 — Core RDF concepts
- RDFS — Schema vocabulary
- PROV-O — Provenance ontology
- SHACL — Constraint validation
- W3C CURIE 1.0 — Compact URI syntax
pnpm testComprehensive test suite covering:
- Syntax parsing and tokenization
- Context management and prefix folding
- Polarity system and retractions
- Elevated statements detection
- Primary metadata extraction
- Round-trip parse/generate cycles
- Origin tracking and provenance
- Documentation — Complete guides and references
- Specification — Formal specification
- Examples — Real-world examples
- Grammar — EBNF grammar specification
- VS Code Extension — Syntax highlighting (coming soon)