@mdream/js 1.5.3 → 1.5.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.
@@ -104,6 +104,33 @@ function canWrapHere(depthMap) {
104
104
  for (let h = 7; h <= 12; h++) if (depthMap[h]) return false;
105
105
  return true;
106
106
  }
107
+ function foldPreLinesToBr(value) {
108
+ let start = 0;
109
+ while (start < value.length) {
110
+ const c = value.charCodeAt(start);
111
+ if (c !== 10 && c !== 13) break;
112
+ start++;
113
+ }
114
+ let end = value.length;
115
+ while (end > start) {
116
+ const c = value.charCodeAt(end - 1);
117
+ if (c !== 10 && c !== 13) break;
118
+ end--;
119
+ }
120
+ let out = "";
121
+ for (let i = start; i < end; i++) {
122
+ const c = value.charCodeAt(i);
123
+ if (c === 13) {
124
+ out += "<br>";
125
+ if (i + 1 < end && value.charCodeAt(i + 1) === 10) i++;
126
+ } else if (c === 10) out += "<br>";
127
+ else if (c === 38) out += "&amp;";
128
+ else if (c === 60) out += "&lt;";
129
+ else if (c === 62) out += "&gt;";
130
+ else out += value[i];
131
+ }
132
+ return out;
133
+ }
107
134
  function currentColumn(buffer) {
108
135
  let col = 0;
109
136
  for (let i = buffer.length - 1; i >= 0; i--) {
@@ -277,6 +304,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
277
304
  if (lastChar === "\n" && value[0] && value[0] !== "\n") value = indent + value;
278
305
  textNode.value = value;
279
306
  }
307
+ if (state.depthMap[34] > 0 && (state.depthMap[32] > 0 || state.depthMap[31] > 0)) textNode.value = foldPreLinesToBr(textNode.value);
280
308
  const wrapWidth = state.options?.wrapWidth;
281
309
  if (wrapWidth && canWrapHere(state.depthMap)) {
282
310
  const wrapped = wrapText(textNode.value, currentColumn(state.buffer), wrapWidth, continuationPrefix(textNode, state.listIndentWidths));
@@ -329,7 +357,15 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
329
357
  }
330
358
  if (element.tagId === 6 && !state.depthMap[34] && output?.length === 1 && output[0] === "\n" && lastChar === "\n" && secondLastChar === "\n") output = void 0;
331
359
  const configuredNewLines = calculateNewLineConfig(node, state.depthMap, state.plainText === true)[eventType] || 0;
332
- const newLines = Math.max(0, configuredNewLines - lastNewLines);
360
+ let effectiveLastNewLines = lastNewLines;
361
+ if (eventType === 1 && output) for (let i = output.length - 1; i >= 0; i--) {
362
+ const frag = output[i];
363
+ if (frag) {
364
+ if (frag.charCodeAt(frag.length - 1) === 96) effectiveLastNewLines = 0;
365
+ break;
366
+ }
367
+ }
368
+ const newLines = Math.max(0, configuredNewLines - effectiveLastNewLines);
333
369
  if (state.pendingInlineWhitespace) {
334
370
  const firstOutput = output?.[0]?.[0] || "";
335
371
  if (eventType === 0) {
@@ -381,7 +381,7 @@ function isAutolinkUri(s) {
381
381
  }
382
382
  function isInsideTableCell(state) {
383
383
  const depthMap = state.depthMap;
384
- return (depthMap[32] || 0) > 0 || (depthMap[31] || 0) > 0;
384
+ return depthMap[32] > 0 || depthMap[31] > 0;
385
385
  }
386
386
  function isInsideRawHtmlBlock(state) {
387
387
  const depthMap = state.depthMap;
@@ -437,11 +437,11 @@ const tagHandlers = {
437
437
  },
438
438
  [2]: {
439
439
  enter: () => "<details>",
440
- exit: () => "</details>\n\n"
440
+ exit: ({ state }) => isInsideTableCell(state) ? "</details>" : "</details>\n\n"
441
441
  },
442
442
  [3]: {
443
443
  enter: () => "<summary>",
444
- exit: () => "</summary>\n\n"
444
+ exit: ({ state }) => isInsideTableCell(state) ? "</summary>" : "</summary>\n\n"
445
445
  },
446
446
  [4]: {
447
447
  collapsesInnerWhiteSpace: true,
@@ -525,11 +525,13 @@ const tagHandlers = {
525
525
  },
526
526
  [34]: {
527
527
  enter: ({ node, state }) => {
528
+ if (isInsideTableCell(state)) return "<pre>";
528
529
  state.preFencePending = true;
529
530
  state.preOwnFence = false;
530
531
  state.preFenceLang = getLanguageFromClass(node.attributes?.class);
531
532
  },
532
533
  exit: ({ state }) => {
534
+ if (isInsideTableCell(state)) return "</pre>";
533
535
  const ownFence = state.preOwnFence;
534
536
  state.preFencePending = false;
535
537
  state.preOwnFence = false;
@@ -544,6 +546,7 @@ const tagHandlers = {
544
546
  [23]: {
545
547
  enter: ({ node, state }) => {
546
548
  if ((state.depthMap?.[34] || 0) > 0) {
549
+ if (isInsideTableCell(state)) return "<code>";
547
550
  if (state.preOwnFence) return;
548
551
  state.preFencePending = false;
549
552
  const language = getLanguageFromClass(node.attributes?.class);
@@ -559,6 +562,7 @@ const tagHandlers = {
559
562
  },
560
563
  exit: ({ state }) => {
561
564
  if ((state.depthMap?.[34] || 0) > 0) {
565
+ if (isInsideTableCell(state)) return "</code>";
562
566
  if (state.preOwnFence) return;
563
567
  if ((state.depthMap?.[25] || 0) > 0) {
564
568
  const indent = state.listIndent;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mdream/js",
3
3
  "type": "module",
4
- "version": "1.5.3",
4
+ "version": "1.5.4",
5
5
  "description": "JavaScript HTML-to-Markdown engine for mdream. Escape hatch for hooks and edge runtimes.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",