Skip to content

feat: DOT-LD import and markdown export#13

Merged
jpmccu merged 4 commits into
mainfrom
copilot/add-import-export-functions-dot-ld
May 6, 2026
Merged

feat: DOT-LD import and markdown export#13
jpmccu merged 4 commits into
mainfrom
copilot/add-import-export-functions-dot-ld

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Adds import and export support for DOT-LD — a markdown extension for embedding formal knowledge graph structures in technical documentation.

Core library (packages/core/src/io/dot-ld.js)

  • Import (importFromDotLD): parses ::config blocks (type definitions + entity assignments), ::rel blocks (->, <-, <->), and [[EntityName]] prose references into Boxes graph format. Bidirectional <-> edges round-trip as a pair of directed edges sharing a _dotldBidi token. Undefined entities (referenced but not assigned a type) are created automatically.
  • Export (exportToDotLD): converts palette node types → type definitions, nodes → entity assignments, edges → ::rel blocks. Bidi pairs collapse back to <->.
  • Both wired up as dotLdImporter / dotLdExporter descriptors following the existing I/O plugin contract.

Example DOT-LD document that round-trips cleanly:

# HVAC System

::config
equipment: round-rectangle, #2196F3, 120
component: ellipse, #4CAF50, 80

ChillerSystem: type=equipment
Pump: type=component
::

The [[ChillerSystem]] circulates water via a [[Pump]].

::rel ChillerSystem -> Pump [uses] ::

ReDoS hardening

Config block bodies are extracted with String.indexOf rather than a greedy [\s\S]*? regex. The ::rel pattern is anchored to single lines (^…$ with m flag) and label/quoted-value capture groups are length-capped ({0,200} / {0,500}).

Registration (packages/web/public/app.js)

dotld importer and dotld markdown exporter added to the existing I/O registry.

Copilot AI and others added 4 commits May 6, 2026 17:35
- packages/core/src/io/dot-ld.js: parse ::config blocks (type defs +
  entity assignments), ::rel blocks (→, ←, ↔), [[EntityName]] refs;
  export to DOT-LD markdown; importer/exporter descriptors
- packages/web/public/io/exporters/dot-ld-html.js: standalone LODE-style
  HTML page with sidebar TOC, entity-types section, per-entity detail
  (properties + in/out relationships), relationships table, ontology
  metadata from owl:Ontology node or graph title/description
- packages/core/src/index.js: export importFromDotLD, exportToDotLD,
  dotLdImporter, dotLdExporter
- packages/web/public/app.js: register dotld importer and dotld /
  dotld-html exporters
- packages/core/tests/dot-ld-io.test.js: 36 tests covering import,
  export, bidirectional edges, backward arrows, multi-config blocks,
  entity properties, undefined entities, and round-trip fidelity

Agent-Logs-Url: https://github.com/jpmccu/boxes/sessions/cd481b95-9eea-429a-82cc-5c359ff556ac

Co-authored-by: jpmccu <602385+jpmccu@users.noreply.github.com>
- Replace CONFIG_BLOCK_RE lazy [\s\S]*? with string-based block extraction
  to eliminate polynomial backtracking on malformed config blocks
- Anchor REL_RE to single lines (^...$, m flag) and use [^\]\n]* instead
  of [^\]]* to prevent cross-line backtracking
- Tighten darkenColor hex validation from < 7 to !== 7

Agent-Logs-Url: https://github.com/jpmccu/boxes/sessions/cd481b95-9eea-429a-82cc-5c359ff556ac

Co-authored-by: jpmccu <602385+jpmccu@users.noreply.github.com>
- Cap PROP_PAIR_RE quoted string lengths at 500 chars
- Cap REL_RE label length at 200 chars
- Replace remaining [\s\S]*? config-stripping regexes with string-based
  stripConfigBlocks() helper in parseEntityRefs and extractDescription
- Use toISOString().split('T')[0] for date formatting in HTML exporter
- Derive section numbers from tocItems array instead of ad-hoc arithmetic

Agent-Logs-Url: https://github.com/jpmccu/boxes/sessions/cd481b95-9eea-429a-82cc-5c359ff556ac

Co-authored-by: jpmccu <602385+jpmccu@users.noreply.github.com>
The DOT-LD exporter now produces only pure DOT-LD markdown.
Deleted dot-ld-html.js and removed its import/registration from app.js.

Agent-Logs-Url: https://github.com/jpmccu/boxes/sessions/cd481b95-9eea-429a-82cc-5c359ff556ac

Co-authored-by: jpmccu <602385+jpmccu@users.noreply.github.com>
@jpmccu jpmccu marked this pull request as ready for review May 6, 2026 17:42
@jpmccu jpmccu merged commit f0d8ff6 into main May 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants