mdld-parse 0.2.8 → 0.2.10

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +43 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@ MD-LD allows you to author RDF graphs directly in Markdown using explicit `{...}
14
14
  # Apollo 11 {=ex:apollo11 .SpaceMission}
15
15
 
16
16
  Launch: [1969-07-16] {startDate ^^xsd:date}
17
- Crew: [Neil Armstrong] {=?ex:armstrong ?crewMember fullName}
17
+ Crew: [Neil Armstrong] {=?ex:armstrong ?crewMember name}
18
18
  Description: [First crewed Moon landing] {description}
19
19
 
20
20
  [Section] {=?#overview ?hasPart}
@@ -29,7 +29,7 @@ ex:apollo11 a schema:SpaceMission ;
29
29
  schema:crewMember ex:armstrong ;
30
30
  schema:description "First crewed Moon landing" .
31
31
 
32
- ex:armstrong schema:fullName "Neil Armstrong" .
32
+ ex:armstrong schema:name "Neil Armstrong" .
33
33
  ```
34
34
 
35
35
  ## Core Features
package/index.js CHANGED
@@ -24,7 +24,6 @@ export function hash(str) {
24
24
  return Math.abs(h).toString(16).slice(0, 12);
25
25
  }
26
26
 
27
- // IRI Utilities
28
27
  export function expandIRI(term, ctx) {
29
28
  if (term == null) return null;
30
29
  const raw = typeof term === 'string' ? term : (typeof term === 'object' && typeof term.value === 'string') ? term.value : String(term);
@@ -281,6 +280,41 @@ function extractInlineCarriers(text, baseOffset = 0) {
281
280
  let pos = 0;
282
281
 
283
282
  while (pos < text.length) {
283
+ // Try emphasis patterns first (before brackets)
284
+ const emphasisMatch = text.match(/^[*__`]+(.+?)[*__`]+\s*\{([^}]+)\}/, pos);
285
+ if (emphasisMatch) {
286
+ const carrierText = emphasisMatch[1];
287
+ const valueRange = [baseOffset + emphasisMatch[0].length, baseOffset + emphasisMatch[0].length + emphasisMatch[1].length];
288
+ carriers.push({
289
+ type: 'emphasis',
290
+ text: carrierText,
291
+ attrs: `{${emphasisMatch[2]}}`,
292
+ attrsRange: [baseOffset + emphasisMatch[0].length + emphasisMatch[1].length + 2, baseOffset + emphasisMatch[0].length + emphasisMatch[1].length + emphasisMatch[2].length],
293
+ valueRange,
294
+ range: [baseOffset + emphasisMatch[0].length, baseOffset + emphasisMatch[0].length + emphasisMatch[1].length]
295
+ });
296
+ pos = baseOffset + emphasisMatch[0].length + emphasisMatch[1].length + emphasisMatch[2].length;
297
+ continue;
298
+ }
299
+
300
+ // Try code spans
301
+ const codeMatch = text.match(/^``(.+?)``\s*\{([^}]+)\}/, pos);
302
+ if (codeMatch) {
303
+ const carrierText = codeMatch[1];
304
+ const valueRange = [baseOffset + 2, baseOffset + 2 + codeMatch[1].length];
305
+ carriers.push({
306
+ type: 'code',
307
+ text: carrierText,
308
+ attrs: `{${codeMatch[2]}}`,
309
+ attrsRange: [baseOffset + 2 + codeMatch[1].length + 2, baseOffset + 2 + codeMatch[1].length + 2],
310
+ valueRange,
311
+ range: [baseOffset + 2, baseOffset + 2 + codeMatch[1].length + 2]
312
+ });
313
+ pos = baseOffset + 2 + codeMatch[1].length + 2;
314
+ continue;
315
+ }
316
+
317
+ // Try bracket patterns (original logic)
284
318
  const bracketStart = text.indexOf('[', pos);
285
319
  if (bracketStart === -1) break;
286
320
 
@@ -372,7 +406,6 @@ function createBlock(subject, types, predicates, entries, range, attrsRange, val
372
406
  };
373
407
  }
374
408
 
375
- // Quad Utilities
376
409
  function quadIndexKey(subject, predicate, object) {
377
410
  const objKey = object.termType === 'Literal'
378
411
  ? JSON.stringify({ t: 'Literal', v: object.value, lang: object.language || '', dt: object.datatype?.value || '' })
@@ -413,7 +446,6 @@ function parseQuadIndexKey(key) {
413
446
  }
414
447
  }
415
448
 
416
- // Semantic Slot Utilities
417
449
  function createSemanticSlotId(subject, predicate) {
418
450
  return hash(`${subject.value}|${predicate.value}`);
419
451
  }
@@ -628,11 +660,17 @@ function processListContext(contextSem, listTokens, state, contextSubject = null
628
660
 
629
661
  contextSem.predicates.forEach(pred => {
630
662
  const P = state.df.namedNode(expandIRI(pred.iri, state.ctx));
631
- if (pred.form === '^' || pred.form === '^?') {
663
+
664
+ // According to MD-LD spec: list predicates that connect to item subjects MUST use object predicate forms (?p or ^?p)
665
+ // Literal predicate forms (p, ^p) in list scope emit no quads
666
+ if (pred.form === '^?') {
667
+ // Reverse object property: O —p→ S
632
668
  emitQuad(state.quads, state.origin.quadIndex, 'list-context', itemSubject, P, contextSubject, state.df);
633
- } else {
669
+ } else if (pred.form === '?') {
670
+ // Object property: S —p→ O
634
671
  emitQuad(state.quads, state.origin.quadIndex, 'list-context', contextSubject, P, itemSubject, state.df);
635
672
  }
673
+ // Note: pred.form === '' and pred.form === '^' are intentionally ignored (literal predicate forms)
636
674
  });
637
675
 
638
676
  const prevSubject = state.currentSubject;
@@ -735,8 +773,6 @@ export function parse(text, options = {}) {
735
773
  return { quads: state.quads, origin: state.origin, context: state.ctx };
736
774
  }
737
775
 
738
-
739
- // Text Processing Utilities
740
776
  function readSpan(block, text, spanType = 'attrs') {
741
777
  const range = spanType === 'attrs' ? block?.attrsRange : block?.valueRange;
742
778
  if (!range) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdld-parse",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
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",