mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-19 00:34:01 +00:00
tagHandler - Handle anchor tag + tests
This commit is contained in:
+14
-1
@@ -2,11 +2,12 @@ import {
|
||||
emphasis,
|
||||
heading,
|
||||
image,
|
||||
link,
|
||||
list,
|
||||
listItem,
|
||||
strong,
|
||||
} from 'mdast-builder';
|
||||
import { ImgHTMLAttributes } from 'react';
|
||||
import { AnchorHTMLAttributes, ImgHTMLAttributes } from 'react';
|
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Node as MDASTNode, Parent as MDASTParent } from 'unist';
|
||||
|
||||
@@ -76,6 +77,18 @@ export default function handleTag(
|
||||
}
|
||||
// END - Handle img tag - with src and alt
|
||||
|
||||
// START - Handle anchor tag (link)
|
||||
case 'a': {
|
||||
const props = node.props as AnchorHTMLAttributes<any>;
|
||||
let href = '';
|
||||
if (props.href !== undefined) {
|
||||
href = props.href;
|
||||
}
|
||||
newParentASTNode = childASTNode = link(href, props.title);
|
||||
break;
|
||||
}
|
||||
// END - Handle anchor tag (link)
|
||||
|
||||
default:
|
||||
newParentASTNode = parentASTNode;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user