@mdream/js
Advanced tools
@@ -152,8 +152,26 @@ import { a as NO_SPACING, c as TABLE_ROW_SPACING, g as TagIdMap, i as LIST_ITEM_SPACING, t as BLOCKQUOTE_SPACING } from "./const.mjs"; | ||
| [23]: { | ||
| enter: ({ node }) => { | ||
| if ((node.depthMap[34] || 0) > 0) return `\`\`\`${getLanguageFromClass(node.attributes?.class)}\n`; | ||
| enter: ({ node, state }) => { | ||
| if ((node.depthMap[34] || 0) > 0) { | ||
| const language = getLanguageFromClass(node.attributes?.class); | ||
| const liDepth = node.depthMap[25] || 0; | ||
| if (liDepth > 0) return `\n\n${" ".repeat(liDepth)}\`\`\`${language}\n`; | ||
| return `\`\`\`${language}\n`; | ||
| } | ||
| if ((node.depthMap[25] || 0) > 0) { | ||
| const lastEntry = state.buffer.at(-1); | ||
| const lastChar = lastEntry?.charAt(lastEntry.length - 1) || ""; | ||
| if (lastChar && lastChar !== " " && lastChar !== "\n") return ` \``; | ||
| } | ||
| return "`"; | ||
| }, | ||
| exit: ({ node }) => { | ||
| return (node.depthMap[34] || 0) > 0 ? `\n\`\`\`` : "`"; | ||
| if ((node.depthMap[34] || 0) > 0) { | ||
| const liDepth = node.depthMap[25] || 0; | ||
| if (liDepth > 0) { | ||
| const indent = " ".repeat(liDepth); | ||
| return `\n${indent}\`\`\`\n\n${indent}`; | ||
| } | ||
| return `\n\`\`\``; | ||
| } | ||
| return "`"; | ||
| }, | ||
@@ -285,2 +303,7 @@ collapsesInnerWhiteSpace: true, | ||
| } | ||
| if ((node.depthMap[25] || 0) > 0) { | ||
| const lastEntry = state.buffer.at(-1); | ||
| const lastChar = lastEntry?.charAt(lastEntry.length - 1) || ""; | ||
| if (lastChar && lastChar !== " " && lastChar !== "\n") return " "; | ||
| } | ||
| } }, | ||
@@ -287,0 +310,0 @@ [36]: {}, |
@@ -122,2 +122,8 @@ import { a as NO_SPACING, n as DEFAULT_BLOCK_SPACING } from "./const.mjs"; | ||
| if (shouldAddSpacingBeforeText(lastChar, lastNode, textNode)) textNode.value = ` ${textNode.value}`; | ||
| if ((state.depthMap[34] || 0) > 0 && (state.depthMap[25] || 0) > 0) { | ||
| const indent = " ".repeat(state.depthMap[25]); | ||
| let value = textNode.value.replace(/\n(?=[^ \t\n])/g, `\n${indent}`); | ||
| if (lastChar === "\n" && value[0] && value[0] !== " " && value[0] !== " " && value[0] !== "\n") value = indent + value; | ||
| textNode.value = value; | ||
| } | ||
| state.buffer.push(textNode.value); | ||
@@ -124,0 +130,0 @@ state.lastContentCache = textNode.value; |
@@ -278,3 +278,3 @@ import "./const.mjs"; | ||
| const parseState = { | ||
| depthMap: new Uint8Array(1024), | ||
| depthMap: processor.state.depthMap, | ||
| depth: 0, | ||
@@ -281,0 +281,0 @@ resolvedPlugins, |
+1
-1
| { | ||
| "name": "@mdream/js", | ||
| "type": "module", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "description": "JavaScript HTML-to-Markdown engine for mdream. Escape hatch for hooks and edge runtimes.", | ||
@@ -6,0 +6,0 @@ "author": { |
155964
0.76%3456
0.85%