mdld-parse 1.0.8 → 1.1.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.
@@ -719,7 +719,9 @@ function detectBracketLink(text, startPos) {
719
719
  if (pos < text.length && text[pos] === "(") {
720
720
  const parenEnd = text.indexOf(")", pos + 1);
721
721
  if (parenEnd !== -1) {
722
- url = text.slice(pos + 1, parenEnd);
722
+ const potentialUrl = text.slice(pos + 1, parenEnd);
723
+ const lowerUrl = potentialUrl.toLowerCase();
724
+ if (lowerUrl.startsWith("http://") || lowerUrl.startsWith("https://")) url = potentialUrl;
723
725
  pos = parenEnd + 1;
724
726
  }
725
727
  } else if (pos < text.length && text[pos] === "<") {
@@ -2055,11 +2057,8 @@ function render(src, options = {}) {
2055
2057
  let iri = null;
2056
2058
  if (parsedSem?.subject && parsedSem.subject !== "RESET") iri = safeExpand(parsedSem.subject);
2057
2059
  else if (parsedSem?.object) iri = safeExpand(parsedSem.object);
2058
- else if (isLink && fallbackHref) iri = safeExpand(fallbackHref);
2059
- if (iri) {
2060
- attrs.push(`data-iri="${escapeHtml$1(iri)}"`);
2061
- if (isLink) attrs.push(`href="${escapeHtml$1(iri)}"`);
2062
- } else if (isLink && fallbackHref) attrs.push(`href="${escapeHtml$1(fallbackHref)}"`);
2060
+ if (iri) attrs.push(`data-iri="${escapeHtml$1(iri)}"`);
2061
+ if (isLink && fallbackHref) attrs.push(`href="${escapeHtml$1(fallbackHref)}"`);
2063
2062
  if (parsedSem?.types?.some((t) => !t.remove)) classes.push("typed");
2064
2063
  if (parsedSem?.predicates?.some((p) => p.remove) || parsedSem?.types?.some((t) => t.remove)) classes.push("retracted");
2065
2064
  if (classes.length > 0) attrs.unshift(`class="${classes.join(" ")}"`);
@@ -2236,7 +2235,19 @@ function deconstruct(html) {
2236
2235
  while (pos < html.length) {
2237
2236
  while (pos < html.length && /\s/.test(html[pos])) pos++;
2238
2237
  if (pos >= html.length) break;
2239
- if (html.startsWith("<div class=\"mdld-prefix\"", pos)) {
2238
+ const nextTagStart = html.indexOf("<", pos);
2239
+ if (nextTagStart === -1) break;
2240
+ const tagEnd = html.indexOf(">", nextTagStart);
2241
+ if (tagEnd === -1) break;
2242
+ const openTag = html.slice(nextTagStart, tagEnd + 1);
2243
+ if (openTag.startsWith("<p") && extractAttr(openTag, "class")?.includes("mdld-paragraph")) {
2244
+ const close = html.indexOf("</p>", pos);
2245
+ if (close === -1) break;
2246
+ const openEnd = html.indexOf(">", pos) + 1;
2247
+ const content = html.slice(openEnd, close);
2248
+ blocks.push(deconstructInline(content));
2249
+ pos = close + 4;
2250
+ } else if (openTag.startsWith("<div") && extractAttr(openTag, "class")?.includes("mdld-prefix")) {
2240
2251
  const end = html.indexOf("></div>", pos);
2241
2252
  if (end === -1) break;
2242
2253
  const tag = html.slice(pos, end + 7);
@@ -2244,7 +2255,7 @@ function deconstruct(html) {
2244
2255
  const raw = extractAttr(tag, "data-raw") || extractAttr(tag, "data-iri");
2245
2256
  blocks.push(`[${prefix}] <${raw}>`);
2246
2257
  pos = end + 7;
2247
- } else if (html.startsWith("<div class=\"mdld-standalone\"", pos)) {
2258
+ } else if (openTag.startsWith("<div") && extractAttr(openTag, "class")?.includes("mdld-standalone")) {
2248
2259
  const end = html.indexOf("</div>", pos);
2249
2260
  if (end === -1) break;
2250
2261
  const ann = extractAttr(html.slice(pos, end + 6), "data-annotation");
@@ -2308,12 +2319,6 @@ function deconstruct(html) {
2308
2319
  }
2309
2320
  blocks.push(items.join("\n"));
2310
2321
  pos = close + 5;
2311
- } else if (html.startsWith("<p class=\"mdld-paragraph\">", pos)) {
2312
- const close = html.indexOf("</p>", pos);
2313
- if (close === -1) break;
2314
- const content = html.slice(pos + 25, close);
2315
- blocks.push(deconstructInline(content));
2316
- pos = close + 4;
2317
2322
  } else pos++;
2318
2323
  }
2319
2324
  return blocks.join("\n\n");
@@ -2384,10 +2389,10 @@ function deconstructInlineElement(tagName, attrs, inner) {
2384
2389
  }
2385
2390
  }
2386
2391
  function extractAttr(tag, name) {
2387
- const re = new RegExp(`${name}=(?:"([^"]*)"|'([^']*)')`, "i");
2392
+ const re = new RegExp(`(?:\\s|^)${name}=(["'])(.*?)\\1`, "is");
2388
2393
  const m = tag.match(re);
2389
2394
  if (!m) return null;
2390
- return unescapeHtml(m[1] !== void 0 ? m[1] : m[2]);
2395
+ return unescapeHtml(m[2]);
2391
2396
  }
2392
2397
  function unescapeHtml(s) {
2393
2398
  return String(s).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'");