safe-mdx 1.3.8 → 1.3.9
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/html/html-and-md.test.d.ts +2 -0
- package/dist/html/html-and-md.test.d.ts.map +1 -0
- package/dist/html/html-and-md.test.js +869 -0
- package/dist/html/html-and-md.test.js.map +1 -0
- package/dist/html/html-to-mdx-ast.d.ts.map +1 -1
- package/dist/html/html-to-mdx-ast.js.map +1 -1
- package/package.json +4 -4
- package/src/html/html-and-md.test.ts +953 -0
- package/src/html/html-to-mdx-ast.ts +9 -8
|
@@ -67,10 +67,11 @@ function defaultConvertAttributeValue({
|
|
|
67
67
|
return value
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
|
|
70
71
|
// Remove common indentation from multi-line text while preserving relative indentation
|
|
71
72
|
function deindent(text: string): string {
|
|
72
73
|
const lines = text.split('\n')
|
|
73
|
-
|
|
74
|
+
|
|
74
75
|
// Find minimum indentation (excluding empty lines)
|
|
75
76
|
let minIndent = Infinity
|
|
76
77
|
for (const line of lines) {
|
|
@@ -81,12 +82,12 @@ function deindent(text: string): string {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
// If no indentation found, return as is
|
|
86
87
|
if (minIndent === 0 || minIndent === Infinity) {
|
|
87
88
|
return text
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
|
|
90
91
|
// Remove common indentation from each line, preserving relative indentation
|
|
91
92
|
return lines
|
|
92
93
|
.map(line => line.slice(minIndent))
|
|
@@ -197,24 +198,24 @@ function htmlNodeToMdxAst(
|
|
|
197
198
|
|
|
198
199
|
if (isTextNode(node)) {
|
|
199
200
|
let textValue = node.textContent || ''
|
|
200
|
-
|
|
201
|
+
|
|
201
202
|
// Skip whitespace-only nodes between elements
|
|
202
203
|
if (!textValue.trim()) {
|
|
203
204
|
const prevSibling = node.previousSibling
|
|
204
205
|
const nextSibling = node.nextSibling
|
|
205
|
-
|
|
206
|
+
|
|
206
207
|
// If between elements and contains newlines, it's likely formatting
|
|
207
|
-
if (textValue.includes('\n') &&
|
|
208
|
+
if (textValue.includes('\n') &&
|
|
208
209
|
((prevSibling && isElementNode(prevSibling)) ||
|
|
209
210
|
(nextSibling && isElementNode(nextSibling)))) {
|
|
210
211
|
return []
|
|
211
212
|
}
|
|
212
213
|
// Otherwise preserve the whitespace (could be intentional space)
|
|
213
214
|
}
|
|
214
|
-
|
|
215
|
+
|
|
215
216
|
// Always deindent text content
|
|
216
217
|
textValue = deindent(textValue).trim()
|
|
217
|
-
|
|
218
|
+
|
|
218
219
|
// Skip empty text after processing
|
|
219
220
|
if (!textValue) {
|
|
220
221
|
return []
|