mdld-parse 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/index.js +13 -41
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -352,6 +352,10 @@ Parse MDLD to RDF quads with lean origin tracking.
|
|
|
352
352
|
- `primary` — Primary metadata quartet: `{ subject, type, label, comment }`
|
|
353
353
|
- `md` — Clean Markdown with annotations stripped
|
|
354
354
|
|
|
355
|
+
`primarySubject` is useful to allow each iri have it's page and vice versa - so we can have arbitrary MD content attached to it. This is where we can render the `md` on the entity page if we have it in our custom `const pages = new Map()`.
|
|
356
|
+
|
|
357
|
+
`md` is useful to detect parsing success: `if(originalText!=parsed.md) {console.log('Parse success. Total annotations: ', originalText.length-md.length) letters.`
|
|
358
|
+
|
|
355
359
|
### `merge(docs, options)`
|
|
356
360
|
|
|
357
361
|
Merge multiple MDLD documents with diff polarity resolution.
|
|
@@ -517,9 +521,11 @@ Comprehensive test suite covering:
|
|
|
517
521
|
- [Formal Specification](./spec/Spec.md)
|
|
518
522
|
- [Compact Spec](./spec/Spec-compact.md)
|
|
519
523
|
- [Ultra Compact Spec](./spec/Spec-ultra.md)
|
|
524
|
+
|
|
520
525
|
- **📚 [Grammar](./grammar/index.md)** — EBNF+TextMate grammar specifications
|
|
521
526
|
- [The TextMate grammar](./grammar/mdld.tmLanguage.json)
|
|
522
527
|
- [ISO 14977 EBNF grammar](./grammar/mdld.ebnf)
|
|
528
|
+
|
|
523
529
|
- **📖 [Documentation](./docs/index.md)** — Complete documentation with guides and references
|
|
524
530
|
- [MD-LD Authoring Guide](./docs/Guide.md)
|
|
525
531
|
- [One Page Guide](./docs/one-page.md)
|
|
@@ -541,6 +547,7 @@ Comprehensive test suite covering:
|
|
|
541
547
|
- [Human-Scale Software & Semantic Infrastructure](./docs/Human-Scale.md)
|
|
542
548
|
- [Quad[] as a Universal Semantic Runtime](./docs/quad-runtime.md)
|
|
543
549
|
- [Use Cases](./docs/Use-Cases.md)
|
|
550
|
+
|
|
544
551
|
- **🎯 [Examples](./examples/index.md)** — Real-world MD-LD examples and use cases
|
|
545
552
|
- [Minimal](./examples/demo/minimal.md)
|
|
546
553
|
- [One-Page Guide](./examples/one-page.md)
|
|
@@ -560,6 +567,10 @@ Comprehensive test suite covering:
|
|
|
560
567
|
- [LLM Time Workflow](./examples/llm-time-workflow.md)
|
|
561
568
|
- [Research Workflow](./examples/workflow.md)
|
|
562
569
|
- [Dogfood](./examples/dogfood.md)
|
|
570
|
+
|
|
571
|
+
- **💻 [Reference server](./server/index.md) - a Node.js implementation of the server for git-powered semantic workflows and publishing
|
|
572
|
+
- [Source code](./server/mdld-server.js)
|
|
573
|
+
|
|
563
574
|
- **🧩 [Ontologies](./ontologies/index.md)** — W3C and related standard ontologies used in RDF
|
|
564
575
|
- [RDF — Resource Description Framework](./ontologies/rdf.md)
|
|
565
576
|
- [RDFS — RDF Schema](./ontologies/rdfs.md)
|
package/dist/index.js
CHANGED
|
@@ -1841,13 +1841,15 @@ function generateNode({ quads, focusIRI, context = {}, compactInline = true, ren
|
|
|
1841
1841
|
compactStats: null
|
|
1842
1842
|
};
|
|
1843
1843
|
const fullContext = Object.assign({}, DEFAULT_CONTEXT, context);
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1844
|
+
const normalizedQuads = normalizeAndSortQuads(quads.filter((q) => q.subject.value === focusIRI || q.predicate.value === focusIRI || q.object.value === focusIRI || q.object.termType === "Literal" && q.object.datatype && (q.object.datatype.value || q.object.datatype) === focusIRI));
|
|
1845
|
+
const { subjectGroups: nodeGroups, reverseIndex } = groupQuadsBySubject(normalizedQuads);
|
|
1846
|
+
const subjectRoots = Array.from(new Set(normalizedQuads.map((q) => q.subject.value)));
|
|
1847
|
+
if (subjectRoots.length === 0) return {
|
|
1846
1848
|
text: "",
|
|
1847
1849
|
context: fullContext,
|
|
1848
1850
|
compactStats: null
|
|
1849
1851
|
};
|
|
1850
|
-
const { text, compactStats } = buildDeterministicMDLD(nodeGroups, fullContext, focusIRI, renderReverse ? reverseIndex : null, compactInline, /* @__PURE__ */ new Map(), lang);
|
|
1852
|
+
const { text, compactStats } = buildDeterministicMDLD(nodeGroups, fullContext, subjectRoots.includes(focusIRI) ? focusIRI : subjectRoots[0], renderReverse ? reverseIndex : null, compactInline, /* @__PURE__ */ new Map(), lang);
|
|
1851
1853
|
return {
|
|
1852
1854
|
text,
|
|
1853
1855
|
context: fullContext,
|
|
@@ -1893,36 +1895,7 @@ function groupQuadsBySubject(quads) {
|
|
|
1893
1895
|
reverseIndex
|
|
1894
1896
|
};
|
|
1895
1897
|
}
|
|
1896
|
-
function
|
|
1897
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1898
|
-
const reverseIndex = /* @__PURE__ */ new Map();
|
|
1899
|
-
const ensure = (key) => {
|
|
1900
|
-
const existing = groups.get(key);
|
|
1901
|
-
if (existing) return existing;
|
|
1902
|
-
const newArray = [];
|
|
1903
|
-
groups.set(key, newArray);
|
|
1904
|
-
return newArray;
|
|
1905
|
-
};
|
|
1906
|
-
for (const quad of quads) {
|
|
1907
|
-
const { subject, predicate, object } = quad;
|
|
1908
|
-
ensure(subject.value).push(quad);
|
|
1909
|
-
if (object.termType === "NamedNode") {
|
|
1910
|
-
ensure(object.value).push(quad);
|
|
1911
|
-
const objectValue = object.value;
|
|
1912
|
-
const reverseList = reverseIndex.get(objectValue);
|
|
1913
|
-
if (reverseList) reverseList.push(quad);
|
|
1914
|
-
else reverseIndex.set(objectValue, [quad]);
|
|
1915
|
-
}
|
|
1916
|
-
ensure(predicate.value).push(quad);
|
|
1917
|
-
if (predicate.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && object.termType === "NamedNode") ensure(object.value).push(quad);
|
|
1918
|
-
if (object.termType === "Literal" && object.datatype) ensure(object.datatype.value || object.datatype).push(quad);
|
|
1919
|
-
}
|
|
1920
|
-
return {
|
|
1921
|
-
nodeGroups: groups,
|
|
1922
|
-
reverseIndex
|
|
1923
|
-
};
|
|
1924
|
-
}
|
|
1925
|
-
function buildDeterministicMDLD(subjectGroups, context, primarySubject = null, reverseIndex = null, compactInline = true, removeBySubject = /* @__PURE__ */ new Map(), lang = null) {
|
|
1898
|
+
function buildDeterministicMDLD(subjectGroups, context, primarySubjectIRI = null, reverseIndex = null, compactInline = true, removeBySubject = /* @__PURE__ */ new Map(), lang = null) {
|
|
1926
1899
|
const textParts = [];
|
|
1927
1900
|
const usedPrefixes = collectUsedPrefixes(subjectGroups, context);
|
|
1928
1901
|
const labelLookup = buildLabelLookup(subjectGroups, lang);
|
|
@@ -1938,7 +1911,6 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null, r
|
|
|
1938
1911
|
for (const [prefix, namespace] of sortedPrefixes) if (prefix !== "@vocab" && !prefix.startsWith("@") && !DEFAULT_CONTEXT[prefix] && usedPrefixes.has(prefix)) textParts.push(generatePrefixDeclaration(prefix, namespace));
|
|
1939
1912
|
if (sortedPrefixes.length > 0) textParts.push("\n");
|
|
1940
1913
|
const sortedSubjects = Array.from(subjectGroups.keys()).sort();
|
|
1941
|
-
const primarySubjectIRI = primarySubject;
|
|
1942
1914
|
const orderedSubjects = primarySubjectIRI ? [primarySubjectIRI, ...sortedSubjects.filter((s) => s !== primarySubjectIRI)] : sortedSubjects;
|
|
1943
1915
|
for (const subjectIRI of orderedSubjects) {
|
|
1944
1916
|
const subjectQuads = subjectGroups.get(subjectIRI);
|
|
@@ -1961,7 +1933,7 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null, r
|
|
|
1961
1933
|
annotations += (annotations ? " " : "") + "label" + langTag;
|
|
1962
1934
|
}
|
|
1963
1935
|
const annotationStr = annotations ? " " + annotations : "";
|
|
1964
|
-
textParts.push(
|
|
1936
|
+
textParts.push(`## ${displayName} {=${shortSubject}${annotationStr}}\n`);
|
|
1965
1937
|
types.forEach((t) => renderedQuads.add(t));
|
|
1966
1938
|
if (labelQuad) renderedQuads.add(labelQuad);
|
|
1967
1939
|
const headingLabel = hasLabel ? labelEntry.value : null;
|
|
@@ -2017,7 +1989,7 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null, r
|
|
|
2017
1989
|
for (const [subjectIRI, removeQuads] of removeBySubject) {
|
|
2018
1990
|
const shortSubject = getCachedShortIRI(subjectIRI, context);
|
|
2019
1991
|
const displayName = extractLocalName(subjectIRI, context);
|
|
2020
|
-
textParts.push(
|
|
1992
|
+
textParts.push(`### ${displayName} {=${shortSubject}}\n`);
|
|
2021
1993
|
for (const quad of removeQuads) textParts.push(generateRetractionText(quad, context));
|
|
2022
1994
|
textParts.push("\n");
|
|
2023
1995
|
}
|
|
@@ -2196,7 +2168,7 @@ function renderTerm(part, isRetracted, prefixes) {
|
|
|
2196
2168
|
const prefixColor = getIRIColor(prefixIRI);
|
|
2197
2169
|
const fullIRI = prefixIRI + local;
|
|
2198
2170
|
const localColor = getIRIColor(fullIRI);
|
|
2199
|
-
return `<span style="color: ${prefixColor}">${escapeHtml(prefix)}</span><span style="color: ${TOKEN_COLORS.marker}">:</span><span
|
|
2171
|
+
return `<span data-iri="${fullIRI}"><span style="color: ${prefixColor}">${escapeHtml(prefix)}</span><span style="color: ${TOKEN_COLORS.marker}">:</span><span style="color: ${localColor}">${escapeHtml(local)}</span></span> `;
|
|
2200
2172
|
}
|
|
2201
2173
|
}
|
|
2202
2174
|
if (part.startsWith("http:") || part.startsWith("https:") || part.startsWith("tag:") || part.startsWith("urn:")) return `<span style="color: ${getIRIColor(part)}">${escapeHtml(part)}</span> `;
|
|
@@ -2272,9 +2244,9 @@ function highlightMDLD(code) {
|
|
|
2272
2244
|
continue;
|
|
2273
2245
|
}
|
|
2274
2246
|
const parsed = parseAnnotation(code.slice(i + 1, endIdx), prefixes);
|
|
2275
|
-
result += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">{</span>`;
|
|
2247
|
+
result += `<span class="mdld-annotation"><span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">{</span>`;
|
|
2276
2248
|
result += parsed;
|
|
2277
|
-
result += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">}</span>`;
|
|
2249
|
+
result += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">}</span></span>`;
|
|
2278
2250
|
i = endIdx + 1;
|
|
2279
2251
|
continue;
|
|
2280
2252
|
}
|
|
@@ -2301,7 +2273,7 @@ function highlightMDLD(code) {
|
|
|
2301
2273
|
const content = code.slice(i + 1, endBracket);
|
|
2302
2274
|
const bracketColor = hasFollowingAnnotation(code, endBracket + 1) ? TOKEN_COLORS.marker : TOKEN_COLORS.value;
|
|
2303
2275
|
const escapedContent = escapeHtml(content);
|
|
2304
|
-
result += `<span style="color: ${bracketColor}; opacity: 0.85">[</span><span style="
|
|
2276
|
+
result += `<span style="color: ${bracketColor}; opacity: 0.85">[</span><span style="background-color: ${bracketColor}15">${escapedContent}</span><span style="color: ${bracketColor}; opacity: 0.85">]</span>`;
|
|
2305
2277
|
i = endBracket + 1;
|
|
2306
2278
|
continue;
|
|
2307
2279
|
}
|
|
@@ -2333,7 +2305,7 @@ function highlightMDLD(code) {
|
|
|
2333
2305
|
const beforeText = headerText.slice(lastIndex, annotationStart);
|
|
2334
2306
|
processedHeaderText += escapeHtml(beforeText);
|
|
2335
2307
|
const parsedAnnotation = parseAnnotation(headerText.slice(annotationStart + 1, annotationEnd), prefixes);
|
|
2336
|
-
processedHeaderText += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">{</span>` + parsedAnnotation + `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">}</span>`;
|
|
2308
|
+
processedHeaderText += `<span class="mdld-annotation"><span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">{</span>` + parsedAnnotation + `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">}</span></span>`;
|
|
2337
2309
|
lastIndex = annotationEnd + 1;
|
|
2338
2310
|
annotationStart = headerText.indexOf("{", lastIndex);
|
|
2339
2311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdld-parse",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Write RDF knowledge graphs as plain Markdown. Parse to quads, generate back, merge documents. The human-friendly semantic web format.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rdf",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"triple-store"
|
|
25
25
|
],
|
|
26
26
|
"type": "module",
|
|
27
|
-
"packageManager": "pnpm@11.24.0+sha512.bd27e345e976dcb0be0b7a1228217b049a817e21b1f355c90dbe7dc46671895a8bc1e6d06c24554505ea93ea0b45f489a27ec1bfbc8de6a9659fca0f16fa0000",
|
|
28
27
|
"main": "./dist/index.js",
|
|
29
28
|
"exports": {
|
|
30
29
|
".": "./dist/index.js"
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
"scripts": {
|
|
36
35
|
"test": "node tests/index.js",
|
|
37
36
|
"dev": "vite dev",
|
|
38
|
-
"build": "vite build && vite build --config vite.config.lib.js && cp -r docs/ dist/docs/ && cp -r examples/ dist/examples/ && cp -r grammar/ dist/grammar/ && cp -r ontologies/ dist/ontologies/ && cp -r spec/ dist/spec/ && cp -r README.md dist/README.md && cp -r docs.html dist/docs.html && cp -r demo/ dist/demo/"
|
|
37
|
+
"build": "vite build && vite build --config vite.config.lib.js && cp -r docs/ dist/docs/ && cp -r server/ dist/server/ && cp -r examples/ dist/examples/ && cp -r grammar/ dist/grammar/ && cp -r ontologies/ dist/ontologies/ && cp -r spec/ dist/spec/ && cp -r README.md dist/README.md && cp -r docs.html dist/docs.html && cp -r demo/ dist/demo/ && cp -r src/ dist/src/"
|
|
39
38
|
},
|
|
40
39
|
"author": "davay42",
|
|
41
40
|
"repository": {
|
|
@@ -47,17 +46,18 @@
|
|
|
47
46
|
"url": "https://github.com/davay42/mdld-parse/issues"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"@unocss/extractor-pug": "^66.
|
|
49
|
+
"@unocss/extractor-pug": "^66.10.2",
|
|
51
50
|
"@vitejs/plugin-vue": "^6.0.8",
|
|
52
51
|
"@vueuse/core": "^14.4.0",
|
|
53
52
|
"codejar": "^4.3.0",
|
|
54
|
-
"markdown-it": "^15.0.
|
|
55
|
-
"n3": "^2.
|
|
53
|
+
"markdown-it": "^15.0.2",
|
|
54
|
+
"n3": "^2.7.12",
|
|
56
55
|
"shiki": "^4.4.3",
|
|
57
|
-
"unocss": "^66.
|
|
58
|
-
"vite": "^8.
|
|
56
|
+
"unocss": "^66.10.2",
|
|
57
|
+
"vite": "^8.3.0",
|
|
59
58
|
"vite-plugin-singlefile": "^2.3.3",
|
|
60
59
|
"vscode-textmate": "^9.3.2",
|
|
61
60
|
"vue": "^3.6.0-beta.17"
|
|
62
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"packageManager": "pnpm@11.26.0+sha512.fc0e2bf890b9f983611f1ab68c0637bce914390653699f83c1a78b005ed25f2c81e77920c8fd8eee2ecf0b58b28cdcb00a84d97f69bcf7c56b2f344710238664"
|
|
63
63
|
}
|