autumnnote 1.9.1 → 1.10.0

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.
@@ -5596,7 +5596,7 @@ function _domToMd(node, depth = 0) {
5596
5596
  * @returns {boolean} `true` if any Markdown-like pattern is present, `false` otherwise.
5597
5597
  */
5598
5598
  function isMarkdown(text) {
5599
- return /^#{1,6} [^\s]|^[ \t]*[-*+] [^\s]|^[ \t]*\d+\. [^\s]|^> [^\s]|^```|^\*{2}[^*\n]+\*{2}/m.test(text) || /^.+\n=+\s*$/m.test(text) || /^.+\n-{2,}\s*$/m.test(text);
5599
+ return /^#{1,6} [^\s]|^[ \t]*[-*+] [^\s]|^[ \t]*\d+\. [^\s]|^> [^\s]|^```|^\*{2}[^*\n]+\*{2}/m.test(text) || /^.+\n=+\s*$/m.test(text) || /^.+\n-{2,}\s*$/m.test(text) || /^---\s*\n(?:[\s\S]*?\n)?(?:---|\.\.\.)\s*(?:\n|$)/.test(text) || /^\|.+\|[ \t]*\n\|[ \t:|-]+\|/m.test(text);
5600
5600
  }
5601
5601
  /**
5602
5602
  * Converts a Markdown string to an HTML string.
@@ -5604,7 +5604,12 @@ function isMarkdown(text) {
5604
5604
  * @returns {string}
5605
5605
  */
5606
5606
  function markdownToHTML(text) {
5607
- const lines = text.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
5607
+ let lines = text.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
5608
+ lines = _stripFrontmatter(lines);
5609
+ const refs = _extractReferenceDefinitions(lines);
5610
+ lines = refs.clean;
5611
+ _linkDefs = refs.linkDefs;
5612
+ _footnoteIds = refs.footnoteIds;
5608
5613
  const out = [];
5609
5614
  let i = 0;
5610
5615
  while (i < lines.length) {
@@ -5704,6 +5709,76 @@ function markdownToHTML(text) {
5704
5709
  }
5705
5710
  return out.join("");
5706
5711
  }
5712
+ /** Reference-link and footnote definitions collected per markdownToHTML() call. */
5713
+ var _linkDefs = /* @__PURE__ */ new Map();
5714
+ var _footnoteIds = /* @__PURE__ */ new Set();
5715
+ /**
5716
+ * Strips a leading YAML frontmatter block (--- ... --- or --- ... ...) from
5717
+ * the line array, only when it is the very first line and the enclosed body
5718
+ * looks like YAML (key: value / list items / indented continuations) — this
5719
+ * disambiguates real frontmatter from a horizontal rule followed by prose.
5720
+ * @param {string[]} lines
5721
+ * @returns {string[]}
5722
+ */
5723
+ function _stripFrontmatter(lines) {
5724
+ if ((lines[0] || "").trim() !== "---") return lines;
5725
+ let closeIdx = -1;
5726
+ for (let j = 1; j < lines.length; j++) {
5727
+ const t = lines[j].trim();
5728
+ if (t === "---" || t === "...") {
5729
+ closeIdx = j;
5730
+ break;
5731
+ }
5732
+ }
5733
+ if (closeIdx === -1) return lines;
5734
+ if (!lines.slice(1, closeIdx).every((l) => l.trim() === "" || /^[ \t]*[\w$.-]+\s*:(\s|$)/.test(l) || /^[ \t]*-\s+\S/.test(l) || /^[ \t]+\S/.test(l))) return lines;
5735
+ let start = closeIdx + 1;
5736
+ if (lines[start] !== void 0 && lines[start].trim() === "") start++;
5737
+ return lines.slice(start);
5738
+ }
5739
+ /**
5740
+ * Extracts GFM reference-link definitions (`[ref]: url "title"`) and footnote
5741
+ * definitions (`[^id]: text`) from the line array, skipping fenced code
5742
+ * regions. Returns the definition-free line array plus lookup maps.
5743
+ * @param {string[]} lines
5744
+ * @returns {{ clean: string[], linkDefs: Map<string, {href: string, title?: string}>, footnoteIds: Set<string> }}
5745
+ */
5746
+ function _extractReferenceDefinitions(lines) {
5747
+ const linkDefs = /* @__PURE__ */ new Map();
5748
+ const footnoteIds = /* @__PURE__ */ new Set();
5749
+ const clean = [];
5750
+ let inFence = false;
5751
+ const linkDefRe = /^\[([^\]]+)\]:\s*(\S+)(?:\s+"([^"]*)")?\s*$/;
5752
+ const footnoteDefRe = /^\[\^([^\]]+)\]:\s*(.+)$/;
5753
+ for (const line of lines) {
5754
+ if (/^```/.test(line)) {
5755
+ inFence = !inFence;
5756
+ clean.push(line);
5757
+ continue;
5758
+ }
5759
+ if (!inFence) {
5760
+ const fm = footnoteDefRe.exec(line);
5761
+ if (fm) {
5762
+ footnoteIds.add(fm[1]);
5763
+ continue;
5764
+ }
5765
+ const lm = linkDefRe.exec(line);
5766
+ if (lm) {
5767
+ linkDefs.set(lm[1].trim().toLowerCase(), {
5768
+ href: lm[2],
5769
+ title: lm[3]
5770
+ });
5771
+ continue;
5772
+ }
5773
+ }
5774
+ clean.push(line);
5775
+ }
5776
+ return {
5777
+ clean,
5778
+ linkDefs,
5779
+ footnoteIds
5780
+ };
5781
+ }
5707
5782
  /**
5708
5783
  * Splits a GFM table row string into trimmed cell strings.
5709
5784
  * '| a | b | c |' → ['a', 'b', 'c']
@@ -5767,6 +5842,19 @@ function _parseListBlock(lines, startIdx) {
5767
5842
  function _inline(text) {
5768
5843
  text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_, alt, src) => `<img src="${_escAttr(src)}" alt="${_escAttr(alt)}" class="an-image">`);
5769
5844
  text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, label, href) => `<a href="${_escAttr(href)}">${_esc(label)}</a>`);
5845
+ text = text.replace(/\[([^\]]+)\]\[([^\]]*)\]/g, (m, label, ref) => {
5846
+ const def = _linkDefs.get((ref || label).trim().toLowerCase());
5847
+ if (!def) return m;
5848
+ const titleAttr = def.title ? ` title="${_escAttr(def.title)}"` : "";
5849
+ return `<a href="${_escAttr(def.href)}"${titleAttr}>${_esc(label)}</a>`;
5850
+ });
5851
+ text = text.replace(/\[([^\]]+)\]/g, (m, label) => {
5852
+ const def = _linkDefs.get(label.trim().toLowerCase());
5853
+ if (!def) return m;
5854
+ const titleAttr = def.title ? ` title="${_escAttr(def.title)}"` : "";
5855
+ return `<a href="${_escAttr(def.href)}"${titleAttr}>${_esc(label)}</a>`;
5856
+ });
5857
+ text = text.replace(/\[\^([^\]]+)\]/g, (m, id) => _footnoteIds.has(id) ? `<sup>[${_esc(id)}]</sup>` : m);
5770
5858
  text = text.replace(/\*{3}([^*\n]+?)\*{3}/g, (_, c) => `<strong><em>${_esc(c)}</em></strong>`);
5771
5859
  text = text.replace(/_{3}([^_\n]+?)_{3}/g, (_, c) => `<strong><em>${_esc(c)}</em></strong>`);
5772
5860
  text = text.replace(/\*{2}([^*\n]+?)\*{2}/g, (_, c) => `<strong>${_esc(c)}</strong>`);
@@ -17581,7 +17669,7 @@ var AutumnNote = {
17581
17669
  /** All pre-built button definitions — accessible in every module format including UMD/CJS. */
17582
17670
  buttons,
17583
17671
  /** Library version */
17584
- version: "1.9.1"
17672
+ version: "1.10.0"
17585
17673
  };
17586
17674
  /**
17587
17675
  * @param {string|Element|NodeList|Element[]} selector