tagHandler - Add tagHandler, handles only h1 now

This commit is contained in:
2019-12-16 10:19:01 +05:30
parent 2810b1907c
commit 2545d8dda9
+30
View File
@@ -0,0 +1,30 @@
import { heading } from 'mdast-builder';
// tslint:disable-next-line: no-implicit-dependencies
import { Node as MDASTNode, Parent as MDASTParent } from 'unist';
import { IReactElementSubset } from './helpers';
export default function handleTag(
node: IReactElementSubset,
parentASTNode: MDASTParent
) {
const { type: tagType } = node;
let childASTNode: MDASTNode | undefined;
let newParentASTNode: MDASTParent | undefined;
switch (tagType) {
case 'h1':
newParentASTNode = childASTNode = heading(1);
break;
default:
newParentASTNode = parentASTNode;
break;
}
if (childASTNode !== undefined) {
parentASTNode.children.push(childASTNode);
}
return newParentASTNode;
}