-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
131 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { hast, plain } from '../../../index'; | ||
|
||
describe('plain compiler', () => { | ||
it('should include the title of Accordion', () => { | ||
const mdx = ` | ||
<Accordion title="Title"> | ||
Body | ||
</Accordion> | ||
`; | ||
|
||
expect(plain(hast(mdx))).toContain('Title Body'); | ||
}); | ||
|
||
it('should include the title of Card', () => { | ||
const mdx = ` | ||
<Card title="Title"> | ||
Body | ||
</Card> | ||
`; | ||
|
||
expect(plain(hast(mdx))).toContain('Title Body'); | ||
}); | ||
|
||
it('should include the title of Tab', () => { | ||
const mdx = ` | ||
<Tab title="Title"> | ||
Body | ||
</Tab> | ||
`; | ||
|
||
expect(plain(hast(mdx))).toContain('Title Body'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { visit } from 'unist-util-visit'; | ||
import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx'; | ||
import { Transform } from 'mdast-util-from-markdown'; | ||
import { Parents } from 'mdast'; | ||
import { getAttrs, isMDXElement } from '../utils'; | ||
import * as Components from '../../components'; | ||
|
||
const setData = (node: MdxJsxFlowElement | MdxJsxTextElement, index: number, parent: Parents) => { | ||
if (!node.name) return; | ||
if (!(node.name in Components)) return; | ||
|
||
parent.children[index] = { | ||
...node, | ||
data: { | ||
hName: node.name, | ||
hProperties: getAttrs(node), | ||
}, | ||
}; | ||
}; | ||
|
||
const mdxToHast = (): Transform => tree => { | ||
visit(tree, isMDXElement, setData); | ||
|
||
return tree; | ||
}; | ||
|
||
export default mdxToHast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters