@takazudo/mdx-formatter 0.4.2 → 0.4.3
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/hybrid-formatter.js +13 -3
- package/dist/index.js +13 -2
- package/package.json +1 -1
package/dist/hybrid-formatter.js
CHANGED
|
@@ -941,14 +941,24 @@ export class HybridFormatter {
|
|
|
941
941
|
}
|
|
942
942
|
return;
|
|
943
943
|
}
|
|
944
|
+
// Find the actual end of the opening tag (may span multiple lines
|
|
945
|
+
// for elements with attributes like <Danger\n title="..."\n>)
|
|
946
|
+
let openingTagEndLine = startLine;
|
|
947
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
948
|
+
const trimmed = this.lines[i].trim();
|
|
949
|
+
if (trimmed.endsWith('>') && !trimmed.endsWith('/>') && !trimmed.startsWith('</')) {
|
|
950
|
+
openingTagEndLine = i;
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
944
954
|
// Check if there's an empty line after the opening tag
|
|
945
|
-
if (
|
|
946
|
-
const lineAfterOpening = this.lines[
|
|
955
|
+
if (openingTagEndLine + 1 < this.lines.length) {
|
|
956
|
+
const lineAfterOpening = this.lines[openingTagEndLine + 1];
|
|
947
957
|
if (lineAfterOpening.trim() !== '') {
|
|
948
958
|
// Add empty line after opening tag
|
|
949
959
|
operations.push({
|
|
950
960
|
type: 'insertLine',
|
|
951
|
-
startLine:
|
|
961
|
+
startLine: openingTagEndLine + 1,
|
|
952
962
|
content: '',
|
|
953
963
|
});
|
|
954
964
|
}
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,19 @@ export function detectMdx(content) {
|
|
|
19
19
|
export async function format(content, options = {}) {
|
|
20
20
|
try {
|
|
21
21
|
const settings = loadConfig(options);
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
let result = content;
|
|
23
|
+
// Some rule interactions (e.g., list indent normalization + addEmptyLinesInBlockJsx)
|
|
24
|
+
// may require multiple passes to converge. 3 iterations is sufficient for all known
|
|
25
|
+
// cases (most files converge in 1, edge cases in 2).
|
|
26
|
+
const MAX_ITERATIONS = 3;
|
|
27
|
+
for (let i = 0; i < MAX_ITERATIONS; i++) {
|
|
28
|
+
const formatter = new HybridFormatter(result, settings);
|
|
29
|
+
const formatted = await formatter.format();
|
|
30
|
+
if (formatted === result)
|
|
31
|
+
break;
|
|
32
|
+
result = formatted;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
24
35
|
}
|
|
25
36
|
catch {
|
|
26
37
|
// Silently return original content if formatting fails
|