mdld-parse 0.3.3 → 0.3.4

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 (2) hide show
  1. package/package.json +4 -1
  2. package/src/parse.js +9 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdld-parse",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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",
@@ -34,5 +34,8 @@
34
34
  "homepage": "https://mdld.js.org",
35
35
  "bugs": {
36
36
  "url": "https://github.com/davay42/mdld-parse/issues"
37
+ },
38
+ "devDependencies": {
39
+ "n3": "^2.0.1"
37
40
  }
38
41
  }
package/src/parse.js CHANGED
@@ -193,20 +193,20 @@ function extractInlineCarriers(text, baseOffset = 0) {
193
193
  continue;
194
194
  }
195
195
 
196
- break;
196
+ pos++; // Advance to next character if no carrier found
197
197
  }
198
198
 
199
199
  return carriers;
200
200
  }
201
201
 
202
- function calcCarrierRanges(match, baseOffset, offset = 0) {
203
- const valueStart = baseOffset + offset;
202
+ function calcCarrierRanges(match, baseOffset, matchStart) {
203
+ const valueStart = baseOffset + matchStart;
204
204
  const valueEnd = valueStart + match[1].length;
205
- const attrsStart = valueEnd + 2;
206
- const attrsEnd = attrsStart + match[2].length;
205
+ const attrsStart = matchStart + match[0].indexOf('{');
206
+ const attrsEnd = attrsStart + match[2].length + 2; // +2 for { and }
207
207
  return {
208
208
  valueRange: [valueStart, valueEnd],
209
- attrsRange: [attrsStart, attrsEnd],
209
+ attrsRange: [attrsStart + 1, attrsEnd - 1], // Exclude braces
210
210
  range: [valueStart, attrsEnd],
211
211
  pos: attrsEnd
212
212
  };
@@ -217,7 +217,7 @@ function tryExtractEmphasisCarrier(text, pos, baseOffset) {
217
217
  const match = INLINE_CARRIER_PATTERNS.EMPHASIS.exec(text);
218
218
  if (!match) return null;
219
219
 
220
- const ranges = calcCarrierRanges(match, baseOffset, match[0].length);
220
+ const ranges = calcCarrierRanges(match, baseOffset, match.index);
221
221
  return createCarrier('emphasis', match[1], `{${match[2]}}`,
222
222
  ranges.attrsRange, ranges.valueRange, ranges.range, ranges.pos);
223
223
  }
@@ -227,14 +227,14 @@ function tryExtractCodeCarrier(text, pos, baseOffset) {
227
227
  const match = INLINE_CARRIER_PATTERNS.CODE_SPAN.exec(text);
228
228
  if (!match) return null;
229
229
 
230
- const ranges = calcCarrierRanges(match, baseOffset, 2);
230
+ const ranges = calcCarrierRanges(match, baseOffset, match.index);
231
231
  return createCarrier('code', match[1], `{${match[2]}}`,
232
232
  ranges.attrsRange, ranges.valueRange, ranges.range, ranges.pos);
233
233
  }
234
234
 
235
235
  function tryExtractBracketCarrier(text, pos, baseOffset) {
236
236
  const bracketStart = text.indexOf('[', pos);
237
- if (bracketStart === -1) return null;
237
+ if (bracketStart === -1 || bracketStart !== pos) return null;
238
238
 
239
239
  const bracketEnd = findMatchingBracket(text, bracketStart);
240
240
  if (!bracketEnd) return null;