Skip to content

Commit

Permalink
fix: decrease priority for jsx compared to HTML
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
petyosi committed Dec 7, 2023
1 parent 552dce1 commit bbc4974
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/examples/jsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { toolbarPlugin } from '../plugins/toolbar'
import { Button } from '../plugins/toolbar/primitives/toolbar'
import { NestedLexicalEditor } from '../plugins/core/NestedLexicalEditor'
import { MdxJsxTextElement } from 'mdast-util-mdx'
import { headingsPlugin } from '..'

const jsxComponentDescriptors: JsxComponentDescriptor[] = [
{
Expand Down Expand Up @@ -99,3 +100,19 @@ export const Example = () => {
/>
)
}

const markdown = `
# Hello world
<div style="background: red">
Content
</div>
`

export const Html = () => {
return (
<div>
<MDXEditor markdown={markdown} plugins={[headingsPlugin(), jsxPlugin({ jsxComponentDescriptors: [] })]} />
</div>
)
}
3 changes: 2 additions & 1 deletion src/plugins/jsx/LexicalJsxVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export const LexicalJsxVisitor: LexicalExportVisitor<LexicalJsxNode, MdxJsxFlowE
actions.registerReferredComponent(mdastNode.name!)
traverseNestedJsxNodes(mdastNode)
actions.appendToParent(mdastParent, mdastNode)
}
},
priority: -200
}
3 changes: 2 additions & 1 deletion src/plugins/jsx/MdastMdxJsxElementVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const MdastMdxJsxElementVisitor: MdastImportVisitor<MdxJsxTextElement> =
},
visitNode({ lexicalParent, mdastNode }) {
;(lexicalParent as ElementNode).append($createLexicalJsxNode(mdastNode))
}
},
priority: -200
}

0 comments on commit bbc4974

Please sign in to comment.