mdld-parse 1.1.0 → 1.1.2

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.
@@ -1,4 +1,4 @@
1
- //#region src/constants.js
1
+ // src/constants.js
2
2
  /**
3
3
  * Shared utilities for MD-LD Parser and Renderer
4
4
  * Ensures DRY code and consistent CommonMark processing
@@ -19,8 +19,7 @@ var XSD_BOOLEAN = "http://www.w3.org/2001/XMLSchema#boolean";
19
19
  var XSD_INTEGER = "http://www.w3.org/2001/XMLSchema#integer";
20
20
  var XSD_DOUBLE = "http://www.w3.org/2001/XMLSchema#double";
21
21
  var URL_REGEX = /^(https?|ftp|mailto|tag|nih|urn|uuid|did|web|ipfs|ipns|data|file|urn:uuid):/;
22
- //#endregion
23
- //#region src/utils.js
22
+ // src/utils.js
24
23
  var VALID_URI_SCHEMES = /^(https?|ftp|mailto|tag|nih|urn|uuid|did|web|ipfs|ipns|data|file):/;
25
24
  var Term = class {
26
25
  constructor(id) {
@@ -431,8 +430,7 @@ function createLiteral(value, datatype, language, context, dataFactory) {
431
430
  if (language) return dataFactory.literal(value, language);
432
431
  return dataFactory.literal(value);
433
432
  }
434
- //#endregion
435
- //#region src/tokenizers.js
433
+ // src/tokenizers.js
436
434
  /**
437
435
  * Character-based Tokenizers for MDLD
438
436
  *
@@ -504,6 +502,8 @@ function detectHeading(line) {
504
502
  attrs = attrsMatch[1];
505
503
  content = trimmed.slice(0, -attrsMatch[0].length).trim();
506
504
  }
505
+ content = content.replace(/[ \t]+#+[ \t]*$/, "");
506
+ if (/^#+$/.test(content)) content = "";
507
507
  return {
508
508
  depth,
509
509
  content,
@@ -526,7 +526,7 @@ function detectList(line) {
526
526
  else if (char >= "0" && char <= "9") {
527
527
  let numEnd = pos + 1;
528
528
  while (numEnd < line.length && line[numEnd] >= "0" && line[numEnd] <= "9") numEnd++;
529
- if (numEnd >= line.length || line[numEnd] !== ".") return null;
529
+ if (numEnd >= line.length || line[numEnd] !== "." && line[numEnd] !== ")") return null;
530
530
  marker = line.slice(pos, numEnd + 1);
531
531
  contentStart = numEnd + 1;
532
532
  } else return null;
@@ -592,6 +592,113 @@ function detectStandaloneSubject(line) {
592
592
  if (pos < line.length) return null;
593
593
  return { content };
594
594
  }
595
+ var HTML_BLOCK_TAGS = /* @__PURE__ */ new Set([
596
+ "address",
597
+ "article",
598
+ "aside",
599
+ "base",
600
+ "basefont",
601
+ "blockquote",
602
+ "body",
603
+ "caption",
604
+ "center",
605
+ "col",
606
+ "colgroup",
607
+ "dd",
608
+ "details",
609
+ "dialog",
610
+ "dir",
611
+ "div",
612
+ "dl",
613
+ "dt",
614
+ "fieldset",
615
+ "figcaption",
616
+ "figure",
617
+ "footer",
618
+ "form",
619
+ "frame",
620
+ "frameset",
621
+ "h1",
622
+ "h2",
623
+ "h3",
624
+ "h4",
625
+ "h5",
626
+ "h6",
627
+ "head",
628
+ "header",
629
+ "hr",
630
+ "html",
631
+ "iframe",
632
+ "legend",
633
+ "li",
634
+ "link",
635
+ "main",
636
+ "menu",
637
+ "menuitem",
638
+ "nav",
639
+ "noframes",
640
+ "ol",
641
+ "optgroup",
642
+ "option",
643
+ "p",
644
+ "param",
645
+ "search",
646
+ "section",
647
+ "summary",
648
+ "table",
649
+ "tbody",
650
+ "td",
651
+ "tfoot",
652
+ "th",
653
+ "thead",
654
+ "title",
655
+ "tr",
656
+ "track",
657
+ "ul"
658
+ ]);
659
+ var HTML_RAW_TEXT_TAGS = /* @__PURE__ */ new Set([
660
+ "script",
661
+ "pre",
662
+ "style",
663
+ "textarea"
664
+ ]);
665
+ /**
666
+ * Detect indented code block line: 4+ spaces or a tab (CommonMark).
667
+ * Cannot interrupt a paragraph — callers must only check at block start.
668
+ */
669
+ function detectIndentedCode(line) {
670
+ if (line[0] === " ") return { indent: " " };
671
+ if (line[0] === " " && line[1] === " " && line[2] === " " && line[3] === " ") return { indent: " " };
672
+ return null;
673
+ }
674
+ /**
675
+ * Detect an HTML block start (CommonMark HTML blocks).
676
+ * Returns { tag, closeTag, interrupt } or null.
677
+ * - interrupt: whether the block may interrupt a paragraph (type 7 cannot).
678
+ * - closeTag: if set, the block ends on the line containing this string;
679
+ * otherwise it ends at the first blank line.
680
+ */
681
+ function detectHtmlBlock(line, interruptOnly = false) {
682
+ const trimmed = line.trim();
683
+ if (trimmed[0] !== "<") return null;
684
+ const m = trimmed.match(/^<(\/?)([A-Za-z][A-Za-z0-9-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/);
685
+ if (!m) return null;
686
+ const tag = m[2].toLowerCase();
687
+ const closing = m[1] === "/";
688
+ let interrupt = true;
689
+ let closeTag = null;
690
+ if (!closing && HTML_RAW_TEXT_TAGS.has(tag)) closeTag = `</${tag}`;
691
+ else if (!HTML_BLOCK_TAGS.has(tag)) {
692
+ if (closing || m[0] !== trimmed) return null;
693
+ interrupt = false;
694
+ }
695
+ if (interruptOnly && !interrupt) return null;
696
+ return {
697
+ tag,
698
+ closeTag,
699
+ interrupt
700
+ };
701
+ }
595
702
  /**
596
703
  * Find matching closing bracket, accounting for nesting
597
704
  */
@@ -636,6 +743,28 @@ function detectAngleBracketUrl(text, startPos) {
636
743
  contentEnd: closeAngle
637
744
  };
638
745
  }
746
+ var UNICODE_PUNCT_RE = /\p{P}/u;
747
+ var UNICODE_WS_RE = /\s/;
748
+ function isUnicodeWs(ch) {
749
+ return ch === void 0 || UNICODE_WS_RE.test(ch);
750
+ }
751
+ function isUnicodePunct(ch) {
752
+ return ch !== void 0 && UNICODE_PUNCT_RE.test(ch);
753
+ }
754
+ function delimiterFlags(text, start, len, char) {
755
+ const before = start > 0 ? text[start - 1] : void 0;
756
+ const after = start + len < text.length ? text[start + len] : void 0;
757
+ const leftFlanking = !isUnicodeWs(after) && (!isUnicodePunct(after) || isUnicodeWs(before) || isUnicodePunct(before));
758
+ const rightFlanking = !isUnicodeWs(before) && (!isUnicodePunct(before) || isUnicodeWs(after) || isUnicodePunct(after));
759
+ if (char === "_") return {
760
+ canOpen: leftFlanking && (!rightFlanking || isUnicodePunct(before)),
761
+ canClose: rightFlanking && (!leftFlanking || isUnicodePunct(after))
762
+ };
763
+ return {
764
+ canOpen: leftFlanking,
765
+ canClose: rightFlanking
766
+ };
767
+ }
639
768
  /**
640
769
  * Detect emphasis/strong spans: *text* or _text_
641
770
  * EBNF: emphasisSpan = "*", text, "*" | "_", text, "_"
@@ -647,28 +776,35 @@ function detectEmphasis(text, startPos) {
647
776
  let delimCount = 1;
648
777
  while (startPos + delimCount < text.length && text[startPos + delimCount] === char) delimCount++;
649
778
  if (delimCount > 2) return null;
779
+ if (!delimiterFlags(text, startPos, delimCount, char).canOpen) return null;
650
780
  const type = delimCount === 1 ? "emphasis" : "strong";
651
- const closer = char.repeat(delimCount);
652
781
  const contentStart = startPos + delimCount;
653
782
  let pos = contentStart;
783
+ let depth = 0;
654
784
  while (pos < text.length) {
655
- if (text.slice(pos, pos + delimCount) === closer) {
656
- if (pos + delimCount < text.length && text[pos + delimCount] === char) {
657
- pos++;
658
- continue;
785
+ if (text[pos] === char) {
786
+ let runLen = 1;
787
+ while (pos + runLen < text.length && text[pos + runLen] === char) runLen++;
788
+ const flags = delimiterFlags(text, pos, runLen, char);
789
+ if (depth === 0 && flags.canClose && runLen >= delimCount) {
790
+ const content = text.slice(contentStart, pos);
791
+ if (content.length === 0) return null;
792
+ const endPos = pos + delimCount;
793
+ const attrsResult = extractAttributes(text, endPos);
794
+ const finalPos = attrsResult ? attrsResult.endPos : endPos;
795
+ return {
796
+ type,
797
+ content,
798
+ attrs: attrsResult?.attrs || null,
799
+ endPos: finalPos,
800
+ contentStart,
801
+ contentEnd: pos
802
+ };
659
803
  }
660
- const content = text.slice(contentStart, pos);
661
- const endPos = pos + delimCount;
662
- const attrsResult = extractAttributes(text, endPos);
663
- const finalPos = attrsResult ? attrsResult.endPos : endPos;
664
- return {
665
- type,
666
- content,
667
- attrs: attrsResult?.attrs || null,
668
- endPos: finalPos,
669
- contentStart,
670
- contentEnd: pos
671
- };
804
+ if (flags.canClose) depth = Math.max(0, depth - 1);
805
+ else if (flags.canOpen) depth++;
806
+ pos += runLen;
807
+ continue;
672
808
  }
673
809
  pos++;
674
810
  }
@@ -705,6 +841,48 @@ function detectCodeSpan(text, startPos) {
705
841
  }
706
842
  return null;
707
843
  }
844
+ function parseLinkTitle(s) {
845
+ if (s.length < 2) return null;
846
+ const open = s[0];
847
+ const close = s[s.length - 1];
848
+ return open === "\"" && close === "\"" || open === "'" && close === "'" || open === "(" && close === ")" ? s.slice(1, -1) : null;
849
+ }
850
+ function parseLinkDestination(inner) {
851
+ const s = inner.trim();
852
+ if (s === "") return null;
853
+ let dest, rest;
854
+ if (s[0] === "<") {
855
+ const close = s.indexOf(">");
856
+ if (close === -1) return null;
857
+ dest = s.slice(1, close);
858
+ rest = s.slice(close + 1).trim();
859
+ } else {
860
+ let w = 0;
861
+ while (w < s.length && s[w] !== " " && s[w] !== " " && s[w] !== "\n") w++;
862
+ dest = s.slice(0, w);
863
+ rest = s.slice(w).trim();
864
+ let depth = 0;
865
+ for (let k = 0; k < dest.length; k++) {
866
+ if (dest[k] === "(") depth++;
867
+ else if (dest[k] === ")") depth--;
868
+ if (depth < 0) return null;
869
+ }
870
+ if (depth !== 0) return null;
871
+ }
872
+ if (dest === "") return null;
873
+ if (rest !== "") {
874
+ const title = parseLinkTitle(rest);
875
+ if (title === null) return null;
876
+ return {
877
+ dest,
878
+ title
879
+ };
880
+ }
881
+ return {
882
+ dest,
883
+ title: null
884
+ };
885
+ }
708
886
  /**
709
887
  * Detect bracket link: [text](url) or [text]{...} or [text] alone
710
888
  * EBNF: linkSpan = "[", text, "](", text, ")" | "[", text, "]"
@@ -716,14 +894,20 @@ function detectBracketLink(text, startPos) {
716
894
  const linkText = text.slice(startPos + 1, bracketEnd);
717
895
  let pos = bracketEnd + 1;
718
896
  let url = null;
897
+ let title = null;
719
898
  if (pos < text.length && text[pos] === "(") {
720
- const parenEnd = text.indexOf(")", pos + 1);
721
- if (parenEnd !== -1) {
722
- const potentialUrl = text.slice(pos + 1, parenEnd);
723
- const lowerUrl = potentialUrl.toLowerCase();
724
- if (lowerUrl.startsWith("http://") || lowerUrl.startsWith("https://")) url = potentialUrl;
725
- pos = parenEnd + 1;
899
+ let parenEnd = text.indexOf(")", pos + 1);
900
+ while (parenEnd !== -1) {
901
+ const parsed = parseLinkDestination(text.slice(pos + 1, parenEnd));
902
+ if (parsed) {
903
+ url = parsed.dest;
904
+ title = parsed.title;
905
+ pos = parenEnd + 1;
906
+ break;
907
+ }
908
+ parenEnd = text.indexOf(")", parenEnd + 1);
726
909
  }
910
+ if (url === null) return null;
727
911
  } else if (pos < text.length && text[pos] === "<") {
728
912
  const closeAngle = text.indexOf(">", pos + 1);
729
913
  if (closeAngle !== -1) {
@@ -740,6 +924,7 @@ function detectBracketLink(text, startPos) {
740
924
  type: url ? "link" : "span",
741
925
  text: linkText,
742
926
  url,
927
+ title,
743
928
  attrs: attrsResult?.attrs || null,
744
929
  endPos: finalPos,
745
930
  contentStart: startPos + 1,
@@ -750,6 +935,15 @@ function detectBracketLink(text, startPos) {
750
935
  * Scan text for all inline carriers using character-based detection
751
936
  * Memory-optimized version - minimizes object allocations
752
937
  */
938
+ function isEscaped(text, pos) {
939
+ let n = 0;
940
+ let j = pos - 1;
941
+ while (j >= 0 && text[j] === "\\") {
942
+ n++;
943
+ j--;
944
+ }
945
+ return n % 2 === 1;
946
+ }
753
947
  function scanInlineCarriers(text, baseOffset = 0) {
754
948
  const carriers = [];
755
949
  const len = text.length;
@@ -757,7 +951,21 @@ function scanInlineCarriers(text, baseOffset = 0) {
757
951
  while (pos < len) {
758
952
  const char = text[pos];
759
953
  let detected = null;
954
+ if (isEscaped(text, pos)) {
955
+ pos++;
956
+ continue;
957
+ }
760
958
  switch (char) {
959
+ case "!":
960
+ if (text[pos + 1] === "[") {
961
+ const inner = detectBracketLink(text, pos + 1);
962
+ if (inner && inner.url) {
963
+ detected = inner;
964
+ detected.type = "image";
965
+ }
966
+ }
967
+ break;
968
+ case "<":
761
969
  case "<":
762
970
  detected = detectAngleBracketUrl(text, pos);
763
971
  if (detected) {
@@ -801,6 +1009,7 @@ function scanInlineCarriers(text, baseOffset = 0) {
801
1009
  valueRange,
802
1010
  attrs,
803
1011
  url,
1012
+ title: detected.title || null,
804
1013
  pos: detected.endPos
805
1014
  };
806
1015
  if (attrs) carrier.attrsRange = [absContentEnd, absEnd];
@@ -809,8 +1018,7 @@ function scanInlineCarriers(text, baseOffset = 0) {
809
1018
  }
810
1019
  return carriers;
811
1020
  }
812
- //#endregion
813
- //#region src/shared.js
1021
+ // src/shared.js
814
1022
  var FENCE_CLOSE_PATTERNS = /* @__PURE__ */ new Map();
815
1023
  function getFenceClosePattern(fenceChar) {
816
1024
  if (!FENCE_CLOSE_PATTERNS.has(fenceChar)) FENCE_CLOSE_PATTERNS.set(fenceChar, new RegExp(`^(${fenceChar}{3,})`));
@@ -912,7 +1120,7 @@ function resolveObject(sem, state) {
912
1120
  if (sem.object.startsWith("#")) return resolveFragment(sem.object.substring(1), state.currentSubject, state.df);
913
1121
  return state.df.namedNode(expandIRI(sem.object, state.ctx));
914
1122
  }
915
- function escapeHtml$1(text) {
1123
+ function escapeHtml(text) {
916
1124
  if (!text) return "";
917
1125
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
918
1126
  }
@@ -1036,8 +1244,7 @@ function generateRetractionText(quad, context) {
1036
1244
  return `[${value}] {${annotation}}\n`;
1037
1245
  }
1038
1246
  }
1039
- //#endregion
1040
- //#region src/parse.js
1247
+ // src/parse.js
1041
1248
  function parse(firstArg, secondArg = {}) {
1042
1249
  const isNamedParams = typeof firstArg === "object" && firstArg !== null && "text" in firstArg;
1043
1250
  const text = isNamedParams ? firstArg.text : firstArg;
@@ -1130,6 +1337,7 @@ function scanTokens(text) {
1130
1337
  let pos = 0;
1131
1338
  let codeBlock = null;
1132
1339
  let sfcBlock = null;
1340
+ let quoteBlock = null;
1133
1341
  function detectSfcStart(trimmed) {
1134
1342
  if (trimmed.startsWith("<!--")) return true;
1135
1343
  return /^<(script|style|template)\b/i.test(trimmed);
@@ -1172,6 +1380,11 @@ function scanTokens(text) {
1172
1380
  return true;
1173
1381
  }
1174
1382
  const PROCESSORS = [
1383
+ {
1384
+ type: "quoteContent",
1385
+ test: () => quoteBlock !== null,
1386
+ process: handleQuoteContent
1387
+ },
1175
1388
  {
1176
1389
  type: "fence",
1177
1390
  test: (line) => detectFence(line.trim()),
@@ -1300,16 +1513,67 @@ function scanTokens(text) {
1300
1513
  mdLines.push(cleanList);
1301
1514
  return true;
1302
1515
  }
1516
+ function quoteValueStart(line) {
1517
+ return line.startsWith("> ") ? 2 : line.indexOf(">") + 1;
1518
+ }
1519
+ function emitQuoteSegment(qb) {
1520
+ if (!qb.parts.length) return;
1521
+ const last = qb.parts[qb.parts.length - 1];
1522
+ const text = qb.parts.map((p) => p.content).join("\n");
1523
+ tokens.push(createToken("blockquote", [qb.segStart, qb.end], text, last.attrs, calcAttrsRange(last.line, last.attrs, last.lineStart), [qb.segValueStart, qb.valueEnd]));
1524
+ qb.parts = [];
1525
+ qb.segStart = null;
1526
+ }
1303
1527
  function handleBlockquote(line, lineStart, pos) {
1304
1528
  const result = detectBlockquote(line);
1305
- const attrs = result.attrs;
1306
- const valueStartInLine = line.startsWith("> ") ? 2 : line.indexOf(">") + 1;
1307
- const valueEndInLine = valueStartInLine + result.content.length;
1308
- tokens.push(createToken("blockquote", [lineStart, pos - 1], result.content, attrs, calcAttrsRange(line, attrs, lineStart), [lineStart + valueStartInLine, lineStart + valueEndInLine]));
1309
- const cleanBlockquote = `> ${result.content}`;
1310
- mdLines.push(cleanBlockquote);
1529
+ const valueStartInLine = quoteValueStart(line);
1530
+ quoteBlock = {
1531
+ segStart: lineStart,
1532
+ segValueStart: lineStart + valueStartInLine,
1533
+ end: pos - 1,
1534
+ valueEnd: lineStart + valueStartInLine + result.content.length,
1535
+ parts: [{
1536
+ content: result.content,
1537
+ attrs: result.attrs,
1538
+ line,
1539
+ lineStart,
1540
+ valueStartInLine
1541
+ }]
1542
+ };
1543
+ mdLines.push(`> ${result.content}`);
1544
+ if (result.attrs) emitQuoteSegment(quoteBlock);
1311
1545
  return true;
1312
1546
  }
1547
+ function flushQuoteBlock() {
1548
+ if (!quoteBlock) return;
1549
+ emitQuoteSegment(quoteBlock);
1550
+ quoteBlock = null;
1551
+ }
1552
+ function handleQuoteContent(line, lineStart, pos) {
1553
+ const bq = detectBlockquote(line);
1554
+ if (bq) {
1555
+ const valueStartInLine = quoteValueStart(line);
1556
+ const qb = quoteBlock;
1557
+ if (!qb.parts.length) {
1558
+ qb.segStart = lineStart;
1559
+ qb.segValueStart = lineStart + valueStartInLine;
1560
+ }
1561
+ qb.parts.push({
1562
+ content: bq.content,
1563
+ attrs: bq.attrs,
1564
+ line,
1565
+ lineStart,
1566
+ valueStartInLine
1567
+ });
1568
+ qb.end = pos - 1;
1569
+ qb.valueEnd = lineStart + valueStartInLine + bq.content.length;
1570
+ mdLines.push(`> ${bq.content}`);
1571
+ if (bq.attrs) emitQuoteSegment(qb);
1572
+ return true;
1573
+ }
1574
+ flushQuoteBlock();
1575
+ return false;
1576
+ }
1313
1577
  function handlePara(line, lineStart, pos) {
1314
1578
  const leadingWhitespace = line.search(/\S/);
1315
1579
  const valueStart = leadingWhitespace === -1 ? lineStart : lineStart + leadingWhitespace;
@@ -1360,6 +1624,7 @@ function scanTokens(text) {
1360
1624
  pos += line.length + 1;
1361
1625
  for (const processor of PROCESSORS) if (processor.test(line) && processor.process(line, lineStart, pos)) break;
1362
1626
  }
1627
+ flushQuoteBlock();
1363
1628
  return {
1364
1629
  tokens,
1365
1630
  md: mdLines.join("\n")
@@ -1683,8 +1948,7 @@ var TOKEN_PROCESSORS = {
1683
1948
  list: (token, state) => processTokenWithBlockTracking(token, state, processTokenAnnotations, createBlockEntry),
1684
1949
  standalone: (token, state) => processStandaloneSubject(token, state)
1685
1950
  };
1686
- //#endregion
1687
- //#region src/merge.js
1951
+ // src/merge.js
1688
1952
  /**
1689
1953
  * Creates a unique key for quad identity matching - using shared utility
1690
1954
  * @param {Quad} quad
@@ -1791,8 +2055,7 @@ function merge(docs, options = {}) {
1791
2055
  primary: primaryObjects
1792
2056
  };
1793
2057
  }
1794
- //#endregion
1795
- //#region src/generate.js
2058
+ // src/generate.js
1796
2059
  var iriCache = /* @__PURE__ */ new Map();
1797
2060
  var CACHE_SIZE_LIMIT = 1e3;
1798
2061
  function getCachedShortIRI(iri, context) {
@@ -1876,9 +2139,15 @@ function normalizeAndSortQuads(quads) {
1876
2139
  if (sComp !== 0) return sComp;
1877
2140
  const pComp = a.predicate.value.localeCompare(b.predicate.value);
1878
2141
  if (pComp !== 0) return pComp;
1879
- const oA = isLiteral(a.object) ? a.object.value : a.object.value;
1880
- const oB = isLiteral(b.object) ? b.object.value : b.object.value;
1881
- return oA.localeCompare(oB);
2142
+ const oComp = a.object.value.localeCompare(b.object.value);
2143
+ if (oComp !== 0) return oComp;
2144
+ const tComp = String(a.object.termType).localeCompare(String(b.object.termType));
2145
+ if (tComp !== 0) return tComp;
2146
+ const dtA = a.object.datatype?.value ?? a.object.datatype ?? "";
2147
+ const dtB = b.object.datatype?.value ?? b.object.datatype ?? "";
2148
+ const dtComp = String(dtA).localeCompare(String(dtB));
2149
+ if (dtComp !== 0) return dtComp;
2150
+ return String(a.object.language ?? "").localeCompare(String(b.object.language ?? ""));
1882
2151
  });
1883
2152
  }
1884
2153
  function groupQuadsBySubject(quads) {
@@ -2033,8 +2302,244 @@ function buildLabelLookup(subjectGroups, lang = null) {
2033
2302
  }
2034
2303
  return labelLookup;
2035
2304
  }
2036
- //#endregion
2037
- //#region src/render.js
2305
+ // src/render.js
2306
+ function detectHr(line) {
2307
+ return /^(\s*[-*_]\s*){3,}$/.test(line);
2308
+ }
2309
+ function isExternalHref(href) {
2310
+ return /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(href);
2311
+ }
2312
+ function isBlockStart(line) {
2313
+ return !!(detectFence(line.trim()) || detectPrefix(line) || detectHeading(line) || detectList(line) || detectBlockquote(line) || detectHtmlBlock(line) || detectHr(line) || detectStandaloneSubject(line) || detectIndentedCode(line));
2314
+ }
2315
+ function isLazyParagraphContent(content) {
2316
+ const t = content.trim();
2317
+ if (t === "") return false;
2318
+ return !(detectFence(t) || detectHeading(t) || detectHtmlBlock(t) || detectHr(t) || detectStandaloneSubject(t) || detectPrefix(t));
2319
+ }
2320
+ var INLINE_HTML_RE = /<\/?[A-Za-z][A-Za-z0-9-]*(?:\s[^<>]*)?\/?>/g;
2321
+ var ASCII_PUNCT = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
2322
+ var NAMED_ENTITIES = Object.assign(Object.create(null), {
2323
+ amp: "&",
2324
+ lt: "<",
2325
+ gt: ">",
2326
+ quot: "\"",
2327
+ apos: "'",
2328
+ nbsp: "\xA0",
2329
+ copy: "©",
2330
+ reg: "®",
2331
+ trade: "™",
2332
+ hellip: "…",
2333
+ mdash: "—",
2334
+ ndash: "–",
2335
+ lsquo: "‘",
2336
+ rsquo: "’",
2337
+ ldquo: "“",
2338
+ rdquo: "”",
2339
+ laquo: "«",
2340
+ raquo: "»",
2341
+ times: "×",
2342
+ divide: "÷",
2343
+ plusmn: "±",
2344
+ deg: "°",
2345
+ micro: "µ",
2346
+ para: "¶",
2347
+ sect: "§",
2348
+ middot: "·",
2349
+ bull: "•",
2350
+ dagger: "†",
2351
+ Dagger: "‡",
2352
+ permil: "‰",
2353
+ prime: "′",
2354
+ Prime: "″",
2355
+ euro: "€",
2356
+ pound: "£",
2357
+ yen: "¥",
2358
+ cent: "¢",
2359
+ curren: "¤",
2360
+ brvbar: "¦",
2361
+ uml: "¨",
2362
+ ordf: "ª",
2363
+ ordm: "º",
2364
+ iexcl: "¡",
2365
+ iquest: "¿",
2366
+ szlig: "ß",
2367
+ shy: "­",
2368
+ ensp: " ",
2369
+ emsp: " ",
2370
+ thinsp: " ",
2371
+ zwnj: "‌",
2372
+ zwj: "‍",
2373
+ lrm: "‎",
2374
+ rlm: "‏",
2375
+ oline: "‾",
2376
+ frasl: "⁄",
2377
+ weierp: "℘",
2378
+ image: "ℑ",
2379
+ real: "ℜ",
2380
+ alefsym: "ℵ",
2381
+ larr: "←",
2382
+ uarr: "↑",
2383
+ rarr: "→",
2384
+ darr: "↓",
2385
+ harr: "↔",
2386
+ crarr: "↵",
2387
+ lArr: "⇐",
2388
+ uArr: "⇑",
2389
+ rArr: "⇒",
2390
+ dArr: "⇓",
2391
+ hArr: "⇔",
2392
+ forall: "∀",
2393
+ part: "∂",
2394
+ exist: "∃",
2395
+ empty: "∅",
2396
+ nabla: "∇",
2397
+ isin: "∈",
2398
+ notin: "∉",
2399
+ ni: "∋",
2400
+ prod: "∏",
2401
+ sum: "∑",
2402
+ minus: "−",
2403
+ lowast: "∗",
2404
+ radic: "√",
2405
+ prop: "∝",
2406
+ infin: "∞",
2407
+ ang: "∠",
2408
+ and: "∧",
2409
+ or: "∨",
2410
+ cap: "∩",
2411
+ cup: "∪",
2412
+ int: "∫",
2413
+ there4: "∴",
2414
+ sim: "∼",
2415
+ cong: "≅",
2416
+ asymp: "≈",
2417
+ ne: "≠",
2418
+ equiv: "≡",
2419
+ le: "≤",
2420
+ ge: "≥",
2421
+ sub: "⊂",
2422
+ sup: "⊃",
2423
+ nsub: "⊄",
2424
+ sube: "⊆",
2425
+ supe: "⊇",
2426
+ oplus: "⊕",
2427
+ otimes: "⊗",
2428
+ perp: "⊥",
2429
+ sdot: "⋅",
2430
+ lceil: "⌈",
2431
+ rceil: "⌉",
2432
+ lfloor: "⌊",
2433
+ rfloor: "⌋",
2434
+ lang: "〈",
2435
+ rang: "〉",
2436
+ loz: "◊",
2437
+ spades: "♠",
2438
+ clubs: "♣",
2439
+ hearts: "♥",
2440
+ diams: "♦"
2441
+ });
2442
+ function decodeNumericEntity(body) {
2443
+ let digits = body.slice(1);
2444
+ let radix = 10;
2445
+ if (digits[0] === "x" || digits[0] === "X") {
2446
+ radix = 16;
2447
+ digits = digits.slice(1);
2448
+ }
2449
+ if (digits === "") return null;
2450
+ for (let k = 0; k < digits.length; k++) {
2451
+ const c = digits[k];
2452
+ if (!(radix === 10 ? c >= "0" && c <= "9" : c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F")) return null;
2453
+ }
2454
+ const cp = parseInt(digits, radix);
2455
+ if (cp === 0 || cp > 1114111 || cp >= 55296 && cp <= 57343) return "�";
2456
+ try {
2457
+ return String.fromCodePoint(cp);
2458
+ } catch {
2459
+ return "�";
2460
+ }
2461
+ }
2462
+ function decodeInlineText(s) {
2463
+ let out = "";
2464
+ let i = 0;
2465
+ while (i < s.length) {
2466
+ const ch = s[i];
2467
+ if (ch === "\\" && i + 1 < s.length && ASCII_PUNCT.indexOf(s[i + 1]) !== -1) {
2468
+ out += s[i + 1];
2469
+ i += 2;
2470
+ continue;
2471
+ }
2472
+ if (ch === "&") {
2473
+ const semi = s.indexOf(";", i + 1);
2474
+ if (semi !== -1 && semi - i <= 33) {
2475
+ const body = s.slice(i + 1, semi);
2476
+ const decoded = body[0] === "#" ? decodeNumericEntity(body) : Object.prototype.hasOwnProperty.call(NAMED_ENTITIES, body) ? NAMED_ENTITIES[body] : null;
2477
+ if (decoded !== null) {
2478
+ out += decoded;
2479
+ i = semi + 1;
2480
+ continue;
2481
+ }
2482
+ }
2483
+ out += "&";
2484
+ i++;
2485
+ continue;
2486
+ }
2487
+ out += ch;
2488
+ i++;
2489
+ }
2490
+ return out;
2491
+ }
2492
+ function isEscapedAt(s, pos) {
2493
+ let n = 0;
2494
+ let j = pos - 1;
2495
+ while (j >= 0 && s[j] === "\\") {
2496
+ n++;
2497
+ j--;
2498
+ }
2499
+ return n % 2 === 1;
2500
+ }
2501
+ function applyHardBreaks(escaped) {
2502
+ let out = "";
2503
+ let i = 0;
2504
+ while (i < escaped.length) {
2505
+ const nl = escaped.indexOf("\n", i);
2506
+ if (nl === -1) {
2507
+ out += escaped.slice(i);
2508
+ break;
2509
+ }
2510
+ let contentEnd = nl;
2511
+ let hard = false;
2512
+ if (escaped[nl - 1] === "\\" && escaped[nl - 2] !== "\\") {
2513
+ contentEnd = nl - 1;
2514
+ hard = true;
2515
+ } else {
2516
+ let j = nl;
2517
+ while (j > i && escaped[j - 1] === " ") j--;
2518
+ if (nl - j >= 2) {
2519
+ contentEnd = j;
2520
+ hard = true;
2521
+ }
2522
+ }
2523
+ out += escaped.slice(i, contentEnd) + (hard ? "<br />\n" : "\n");
2524
+ i = nl + 1;
2525
+ }
2526
+ return out;
2527
+ }
2528
+ function escapeTextPreserveHtml(s) {
2529
+ let out = "";
2530
+ let last = 0;
2531
+ let m;
2532
+ INLINE_HTML_RE.lastIndex = 0;
2533
+ while (m = INLINE_HTML_RE.exec(s)) {
2534
+ if (isEscapedAt(s, m.index)) {
2535
+ INLINE_HTML_RE.lastIndex = m.index + 1;
2536
+ continue;
2537
+ }
2538
+ out += applyHardBreaks(escapeHtml(decodeInlineText(s.slice(last, m.index)))) + m[0];
2539
+ last = m.index + m[0].length;
2540
+ }
2541
+ return out + applyHardBreaks(escapeHtml(decodeInlineText(s.slice(last))));
2542
+ }
2038
2543
  /**
2039
2544
  * MD-LD UI Renderer
2040
2545
  *
@@ -2053,12 +2558,12 @@ function render(src, options = {}) {
2053
2558
  function getAttrs(rawAnnotation, parsedSem, isLink = false, fallbackHref = null) {
2054
2559
  const attrs = [];
2055
2560
  const classes = [];
2056
- if (rawAnnotation) attrs.push(`data-annotation="${escapeHtml$1("{" + rawAnnotation + "}")}"`);
2561
+ if (rawAnnotation) attrs.push(`data-annotation="${escapeHtml("{" + rawAnnotation + "}")}"`);
2057
2562
  let iri = null;
2058
2563
  if (parsedSem?.subject && parsedSem.subject !== "RESET") iri = safeExpand(parsedSem.subject);
2059
2564
  else if (parsedSem?.object) iri = safeExpand(parsedSem.object);
2060
- if (iri) attrs.push(`data-iri="${escapeHtml$1(iri)}"`);
2061
- if (isLink && fallbackHref) attrs.push(`href="${escapeHtml$1(fallbackHref)}"`);
2565
+ if (iri) attrs.push(`data-iri="${escapeHtml(iri)}"`);
2566
+ if (isLink && fallbackHref) attrs.push(`href="${escapeHtml(fallbackHref)}"`);
2062
2567
  if (parsedSem?.types?.some((t) => !t.remove)) classes.push("typed");
2063
2568
  if (parsedSem?.predicates?.some((p) => p.remove) || parsedSem?.types?.some((t) => t.remove)) classes.push("retracted");
2064
2569
  if (classes.length > 0) attrs.unshift(`class="${classes.join(" ")}"`);
@@ -2075,56 +2580,95 @@ function render(src, options = {}) {
2075
2580
  return `class="${finalClass}"${remainingAttrs ? " " + remainingAttrs : ""}`;
2076
2581
  }
2077
2582
  function renderInline(text) {
2583
+ text = text.replace(/<!--[\s\S]*?-->/g, "");
2078
2584
  const carriers = scanInlineCarriers(text, 0);
2079
- if (carriers.length === 0) return escapeHtml$1(text);
2585
+ if (carriers.length === 0) return escapeTextPreserveHtml(text);
2080
2586
  let out = "";
2081
2587
  let lastPos = 0;
2082
2588
  for (const c of carriers) {
2083
- if (c.range[0] > lastPos) out += escapeHtml$1(text.slice(lastPos, c.range[0]));
2589
+ if (c.range[0] > lastPos) out += escapeTextPreserveHtml(text.slice(lastPos, c.range[0]));
2084
2590
  const sem = c.attrs ? parseSemanticBlock(c.attrs) : null;
2085
2591
  const raw = c.attrs || "";
2086
2592
  const isLink = c.type === "link";
2087
2593
  const fallbackHref = c.url || null;
2088
- let tag = "span";
2089
- let baseClass = "mdld-bracket";
2090
- if (c.type === "link") {
2091
- tag = "a";
2092
- baseClass = "mdld-link";
2093
- } else if (c.type === "code") {
2094
- tag = "code";
2095
- baseClass = "mdld-code";
2096
- } else if (c.type === "strong") {
2097
- tag = "strong";
2098
- baseClass = "mdld-bold";
2099
- } else if (c.type === "emphasis") {
2100
- tag = "em";
2101
- baseClass = "mdld-italic";
2594
+ const titleAttr = c.title ? ` title="${escapeHtml(c.title)}"` : "";
2595
+ if (c.type === "image") {
2596
+ const alt = escapeHtml(c.text);
2597
+ const src = escapeHtml(c.url);
2598
+ const attrString = mergeClasses("mdld-image", getAttrs(raw, sem, false, null));
2599
+ out += `<img src="${src}" alt="${alt}" ${attrString}${titleAttr} />`;
2600
+ } else {
2601
+ let tag = "span";
2602
+ let baseClass = "mdld-bracket";
2603
+ if (c.type === "link") {
2604
+ tag = "a";
2605
+ baseClass = "mdld-link";
2606
+ } else if (c.type === "code") {
2607
+ tag = "code";
2608
+ baseClass = "mdld-code";
2609
+ } else if (c.type === "strong") {
2610
+ tag = "strong";
2611
+ baseClass = "mdld-bold";
2612
+ } else if (c.type === "emphasis") {
2613
+ tag = "em";
2614
+ baseClass = "mdld-italic";
2615
+ }
2616
+ const customAttrs = getAttrs(raw, sem, isLink, fallbackHref);
2617
+ const attrString = mergeClasses(baseClass, isLink && fallbackHref && isExternalHref(fallbackHref) ? customAttrs + " target=\"_blank\" rel=\"noopener noreferrer\"" : customAttrs);
2618
+ const inner = c.type === "code" ? escapeHtml(c.text) : renderInline(c.text);
2619
+ out += `<${tag} ${attrString}${titleAttr}>${inner}</${tag}>`;
2102
2620
  }
2103
- const customAttrs = getAttrs(raw, sem, isLink, fallbackHref);
2104
- const attrString = mergeClasses(baseClass, customAttrs);
2105
- out += `<${tag} ${attrString}>${renderInline(c.text)}</${tag}>`;
2106
2621
  lastPos = c.range[1];
2107
2622
  }
2108
- if (lastPos < text.length) out += escapeHtml$1(text.slice(lastPos));
2623
+ if (lastPos < text.length) out += escapeTextPreserveHtml(text.slice(lastPos));
2109
2624
  return out;
2110
2625
  }
2111
2626
  const out = [];
2112
2627
  let i = 0;
2113
2628
  let codeBlock = null;
2629
+ let inComment = false;
2114
2630
  while (i < lines.length) {
2115
- const line = lines[i];
2631
+ let line = lines[i];
2116
2632
  if (codeBlock) {
2117
2633
  if (new RegExp(`^${codeBlock.fenceChar}{${codeBlock.fenceLength},}\\s*$`).test(line.trim())) {
2118
2634
  const sem = codeBlock.attrs ? parseSemanticBlock(codeBlock.attrs) : null;
2119
2635
  const carrierText = codeBlock.content.join("\n");
2120
2636
  const customAttrs = getAttrs(codeBlock.attrs, sem);
2121
2637
  const attrString = mergeClasses(`mdld-codeblock language-${codeBlock.lang || "text"}`, customAttrs);
2122
- out.push(`<pre><code ${attrString}>${escapeHtml$1(carrierText)}</code></pre>`);
2638
+ out.push(`<pre><code ${attrString}>${escapeHtml(carrierText)}</code></pre>`);
2123
2639
  codeBlock = null;
2124
2640
  } else codeBlock.content.push(line);
2125
2641
  i++;
2126
2642
  continue;
2127
2643
  }
2644
+ if (inComment) {
2645
+ const endIdx = line.indexOf("-->");
2646
+ if (endIdx !== -1) {
2647
+ inComment = false;
2648
+ line = line.slice(endIdx + 3);
2649
+ } else {
2650
+ i++;
2651
+ continue;
2652
+ }
2653
+ }
2654
+ let processedLine = "";
2655
+ let current = line;
2656
+ while (true) {
2657
+ const startIdx = current.indexOf("<!--");
2658
+ if (startIdx === -1) {
2659
+ processedLine += current;
2660
+ break;
2661
+ }
2662
+ const endIdx = current.indexOf("-->", startIdx);
2663
+ if (endIdx === -1) {
2664
+ inComment = true;
2665
+ processedLine += current.slice(0, startIdx);
2666
+ break;
2667
+ }
2668
+ processedLine += current.slice(0, startIdx);
2669
+ current = current.slice(endIdx + 3);
2670
+ }
2671
+ line = processedLine;
2128
2672
  if (line.trim() === "") {
2129
2673
  i++;
2130
2674
  continue;
@@ -2144,7 +2688,7 @@ function render(src, options = {}) {
2144
2688
  const prefix = detectPrefix(line);
2145
2689
  if (prefix) {
2146
2690
  const resolvedIri = context[prefix.prefix];
2147
- out.push(`<div class="mdld-prefix" data-prefix="${prefix.prefix}" data-raw="${escapeHtml$1(prefix.iri)}" data-iri="${escapeHtml$1(resolvedIri)}" style="display:none"></div>`);
2691
+ out.push(`<div class="mdld-prefix" data-prefix="${prefix.prefix}" data-raw="${escapeHtml(prefix.iri)}" data-iri="${escapeHtml(resolvedIri)}" style="display:none"></div>`);
2148
2692
  i++;
2149
2693
  continue;
2150
2694
  }
@@ -2156,33 +2700,82 @@ function render(src, options = {}) {
2156
2700
  i++;
2157
2701
  continue;
2158
2702
  }
2159
- if (detectList(line)) {
2160
- out.push("<ul class=\"mdld-list\">");
2703
+ const list = detectList(line);
2704
+ if (list) {
2705
+ const isOrdered = /^\s*\d+[.)]\s/.test(line);
2706
+ const listTag = isOrdered ? "ol" : "ul";
2707
+ const sameMarker = (m) => isOrdered ? m.marker[m.marker.length - 1] === list.marker[list.marker.length - 1] : m.marker === list.marker;
2708
+ const startNum = isOrdered ? parseInt(list.marker, 10) : 1;
2709
+ const startAttr = isOrdered && startNum !== 1 ? ` start="${startNum}"` : "";
2710
+ out.push(`<${listTag} class="mdld-list"${startAttr}>`);
2711
+ let currentListItemLines = [];
2712
+ let currentAttrs = null;
2713
+ const processListItem = (content, attrs) => {
2714
+ const attrString = mergeClasses("mdld-item", getAttrs(attrs, attrs ? parseSemanticBlock(attrs) : null));
2715
+ out.push(`<li ${attrString}>${renderInline(content.join("\n"))}</li>`);
2716
+ };
2161
2717
  while (i < lines.length) {
2162
2718
  const l = detectList(lines[i]);
2163
- if (!l) break;
2164
- const sem = l.attrs ? parseSemanticBlock(l.attrs) : null;
2165
- const attrString = mergeClasses("mdld-item", getAttrs(l.attrs, sem));
2166
- out.push(`<li ${attrString}>${renderInline(l.content)}</li>`);
2167
- i++;
2719
+ if (l) {
2720
+ const nextIsOrdered = /^\s*\d+[.)]\s/.test(lines[i]);
2721
+ if (currentListItemLines.length > 0 && (nextIsOrdered !== isOrdered || !sameMarker(l))) break;
2722
+ if (currentListItemLines.length > 0) {
2723
+ processListItem(currentListItemLines, currentAttrs);
2724
+ currentListItemLines = [];
2725
+ }
2726
+ currentListItemLines.push(l.content);
2727
+ currentAttrs = l.attrs;
2728
+ i++;
2729
+ } else if (lines[i].trim() === "") {
2730
+ let peek = i + 1;
2731
+ while (peek < lines.length && lines[peek].trim() === "") peek++;
2732
+ if (peek < lines.length) {
2733
+ const nextList = detectList(lines[peek]);
2734
+ if (nextList) {
2735
+ if (/^\s*\d+[.)]\s/.test(lines[peek]) === isOrdered && sameMarker(nextList)) {
2736
+ currentListItemLines.push("");
2737
+ i = peek;
2738
+ continue;
2739
+ }
2740
+ }
2741
+ if (/^\s{2,}/.test(lines[peek]) || /^\t/.test(lines[peek])) {
2742
+ currentListItemLines.push("");
2743
+ i = peek;
2744
+ continue;
2745
+ }
2746
+ }
2747
+ break;
2748
+ } else if (/^\s{2,}/.test(lines[i]) || /^\t/.test(lines[i])) {
2749
+ currentListItemLines.push(lines[i].replace(/^(\s{2,}|\t)/, ""));
2750
+ i++;
2751
+ } else break;
2168
2752
  }
2169
- out.push("</ul>");
2753
+ if (currentListItemLines.length > 0) processListItem(currentListItemLines, currentAttrs);
2754
+ out.push(`</${listTag}>`);
2170
2755
  continue;
2171
2756
  }
2172
2757
  const blockquote = detectBlockquote(line);
2173
2758
  if (blockquote) {
2174
2759
  let quoteLines = [blockquote.content];
2175
2760
  i++;
2761
+ let lazyOk = isLazyParagraphContent(quoteLines[quoteLines.length - 1]);
2176
2762
  while (i < lines.length) {
2177
2763
  const bq = detectBlockquote(lines[i]);
2178
- if (!bq) break;
2179
- quoteLines.push(bq.content);
2764
+ if (bq) {
2765
+ quoteLines.push(bq.attrs ? `${bq.content} {${bq.attrs}}` : bq.content);
2766
+ lazyOk = isLazyParagraphContent(bq.content);
2767
+ i++;
2768
+ continue;
2769
+ }
2770
+ if (!lazyOk || lines[i].trim() === "" || isBlockStart(lines[i])) break;
2771
+ quoteLines.push(lines[i]);
2772
+ lazyOk = true;
2180
2773
  i++;
2181
2774
  }
2182
2775
  const sem = blockquote.attrs ? parseSemanticBlock(blockquote.attrs) : null;
2183
2776
  const attrString = mergeClasses("mdld-quote", getAttrs(blockquote.attrs, sem));
2184
- const carrierText = quoteLines.join("\n");
2185
- out.push(`<blockquote ${attrString}>${renderInline(carrierText)}</blockquote>`);
2777
+ const innerHtml = render(quoteLines.join("\n"), { context });
2778
+ out.push(`<blockquote ${attrString}>${innerHtml}</blockquote>`);
2186
2779
  continue;
2187
2780
  }
2188
2781
  const standalone = detectStandaloneSubject(line);
@@ -2193,9 +2786,51 @@ function render(src, options = {}) {
2193
2786
  i++;
2194
2787
  continue;
2195
2788
  }
2789
+ if (detectHr(line)) {
2790
+ out.push(`<hr class="mdld-hr" />`);
2791
+ i++;
2792
+ continue;
2793
+ }
2794
+ const htmlBlock = detectHtmlBlock(line);
2795
+ if (htmlBlock) {
2796
+ const blockLines = [line];
2797
+ i++;
2798
+ if (htmlBlock.closeTag) {
2799
+ const needle = htmlBlock.closeTag.toLowerCase();
2800
+ while (i < lines.length) {
2801
+ blockLines.push(lines[i]);
2802
+ const done = lines[i].toLowerCase().includes(needle);
2803
+ i++;
2804
+ if (done) break;
2805
+ }
2806
+ } else while (i < lines.length && lines[i].trim() !== "") {
2807
+ blockLines.push(lines[i]);
2808
+ i++;
2809
+ }
2810
+ out.push(blockLines.join("\n"));
2811
+ continue;
2812
+ }
2813
+ if (detectIndentedCode(line)) {
2814
+ const codeLines = [];
2815
+ while (i < lines.length) {
2816
+ const l = lines[i];
2817
+ if (l.trim() === "") {
2818
+ codeLines.push("");
2819
+ i++;
2820
+ continue;
2821
+ }
2822
+ const ind = detectIndentedCode(l);
2823
+ if (!ind) break;
2824
+ codeLines.push(l.slice(ind.indent.length));
2825
+ i++;
2826
+ }
2827
+ while (codeLines.length > 0 && codeLines[codeLines.length - 1] === "") codeLines.pop();
2828
+ out.push(`<pre><code class="mdld-codeblock language-text">${escapeHtml(codeLines.join("\n"))}</code></pre>`);
2829
+ continue;
2830
+ }
2196
2831
  let paraLines = [line];
2197
2832
  i++;
2198
- while (i < lines.length && lines[i].trim() !== "" && !detectFence(lines[i].trim()) && !detectPrefix(lines[i]) && !detectHeading(lines[i]) && !detectList(lines[i]) && !detectBlockquote(lines[i]) && !detectStandaloneSubject(lines[i])) {
2833
+ while (i < lines.length && lines[i].trim() !== "" && !detectFence(lines[i].trim()) && !detectPrefix(lines[i]) && !detectHeading(lines[i]) && !detectList(lines[i]) && !detectBlockquote(lines[i]) && !detectStandaloneSubject(lines[i]) && !detectHr(lines[i]) && !detectHtmlBlock(lines[i], true)) {
2199
2834
  paraLines.push(lines[i]);
2200
2835
  i++;
2201
2836
  }
@@ -2229,6 +2864,7 @@ function buildRenderContext(lines, userContext = {}) {
2229
2864
  * Pure string scanning over our constrained output format.
2230
2865
  * Platform-agnostic: no DOMParser, no browser APIs required.
2231
2866
  */
2867
+ var MDLD_BLOCK_START_RE = /^<(?:p class="mdld-paragraph"|div class="mdld-prefix"|div class="mdld-standalone"|pre><code class="mdld-codeblock|h[1-6] class="mdld-heading"|blockquote class="mdld-quote"|ul class="mdld-list"|ol class="mdld-list"|hr class="mdld-hr")/;
2232
2868
  function deconstruct(html) {
2233
2869
  const blocks = [];
2234
2870
  let pos = 0;
@@ -2262,19 +2898,23 @@ function deconstruct(html) {
2262
2898
  if (ann) blocks.push(ann);
2263
2899
  pos = end + 6;
2264
2900
  } else if (html.startsWith("<pre><code", pos)) {
2901
+ const preClose = html.indexOf(">", pos) + 1;
2902
+ const codeOpenEnd = html.indexOf(">", preClose) + 1;
2903
+ const codeTag = html.slice(preClose, codeOpenEnd);
2904
+ if (!extractAttr(codeTag, "class")?.includes("mdld-codeblock")) {
2905
+ pos = nextTagStart + 1;
2906
+ continue;
2907
+ }
2265
2908
  const closePre = html.indexOf("</code></pre>", pos);
2266
2909
  if (closePre === -1) break;
2267
2910
  const full = html.slice(pos, closePre + 13);
2268
- const preClose = full.indexOf(">") + 1;
2269
- const codeOpenEnd = full.indexOf(">", preClose) + 1;
2270
- const codeTag = full.slice(preClose, codeOpenEnd);
2271
- const content = full.slice(codeOpenEnd, full.length - 13);
2911
+ const content = full.slice(codeOpenEnd - pos, full.length - 13);
2272
2912
  const langMatch = (extractAttr(codeTag, "class") || "").match(/language-(\w+)/);
2273
2913
  const lang = langMatch ? langMatch[1] : "";
2274
2914
  const ann = extractAttr(codeTag, "data-annotation");
2275
2915
  blocks.push(`\`\`\`${lang}${ann ? " " + ann : ""}\n${unescapeHtml(content)}\n\`\`\``);
2276
2916
  pos = closePre + 13;
2277
- } else if (html[pos] === "<" && /^<h[1-6]/.test(html.slice(pos, pos + 4))) {
2917
+ } else if (html[pos] === "<" && /^<h[1-6]/.test(html.slice(pos, pos + 4)) && extractAttr(openTag, "class")?.includes("mdld-heading")) {
2278
2918
  const level = html[pos + 2];
2279
2919
  const closeTag = `</h${level}>`;
2280
2920
  const close = html.indexOf(closeTag, pos);
@@ -2287,7 +2927,7 @@ function deconstruct(html) {
2287
2927
  const ann = extractAttr(openTag, "data-annotation");
2288
2928
  blocks.push(`${hashes} ${deconstructInline(content)}${ann ? " " + ann : ""}`);
2289
2929
  pos = close + closeTag.length;
2290
- } else if (html.startsWith("<blockquote", pos)) {
2930
+ } else if (html.startsWith("<blockquote", pos) && extractAttr(openTag, "class")?.includes("mdld-quote")) {
2291
2931
  const close = html.indexOf("</blockquote>", pos);
2292
2932
  if (close === -1) break;
2293
2933
  const full = html.slice(pos, close + 13);
@@ -2295,15 +2935,19 @@ function deconstruct(html) {
2295
2935
  const openTag = full.slice(0, openEnd);
2296
2936
  const content = full.slice(openEnd, full.length - 13);
2297
2937
  const ann = extractAttr(openTag, "data-annotation");
2298
- const quoted = deconstructInline(content).split("\n").map((l) => l.trim() ? `> ${l}` : ">").join("\n");
2938
+ const quoted = deconstruct(content).split("\n").map((l) => l.trim() ? `> ${l}` : ">").join("\n");
2299
2939
  blocks.push(ann ? `${quoted} ${ann}` : quoted);
2300
2940
  pos = close + 13;
2301
- } else if (html.startsWith("<ul class=\"mdld-list\">", pos)) {
2302
- const close = html.indexOf("</ul>", pos);
2941
+ } else if ((openTag.startsWith("<ul") || openTag.startsWith("<ol")) && extractAttr(openTag, "class")?.includes("mdld-list")) {
2942
+ const isOrdered = openTag.startsWith("<ol");
2943
+ const closeTag = isOrdered ? "</ol>" : "</ul>";
2944
+ const close = html.indexOf(closeTag, pos);
2303
2945
  if (close === -1) break;
2304
- const inner = html.slice(pos + 21, close);
2946
+ const openEnd = html.indexOf(">", pos) + 1;
2947
+ const inner = html.slice(openEnd, close);
2305
2948
  const items = [];
2306
2949
  let itemPos = 0;
2950
+ let counter = isOrdered ? parseInt(extractAttr(openTag, "start") || "1", 10) || 1 : 1;
2307
2951
  while (itemPos < inner.length) {
2308
2952
  const liStart = inner.indexOf("<li", itemPos);
2309
2953
  if (liStart === -1) break;
@@ -2314,16 +2958,46 @@ function deconstruct(html) {
2314
2958
  const openTag = liFull.slice(0, openEnd);
2315
2959
  const liContent = liFull.slice(openEnd, liFull.length - 5);
2316
2960
  const ann = extractAttr(openTag, "data-annotation");
2317
- items.push(`- ${deconstructInline(liContent)}${ann ? " " + ann : ""}`);
2961
+ const lines = deconstructInline(liContent).split("\n");
2962
+ const indent = isOrdered ? " " : " ";
2963
+ const indented = lines.map((l, idx) => idx === 0 ? l : `${indent}${l}`).join("\n");
2964
+ const bullet = isOrdered ? `${counter}. ` : "- ";
2965
+ items.push(`${bullet}${indented}${ann ? " " + ann : ""}`);
2966
+ counter++;
2318
2967
  itemPos = liClose + 5;
2319
2968
  }
2320
2969
  blocks.push(items.join("\n"));
2321
- pos = close + 5;
2970
+ pos = close + closeTag.length;
2971
+ } else if (openTag.startsWith("<hr") && extractAttr(openTag, "class")?.includes("mdld-hr")) {
2972
+ blocks.push("---");
2973
+ pos = tagEnd + 1;
2974
+ } else if (html[pos] === "<" && /^<\/?[A-Za-z]/.test(html.slice(pos, pos + 3))) {
2975
+ let end = pos;
2976
+ while (end < html.length) {
2977
+ const nl = html.indexOf("\n", end);
2978
+ const lineEnd = nl === -1 ? html.length : nl;
2979
+ const line = html.slice(end, lineEnd);
2980
+ if (end !== pos && (line.trim() === "" || MDLD_BLOCK_START_RE.test(line.trimStart()))) break;
2981
+ end = nl === -1 ? html.length : nl + 1;
2982
+ }
2983
+ blocks.push(html.slice(pos, end).trim());
2984
+ pos = end;
2322
2985
  } else pos++;
2323
2986
  }
2324
2987
  return blocks.join("\n\n");
2325
2988
  }
2326
- function deconstructInline(html) {
2989
+ function mdEscapeText(s) {
2990
+ let out = "";
2991
+ for (let i = 0; i < s.length; i++) {
2992
+ const ch = s[i];
2993
+ if (ch === "&") out += "&amp;";
2994
+ else if (ch === "<") out += "&lt;";
2995
+ else if (ch === "\\" || ch === "`" || ch === "*" || ch === "_" || ch === "[" || ch === "]") out += "\\" + ch;
2996
+ else out += ch;
2997
+ }
2998
+ return out;
2999
+ }
3000
+ function deconstructInline(html, inCode = false) {
2327
3001
  let out = "";
2328
3002
  let i = 0;
2329
3003
  while (i < html.length) if (html[i] === "<") {
@@ -2340,12 +3014,28 @@ function deconstructInline(html) {
2340
3014
  const spaceOrEnd = tagContent.search(/[\s/]/);
2341
3015
  const tagName = (spaceOrEnd === -1 ? tagContent : tagContent.slice(0, spaceOrEnd)).toLowerCase();
2342
3016
  const attrs = spaceOrEnd === -1 ? "" : tagContent.slice(spaceOrEnd);
3017
+ if (tagContent.endsWith("/")) {
3018
+ out += deconstructInlineElement(tagName, attrs, "", inCode);
3019
+ i = closeGt + 1;
3020
+ continue;
3021
+ }
2343
3022
  const closeTag = `</${tagName}>`;
2344
3023
  let depth = 1;
2345
3024
  let j = closeGt + 1;
2346
3025
  let found = false;
2347
3026
  while (j < html.length && depth > 0) {
2348
- const nextOpen = html.indexOf(`<${tagName}`, j);
3027
+ let nextOpen = -1;
3028
+ let searchIdx = j;
3029
+ while (searchIdx < html.length) {
3030
+ const idx = html.indexOf(`<${tagName}`, searchIdx);
3031
+ if (idx === -1) break;
3032
+ const nextChar = html[idx + tagName.length + 1];
3033
+ if (nextChar === " " || nextChar === ">" || nextChar === "/" || nextChar === void 0) {
3034
+ nextOpen = idx;
3035
+ break;
3036
+ }
3037
+ searchIdx = idx + 1;
3038
+ }
2349
3039
  const nextClose = html.indexOf(closeTag, j);
2350
3040
  if (nextClose === -1) break;
2351
3041
  if (nextOpen !== -1 && nextOpen < nextClose) {
@@ -2355,7 +3045,7 @@ function deconstructInline(html) {
2355
3045
  depth--;
2356
3046
  if (depth === 0) {
2357
3047
  const inner = html.slice(closeGt + 1, nextClose);
2358
- out += deconstructInlineElement(tagName, attrs, inner);
3048
+ out += deconstructInlineElement(tagName, attrs, inner, inCode);
2359
3049
  i = nextClose + closeTag.length;
2360
3050
  found = true;
2361
3051
  break;
@@ -2370,21 +3060,29 @@ function deconstructInline(html) {
2370
3060
  } else {
2371
3061
  const nextTag = html.indexOf("<", i);
2372
3062
  const textEnd = nextTag === -1 ? html.length : nextTag;
2373
- out += unescapeHtml(html.slice(i, textEnd));
3063
+ const text = unescapeHtml(html.slice(i, textEnd));
3064
+ out += inCode ? text : mdEscapeText(text);
2374
3065
  i = textEnd;
2375
3066
  }
2376
3067
  return out;
2377
3068
  }
2378
- function deconstructInlineElement(tagName, attrs, inner) {
3069
+ function deconstructInlineElement(tagName, attrs, inner, inCode = false) {
2379
3070
  const ann = extractAttr(attrs, "data-annotation");
2380
- const content = deconstructInline(inner);
3071
+ const content = deconstructInline(inner, inCode || tagName === "code");
2381
3072
  const suffix = ann ? " " + ann : "";
3073
+ const title = extractAttr(attrs, "title");
3074
+ const titleStr = title ? ` "${title}"` : "";
2382
3075
  switch (tagName) {
2383
- case "a": return `[${content}](${extractAttr(attrs, "href") || ""})${suffix}`;
3076
+ case "a": return `[${content}](${extractAttr(attrs, "href") || ""}${titleStr})${suffix}`;
3077
+ case "img": {
3078
+ const src = extractAttr(attrs, "src") || "";
3079
+ return `![${extractAttr(attrs, "alt") || ""}](${src}${titleStr})${suffix}`;
3080
+ }
2384
3081
  case "span": return `[${content}]${suffix}`;
2385
3082
  case "code": return `\`${content}\`${suffix}`;
2386
3083
  case "strong": return `**${content}**${suffix}`;
2387
3084
  case "em": return `*${content}*${suffix}`;
3085
+ case "br": return " " + suffix;
2388
3086
  default: return content + suffix;
2389
3087
  }
2390
3088
  }
@@ -2397,328 +3095,7 @@ function extractAttr(tag, name) {
2397
3095
  function unescapeHtml(s) {
2398
3096
  return String(s).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'");
2399
3097
  }
2400
- //#endregion
2401
- //#region src/highlight.js
2402
- /**
2403
- * MD-LD Syntax Highlighter
2404
- *
2405
- * A performant, token-based syntax highlighter for MD-LD (Markdown Linked Data).
2406
- * Uses simple string operations rather than complex grammars for reliability
2407
- * and maintainability.
2408
- *
2409
- * Features:
2410
- * - Token-based parsing with string operations
2411
- * - Markdown formatting support with semantic distinction
2412
- * - Lookahead detection for legal value carriers
2413
- * - Orange semantic markers vs default markdown spans
2414
- * - Annotation, value carrier, and heading highlighting
2415
- */
2416
- function escapeHtml(s) {
2417
- return String(s).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
2418
- }
2419
- var TOKEN_COLORS = {
2420
- text: "#6b7280",
2421
- marker: "#f97316",
2422
- retraction: "#dc2626",
2423
- value: "#eab308",
2424
- annotation: "#4b5563"
2425
- };
2426
- function hasFollowingAnnotation(code, endPos) {
2427
- let i = endPos;
2428
- while (i < code.length && code[i] !== "\n" && code[i] !== "\r") {
2429
- if (code[i] === "{") return true;
2430
- i++;
2431
- }
2432
- return false;
2433
- }
2434
- function processMarkdownFormattingAtPosition(code, startPos) {
2435
- const char = code[startPos];
2436
- if (char === "*" && startPos + 1 < code.length && code[startPos + 1] === "*") {
2437
- const endPos = code.indexOf("**", startPos + 2);
2438
- if (endPos !== -1) {
2439
- const content = code.slice(startPos + 2, endPos);
2440
- const color = hasFollowingAnnotation(code, endPos + 2) ? ` style="color: ${TOKEN_COLORS.marker}"` : "";
2441
- return {
2442
- html: `<span${color}>**</span><strong>${escapeHtml(content)}</strong><span${color}>**</span>`,
2443
- nextIndex: endPos + 2
2444
- };
2445
- }
2446
- }
2447
- if (char === "_" && startPos + 1 < code.length && code[startPos + 1] === "_") {
2448
- const endPos = code.indexOf("__", startPos + 2);
2449
- if (endPos !== -1) {
2450
- const content = code.slice(startPos + 2, endPos);
2451
- const color = hasFollowingAnnotation(code, endPos + 2) ? ` style="color: ${TOKEN_COLORS.marker}"` : "";
2452
- return {
2453
- html: `<span${color}>__</span><strong>${escapeHtml(content)}</strong><span${color}>__</span>`,
2454
- nextIndex: endPos + 2
2455
- };
2456
- }
2457
- }
2458
- if (char === "*") {
2459
- const endPos = code.indexOf("*", startPos + 1);
2460
- if (endPos !== -1) {
2461
- const content = code.slice(startPos + 1, endPos);
2462
- const color = hasFollowingAnnotation(code, endPos + 1) ? ` style="color: ${TOKEN_COLORS.marker}"` : "";
2463
- return {
2464
- html: `<span${color}>*</span><em>${escapeHtml(content)}</em><span${color}>*</span>`,
2465
- nextIndex: endPos + 1
2466
- };
2467
- }
2468
- }
2469
- if (char === "_") {
2470
- const endPos = code.indexOf("_", startPos + 1);
2471
- if (endPos !== -1) {
2472
- const content = code.slice(startPos + 1, endPos);
2473
- const color = hasFollowingAnnotation(code, endPos + 1) ? ` style="color: ${TOKEN_COLORS.marker}"` : "";
2474
- return {
2475
- html: `<span${color}>_</span><em>${escapeHtml(content)}</em><span${color}>_</span>`,
2476
- nextIndex: endPos + 1
2477
- };
2478
- }
2479
- }
2480
- if (char === "`") {
2481
- const endPos = code.indexOf("`", startPos + 1);
2482
- if (endPos !== -1) {
2483
- const content = code.slice(startPos + 1, endPos);
2484
- const color = hasFollowingAnnotation(code, endPos + 1) ? ` style="color: ${TOKEN_COLORS.marker}"` : "";
2485
- return {
2486
- html: `<span${color}>\`</span><code style="background-color:#7773">${escapeHtml(content)}</code><span${color}>\`</span>`,
2487
- nextIndex: endPos + 1
2488
- };
2489
- }
2490
- }
2491
- return null;
2492
- }
2493
- var colorCache = /* @__PURE__ */ new Map();
2494
- function hashIRI(iri) {
2495
- let hash = 0;
2496
- for (let i = 0; i < iri.length; i++) {
2497
- const char = iri.charCodeAt(i);
2498
- hash = (hash << 5) - hash + char;
2499
- hash = hash & hash;
2500
- }
2501
- return Math.abs(hash);
2502
- }
2503
- function getIRIColor(iri) {
2504
- if (colorCache.has(iri)) return colorCache.get(iri);
2505
- const hash = hashIRI(iri);
2506
- const color = `hsl(${hash % 360}, ${15 + hash % 10}%, ${45 + hash % 10}%)`;
2507
- colorCache.set(iri, color);
2508
- return color;
2509
- }
2510
- function extractPrefixes(code) {
2511
- const prefixes = /* @__PURE__ */ new Map();
2512
- const prefixRegex = /^\[(\w+)\]\s*<([^>]*)>\s*$/gm;
2513
- let match;
2514
- while ((match = prefixRegex.exec(code)) !== null) {
2515
- const prefixName = match[1];
2516
- let iri = match[2];
2517
- if (iri.includes(":")) {
2518
- const colonIndex = iri.indexOf(":");
2519
- if (colonIndex > 0) {
2520
- const refPrefix = iri.slice(0, colonIndex);
2521
- const refSuffix = iri.slice(colonIndex + 1);
2522
- if (prefixes.has(refPrefix)) iri = prefixes.get(refPrefix) + refSuffix;
2523
- }
2524
- }
2525
- prefixes.set(prefixName, iri);
2526
- }
2527
- for (const [key, iri] of Object.entries(DEFAULT_CONTEXT)) if (key !== "@vocab") prefixes.set(key, iri);
2528
- return prefixes;
2529
- }
2530
- function renderTerm(part, isRetracted, prefixes) {
2531
- const baseColor = isRetracted ? TOKEN_COLORS.retraction : TOKEN_COLORS.text;
2532
- const colonIndex = part.indexOf(":");
2533
- if (colonIndex > 0) {
2534
- const prefix = part.slice(0, colonIndex);
2535
- const local = part.slice(colonIndex + 1);
2536
- if (prefixes.has(prefix)) {
2537
- const prefixIRI = prefixes.get(prefix);
2538
- const prefixColor = getIRIColor(prefixIRI);
2539
- const fullIRI = prefixIRI + local;
2540
- const localColor = getIRIColor(fullIRI);
2541
- 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> `;
2542
- }
2543
- }
2544
- if (part.startsWith("http:") || part.startsWith("https:") || part.startsWith("tag:") || part.startsWith("urn:")) return `<span style="color: ${getIRIColor(part)}">${escapeHtml(part)}</span> `;
2545
- return `<span style="color: ${baseColor}">${escapeHtml(part)}</span> `;
2546
- }
2547
- function parseAnnotation(content, prefixes) {
2548
- const parts = content.trim().split(/\s+/);
2549
- let result = "";
2550
- let nextTermIsRetracted = false;
2551
- for (let i = 0; i < parts.length; i++) {
2552
- const part = parts[i];
2553
- if (!part) continue;
2554
- if (part.startsWith("=") || part.startsWith("+")) {
2555
- const marker = part[0];
2556
- const rest = part.slice(1);
2557
- result += `<span style="color: ${TOKEN_COLORS.marker}">${escapeHtml(marker)}</span>${renderTerm(rest, false, prefixes)}`;
2558
- continue;
2559
- }
2560
- if (part === "-") {
2561
- nextTermIsRetracted = true;
2562
- result += `<span style="color: ${TOKEN_COLORS.retraction}">${escapeHtml(part)}</span> `;
2563
- continue;
2564
- }
2565
- if (part.startsWith("-") && part.length > 1) {
2566
- result += `<span style="color: ${TOKEN_COLORS.retraction}">${escapeHtml(part)}</span> `;
2567
- continue;
2568
- }
2569
- const isRetracted = nextTermIsRetracted;
2570
- nextTermIsRetracted = false;
2571
- if (part.startsWith("?") || part.startsWith("!")) {
2572
- const marker = part[0];
2573
- const rest = part.slice(1);
2574
- const color = isRetracted ? TOKEN_COLORS.retraction : TOKEN_COLORS.marker;
2575
- result += `<span style="color: ${color}">${escapeHtml(marker)}</span>${renderTerm(rest, isRetracted, prefixes)}`;
2576
- continue;
2577
- }
2578
- if (part.startsWith("^^")) {
2579
- const marker = "^^";
2580
- const rest = part.slice(2);
2581
- const color = isRetracted ? TOKEN_COLORS.retraction : TOKEN_COLORS.marker;
2582
- result += `<span style="color: ${color}">${escapeHtml(marker)}</span>${renderTerm(rest, isRetracted, prefixes)}`;
2583
- continue;
2584
- }
2585
- if (part.startsWith("@")) {
2586
- const marker = "@";
2587
- const rest = part.slice(1);
2588
- const color = isRetracted ? TOKEN_COLORS.retraction : TOKEN_COLORS.marker;
2589
- result += `<span style="color: ${color}">${escapeHtml(marker)}</span>${renderTerm(rest, isRetracted, prefixes)}`;
2590
- continue;
2591
- }
2592
- if (part.startsWith(".")) {
2593
- const marker = ".";
2594
- const rest = part.slice(1);
2595
- const color = isRetracted ? TOKEN_COLORS.retraction : TOKEN_COLORS.marker;
2596
- result += `<span style="color: ${color}">${escapeHtml(marker)}</span>${renderTerm(rest, isRetracted, prefixes)}`;
2597
- continue;
2598
- }
2599
- result += renderTerm(part, isRetracted, prefixes);
2600
- }
2601
- return result.trim();
2602
- }
2603
- function highlightMDLD(code) {
2604
- const prefixes = extractPrefixes(code);
2605
- let result = "";
2606
- let i = 0;
2607
- while (i < code.length) {
2608
- const char = code[i];
2609
- if (char === "{") {
2610
- const endIdx = code.indexOf("}", i);
2611
- if (endIdx === -1) {
2612
- result += escapeHtml(char);
2613
- i++;
2614
- continue;
2615
- }
2616
- const parsed = parseAnnotation(code.slice(i + 1, endIdx), prefixes);
2617
- result += `<span class="mdld-annotation"><span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">{</span>`;
2618
- result += parsed;
2619
- result += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">}</span></span>`;
2620
- i = endIdx + 1;
2621
- continue;
2622
- }
2623
- if (char === "[") {
2624
- const endBracket = code.indexOf("]", i);
2625
- if (endBracket === -1) {
2626
- result += escapeHtml(char);
2627
- i++;
2628
- continue;
2629
- }
2630
- const prefixName = code.slice(i + 1, endBracket);
2631
- let j = endBracket + 1;
2632
- while (j < code.length && /\s/.test(code[j])) j++;
2633
- if (j < code.length && code[j] === "<") {
2634
- const iriEnd = code.indexOf(">", j);
2635
- if (iriEnd !== -1) {
2636
- const iriContent = code.slice(j + 1, iriEnd);
2637
- const prefixColor = prefixes.has(prefixName) ? getIRIColor(prefixes.get(prefixName)) : TOKEN_COLORS.text;
2638
- result += `<span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">[</span><span style="color: ${prefixColor}">${escapeHtml(prefixName)}</span><span style="color: ${TOKEN_COLORS.annotation}; opacity: 0.75">]</span> <span style="color: ${TOKEN_COLORS.text}; opacity: 0.6">&lt;${escapeHtml(iriContent)}&gt;</span>`;
2639
- i = iriEnd + 1;
2640
- continue;
2641
- }
2642
- }
2643
- const content = code.slice(i + 1, endBracket);
2644
- const bracketColor = hasFollowingAnnotation(code, endBracket + 1) ? TOKEN_COLORS.marker : TOKEN_COLORS.value;
2645
- const escapedContent = escapeHtml(content);
2646
- 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>`;
2647
- i = endBracket + 1;
2648
- continue;
2649
- }
2650
- if (char === "*" || char === "_" || char === "`") {
2651
- const processed = processMarkdownFormattingAtPosition(code, i);
2652
- if (processed) {
2653
- result += processed.html;
2654
- i = processed.nextIndex;
2655
- continue;
2656
- }
2657
- }
2658
- if (char === "#") {
2659
- let hashCount = 0;
2660
- let j = i;
2661
- while (j < code.length && code[j] === "#") {
2662
- hashCount++;
2663
- j++;
2664
- }
2665
- if (hashCount <= 6 && (j >= code.length || code[j] === " " || code[j] === " ")) {
2666
- const lineEnd = code.indexOf("\n", j);
2667
- const endIdx = lineEnd === -1 ? code.length : lineEnd;
2668
- const headerText = code.slice(j, endIdx).trim();
2669
- let processedHeaderText = "";
2670
- let lastIndex = 0;
2671
- let annotationStart = headerText.indexOf("{");
2672
- while (annotationStart !== -1) {
2673
- const annotationEnd = headerText.indexOf("}", annotationStart);
2674
- if (annotationEnd === -1) break;
2675
- const beforeText = headerText.slice(lastIndex, annotationStart);
2676
- processedHeaderText += escapeHtml(beforeText);
2677
- const parsedAnnotation = parseAnnotation(headerText.slice(annotationStart + 1, annotationEnd), prefixes);
2678
- 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>`;
2679
- lastIndex = annotationEnd + 1;
2680
- annotationStart = headerText.indexOf("{", lastIndex);
2681
- }
2682
- processedHeaderText += escapeHtml(headerText.slice(lastIndex));
2683
- const hasAnnotation = headerText.includes("{") && headerText.includes("}");
2684
- const headingTag = `h${hashCount}`;
2685
- const headingStyle = `margin: 0; font-weight: 600;`;
2686
- const hashes = "#".repeat(hashCount);
2687
- const hashColor = hasAnnotation ? `color: ${TOKEN_COLORS.marker}; opacity: 0.8` : "";
2688
- result += `<${headingTag} style="${headingStyle}"><span style="${hashColor}">${hashes}</span> ${processedHeaderText}</${headingTag}>`;
2689
- i = endIdx;
2690
- continue;
2691
- }
2692
- }
2693
- if (char === "-" || char === "*") {
2694
- const prevChar = i > 0 ? code[i - 1] : "\n";
2695
- if (prevChar === "\n" || prevChar === "\r" || prevChar === " " || prevChar === " ") {
2696
- if (code[i + 1] === " ") {
2697
- const markerColor = hasFollowingAnnotation(code, i + 2) ? `color: ${TOKEN_COLORS.marker}; opacity: 0.85` : "";
2698
- result += `<span style="${markerColor}">${escapeHtml(char)}</span>`;
2699
- i++;
2700
- continue;
2701
- }
2702
- }
2703
- }
2704
- if (char === ">") {
2705
- const prevChar = i > 0 ? code[i - 1] : "\n";
2706
- if (prevChar === "\n" || prevChar === "\r" || prevChar === " " || prevChar === " ") {
2707
- if (code[i + 1] === " ") {
2708
- const markerColor = hasFollowingAnnotation(code, i + 2) ? `color: ${TOKEN_COLORS.marker}; opacity: 0.85` : "";
2709
- result += `<span style="${markerColor}">${escapeHtml(char)}</span>`;
2710
- i++;
2711
- continue;
2712
- }
2713
- }
2714
- }
2715
- result += escapeHtml(char);
2716
- i++;
2717
- }
2718
- return result;
2719
- }
2720
- //#endregion
2721
- //#region src/index.js
3098
+ // src/index.js
2722
3099
  /**
2723
3100
  * Update the value of a quad in MDLD text and return the updated text
2724
3101
  *
@@ -2734,5 +3111,4 @@ function updateValue({ text, quad, value, origin }) {
2734
3111
  if (!location || !location.valueRange) return text;
2735
3112
  return text.substring(0, location.valueRange.start) + value + text.substring(location.valueRange.end);
2736
3113
  }
2737
- //#endregion
2738
- export { DEFAULT_CONTEXT, DataFactory, deconstruct, expandIRI, generate, generateNode, getIRIColor, hash, hashIRI, highlightMDLD, locate, merge, parse, parseSemanticBlock, render, shortenIRI, updateValue };
3114
+ export { DEFAULT_CONTEXT, DataFactory, deconstruct, expandIRI, generate, generateNode, hash, locate, merge, parse, parseSemanticBlock, render, shortenIRI, updateValue };