tagHandler - Handle img tags + tests

This commit is contained in:
2019-12-21 16:01:34 +05:30
parent 4148ef7ba4
commit 991f0162a0
2 changed files with 54 additions and 2 deletions
+22 -2
View File
@@ -1,6 +1,15 @@
import { emphasis, heading, strong, list, listItem } from 'mdast-builder';
import {
emphasis,
heading,
image,
list,
listItem,
strong,
} from 'mdast-builder';
import { ImgHTMLAttributes } from 'react';
// tslint:disable-next-line: no-implicit-dependencies
import { Node as MDASTNode, Parent as MDASTParent } from 'unist';
import { IReactElementSubset } from './helpers';
export default function handleTag(
@@ -50,9 +59,20 @@ export default function handleTag(
case 'li':
newParentASTNode = childASTNode = listItem([]);
break;
// END - Handle lists - ul, ol, li
// START - Handle img tag - with src and alt
case 'img': {
const props = node.props as ImgHTMLAttributes<any>;
let source = '';
if (props.src !== undefined) {
source = props.src;
}
newParentASTNode = childASTNode = image(source, props.title, props.alt);
break;
}
// END - Handle img tag - with src and alt
default:
newParentASTNode = parentASTNode;
break;