mdld-parse 0.2.5 → 0.2.6
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 +17 -1
- package/index.js +43 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,12 +94,28 @@ Each predicate form determines the graph edge:
|
|
|
94
94
|
|
|
95
95
|
### Subject Declaration
|
|
96
96
|
|
|
97
|
-
Set
|
|
97
|
+
Set current subject (emits no quads):
|
|
98
98
|
|
|
99
99
|
```markdown
|
|
100
100
|
## Apollo 11 {=ex:apollo11}
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
#### Fragment Syntax
|
|
104
|
+
|
|
105
|
+
Create fragment IRIs relative to current subject:
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
# Document {=ex:document}
|
|
109
|
+
{=#summary}
|
|
110
|
+
[Content] {name}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```turtle
|
|
114
|
+
ex:document#summary schema:name "Content" .
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Fragments replace any existing fragment and require a current subject.
|
|
118
|
+
|
|
103
119
|
Subject remains in scope until reset with `{=}` or new subject declared.
|
|
104
120
|
|
|
105
121
|
### Type Declaration
|
package/index.js
CHANGED
|
@@ -73,6 +73,13 @@ function parseSemanticBlock(raw) {
|
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
if (token.startsWith('=#')) {
|
|
77
|
+
const fragment = token.substring(2);
|
|
78
|
+
result.subject = `=#${fragment}`;
|
|
79
|
+
result.entries.push({ kind: 'fragment', fragment, relRange: { start: relStart, end: relEnd }, raw: token });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
76
83
|
if (token.startsWith('=')) {
|
|
77
84
|
const iri = token.substring(1);
|
|
78
85
|
result.subject = iri;
|
|
@@ -469,7 +476,22 @@ function processAnnotation(carrier, sem, state) {
|
|
|
469
476
|
}
|
|
470
477
|
|
|
471
478
|
const previousSubject = state.currentSubject;
|
|
472
|
-
let newSubject =
|
|
479
|
+
let newSubject = null;
|
|
480
|
+
|
|
481
|
+
if (sem.subject) {
|
|
482
|
+
if (sem.subject.startsWith('=#')) {
|
|
483
|
+
// Handle fragment syntax
|
|
484
|
+
const fragment = sem.subject.substring(2);
|
|
485
|
+
if (state.currentSubject) {
|
|
486
|
+
// Replace any existing fragment in current subject
|
|
487
|
+
const baseIRI = state.currentSubject.value.split('#')[0];
|
|
488
|
+
newSubject = state.df.namedNode(`${baseIRI}#${fragment}`);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
// Regular IRI
|
|
492
|
+
newSubject = state.df.namedNode(expandIRI(sem.subject, state.ctx));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
473
495
|
if (newSubject) state.currentSubject = newSubject;
|
|
474
496
|
|
|
475
497
|
const S = state.currentSubject;
|
|
@@ -522,7 +544,16 @@ function processListContext(contextSem, listTokens, state, contextSubject = null
|
|
|
522
544
|
if (listToken.attrs) {
|
|
523
545
|
const itemSem = parseSemanticBlock(listToken.attrs);
|
|
524
546
|
if (itemSem.subject && itemSem.subject !== 'RESET') {
|
|
525
|
-
|
|
547
|
+
if (itemSem.subject.startsWith('=#')) {
|
|
548
|
+
// Handle fragment syntax in list items
|
|
549
|
+
const fragment = itemSem.subject.substring(2);
|
|
550
|
+
if (state.currentSubject) {
|
|
551
|
+
const baseIRI = state.currentSubject.value.split('#')[0];
|
|
552
|
+
itemSubject = state.df.namedNode(`${baseIRI}#${fragment}`);
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
itemSubject = state.df.namedNode(expandIRI(itemSem.subject, state.ctx));
|
|
556
|
+
}
|
|
526
557
|
itemSubjectCarrier = { type: 'list', text: listToken.text, attrs: listToken.attrs, range: listToken.range };
|
|
527
558
|
}
|
|
528
559
|
}
|
|
@@ -532,7 +563,16 @@ function processListContext(contextSem, listTokens, state, contextSubject = null
|
|
|
532
563
|
if (carrier.attrs) {
|
|
533
564
|
const itemSem = parseSemanticBlock(carrier.attrs);
|
|
534
565
|
if (itemSem.subject && itemSem.subject !== 'RESET') {
|
|
535
|
-
|
|
566
|
+
if (itemSem.subject.startsWith('=#')) {
|
|
567
|
+
// Handle fragment syntax in inline carriers
|
|
568
|
+
const fragment = itemSem.subject.substring(2);
|
|
569
|
+
if (state.currentSubject) {
|
|
570
|
+
const baseIRI = state.currentSubject.value.split('#')[0];
|
|
571
|
+
itemSubject = state.df.namedNode(`${baseIRI}#${fragment}`);
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
itemSubject = state.df.namedNode(expandIRI(itemSem.subject, state.ctx));
|
|
575
|
+
}
|
|
536
576
|
itemSubjectCarrier = carrier;
|
|
537
577
|
break;
|
|
538
578
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdld-parse",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A standards-compliant parser for **MD-LD (Markdown-Linked Data)** — a human-friendly RDF authoring format that extends Markdown with semantic annotations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|