mdld-parse 0.2.8 → 0.2.9
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/index.js +35 -5
- package/package.json +1 -1
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
|
}
|
|
@@ -735,8 +767,6 @@ export function parse(text, options = {}) {
|
|
|
735
767
|
return { quads: state.quads, origin: state.origin, context: state.ctx };
|
|
736
768
|
}
|
|
737
769
|
|
|
738
|
-
|
|
739
|
-
// Text Processing Utilities
|
|
740
770
|
function readSpan(block, text, spanType = 'attrs') {
|
|
741
771
|
const range = spanType === 'attrs' ? block?.attrsRange : block?.valueRange;
|
|
742
772
|
if (!range) return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdld-parse",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
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",
|