@mdream/js 1.0.4 → 1.0.5
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.
package/dist/_chunks/parse.mjs
CHANGED
|
@@ -149,12 +149,30 @@ const tagHandlers = {
|
|
|
149
149
|
spacing: BLOCKQUOTE_SPACING
|
|
150
150
|
},
|
|
151
151
|
[23]: {
|
|
152
|
-
enter: ({ node }) => {
|
|
153
|
-
if ((node.depthMap[34] || 0) > 0)
|
|
152
|
+
enter: ({ node, state }) => {
|
|
153
|
+
if ((node.depthMap[34] || 0) > 0) {
|
|
154
|
+
const language = getLanguageFromClass(node.attributes?.class);
|
|
155
|
+
const liDepth = node.depthMap[25] || 0;
|
|
156
|
+
if (liDepth > 0) return `\n\n${" ".repeat(liDepth)}\`\`\`${language}\n`;
|
|
157
|
+
return `\`\`\`${language}\n`;
|
|
158
|
+
}
|
|
159
|
+
if ((node.depthMap[25] || 0) > 0) {
|
|
160
|
+
const lastEntry = state.buffer.at(-1);
|
|
161
|
+
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
162
|
+
if (lastChar && lastChar !== " " && lastChar !== "\n") return ` \``;
|
|
163
|
+
}
|
|
154
164
|
return "`";
|
|
155
165
|
},
|
|
156
166
|
exit: ({ node }) => {
|
|
157
|
-
|
|
167
|
+
if ((node.depthMap[34] || 0) > 0) {
|
|
168
|
+
const liDepth = node.depthMap[25] || 0;
|
|
169
|
+
if (liDepth > 0) {
|
|
170
|
+
const indent = " ".repeat(liDepth);
|
|
171
|
+
return `\n${indent}\`\`\`\n\n${indent}`;
|
|
172
|
+
}
|
|
173
|
+
return `\n\`\`\``;
|
|
174
|
+
}
|
|
175
|
+
return "`";
|
|
158
176
|
},
|
|
159
177
|
collapsesInnerWhiteSpace: true,
|
|
160
178
|
spacing: NO_SPACING,
|
|
@@ -281,6 +299,11 @@ const tagHandlers = {
|
|
|
281
299
|
return `\n${prefix.trimEnd()}\n${prefix}`;
|
|
282
300
|
}
|
|
283
301
|
}
|
|
302
|
+
if ((node.depthMap[25] || 0) > 0) {
|
|
303
|
+
const lastEntry = state.buffer.at(-1);
|
|
304
|
+
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
305
|
+
if (lastChar && lastChar !== " " && lastChar !== "\n") return " ";
|
|
306
|
+
}
|
|
284
307
|
} },
|
|
285
308
|
[36]: {},
|
|
286
309
|
[37]: {
|
|
@@ -119,6 +119,12 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
119
119
|
if (textNode.excludedFromMarkdown) return;
|
|
120
120
|
if (textNode.value === " " && lastChar === "\n") return;
|
|
121
121
|
if (shouldAddSpacingBeforeText(lastChar, lastNode, textNode)) textNode.value = ` ${textNode.value}`;
|
|
122
|
+
if ((state.depthMap[34] || 0) > 0 && (state.depthMap[25] || 0) > 0) {
|
|
123
|
+
const indent = " ".repeat(state.depthMap[25]);
|
|
124
|
+
let value = textNode.value.replace(/\n(?=[^ \t\n])/g, `\n${indent}`);
|
|
125
|
+
if (lastChar === "\n" && value[0] && value[0] !== " " && value[0] !== " " && value[0] !== "\n") value = indent + value;
|
|
126
|
+
textNode.value = value;
|
|
127
|
+
}
|
|
122
128
|
state.buffer.push(textNode.value);
|
|
123
129
|
state.lastContentCache = textNode.value;
|
|
124
130
|
}
|
package/dist/_chunks/src.mjs
CHANGED
|
@@ -275,7 +275,7 @@ async function* streamHtmlToMarkdown$1(htmlStream, options = {}, resolvedPlugins
|
|
|
275
275
|
const reader = htmlStream.getReader();
|
|
276
276
|
const processor = createMarkdownProcessor(options, resolvedPlugins, tagOverrideHandlers);
|
|
277
277
|
const parseState = {
|
|
278
|
-
depthMap:
|
|
278
|
+
depthMap: processor.state.depthMap,
|
|
279
279
|
depth: 0,
|
|
280
280
|
resolvedPlugins,
|
|
281
281
|
tagOverrideHandlers
|
package/package.json
CHANGED