mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-17 16:47:56 +02:00
feat(mdx-loader): Remark plugin to report unused MDX / Markdown directives (#9394)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
56cc8e8ffa
commit
c6762a2542
19 changed files with 506 additions and 26 deletions
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import escapeHtml from 'escape-html';
|
||||
import type {Parent} from 'unist';
|
||||
import type {Parent, Node} from 'unist';
|
||||
import type {PhrasingContent, Heading} from 'mdast';
|
||||
import type {
|
||||
MdxJsxAttribute,
|
||||
|
@ -15,6 +15,27 @@ import type {
|
|||
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
||||
} from 'mdast-util-mdx';
|
||||
|
||||
/**
|
||||
* Util to transform one node type to another node type
|
||||
* The input node is mutated in place
|
||||
* @param node the node to mutate
|
||||
* @param newNode what the original node should become become
|
||||
*/
|
||||
export function transformNode<NewNode extends Node>(
|
||||
node: Node,
|
||||
newNode: NewNode,
|
||||
): NewNode {
|
||||
Object.keys(node).forEach((key) => {
|
||||
// @ts-expect-error: unsafe but ok
|
||||
delete node[key];
|
||||
});
|
||||
Object.keys(newNode).forEach((key) => {
|
||||
// @ts-expect-error: unsafe but ok
|
||||
node[key] = newNode[key];
|
||||
});
|
||||
return node as NewNode;
|
||||
}
|
||||
|
||||
export function stringifyContent(
|
||||
node: Parent,
|
||||
toString: (param: unknown) => string, // TODO weird but works
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue