|
1 | 1 | import { fromMarkdown } from "mdast-util-from-markdown"; |
2 | 2 | import { toMarkdown } from "mdast-util-to-markdown"; |
3 | 3 | import { mdxFromMarkdown, mdxToMarkdown } from "mdast-util-mdx"; |
| 4 | +import { mdxJsxToMarkdown } from "mdast-util-mdx-jsx"; |
4 | 5 | import { mdxjs } from "micromark-extension-mdxjs"; |
5 | 6 | import { directive } from "micromark-extension-directive"; |
6 | 7 | import { directiveFromMarkdown, directiveToMarkdown } from "mdast-util-directive"; |
@@ -108,6 +109,11 @@ async function processFile(filePath: string, options: ExtendedTransformerOptions |
108 | 109 | } |
109 | 110 |
|
110 | 111 | // Convert AST back to MDX |
| 112 | + const defaultMdxJsxFlowElement = mdxJsxToMarkdown().handlers?.mdxJsxFlowElement; |
| 113 | + if (!defaultMdxJsxFlowElement) { |
| 114 | + throw new Error("Default handler for mdxJsxFlowElement not found"); |
| 115 | + } |
| 116 | + |
111 | 117 | const newContent = toMarkdown(ast, { |
112 | 118 | extensions: [ |
113 | 119 | mdxToMarkdown(), |
@@ -166,27 +172,25 @@ async function processFile(filePath: string, options: ExtendedTransformerOptions |
166 | 172 | return text; |
167 | 173 | }) as Handle, |
168 | 174 |
|
169 | | - // Custom handler to prevent root child indentation of FileTree and Steps components. |
170 | | - // Unfortunately this messes with all other components and will not render them correctly despite the conditional statement. |
171 | | - |
172 | | - // mdxJsxFlowElement: ((node, parent, context: State) => { |
173 | | - // if (node.name === "FileTree" || node.name === "Steps") { |
174 | | - // const exit = context.enter("mdxJsxFlowElement"); |
175 | | - // const nodeContent = node.children |
176 | | - // .map((child: any) => |
177 | | - // context.handle(child, node, context, { |
178 | | - // after: "", |
179 | | - // before: "", |
180 | | - // lineShift: 0, |
181 | | - // now: { line: 1, column: 1 }, |
182 | | - // }), |
183 | | - // ) |
184 | | - // .join("\n"); |
185 | | - // exit(); |
186 | | - // return `<${node.name}>\n\n${nodeContent}\n\n</${node.name}>`; |
187 | | - // } |
188 | | - // return null; |
189 | | - // }) as Handle, |
| 175 | + mdxJsxFlowElement: (node, parent, context, info) => { |
| 176 | + if (node.name === "FileTree" || node.name === "Steps") { |
| 177 | + const exit = context.enter("mdxJsxFlowElement"); |
| 178 | + const nodeContent = node.children |
| 179 | + .map((child: any) => |
| 180 | + context.handle(child, node, context, { |
| 181 | + after: "", |
| 182 | + before: "", |
| 183 | + lineShift: 0, |
| 184 | + now: { line: 1, column: 1 }, |
| 185 | + }), |
| 186 | + ) |
| 187 | + .join("\n"); |
| 188 | + exit(); |
| 189 | + return `<${node.name}>\n\n${nodeContent}\n\n</${node.name}>`; |
| 190 | + } |
| 191 | + |
| 192 | + return defaultMdxJsxFlowElement(node, parent, context, info); |
| 193 | + }, |
190 | 194 | }, |
191 | 195 | }); |
192 | 196 |
|
|
0 commit comments