diff --git a/lib/index.js b/lib/index.js index 98a62e2..692cd27 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,6 +41,8 @@ * cannot combine w/ `disallowedElements`. * @property {string | null | undefined} [children] * Markdown. + * @property {boolean | null | undefined} [autoLink] + * Automatically detect and add hyperlink to urls and emails. * @property {string | null | undefined} [className] * Wrap in a `div` with this class name. * @property {Components | null | undefined} [components] @@ -78,6 +80,7 @@ import {unreachable} from 'devlop' import {toJsxRuntime} from 'hast-util-to-jsx-runtime' import {urlAttributes} from 'html-url-attributes' +import {autoLinkMd} from 'react-markdown-autolink' import {Fragment, jsx, jsxs} from 'react/jsx-runtime' import remarkParse from 'remark-parse' import remarkRehype from 'remark-rehype' @@ -163,7 +166,7 @@ export function Markdown(options) { const file = new VFile() if (typeof children === 'string') { - file.value = children + file.value = options.autoLink ? autoLinkMd(children) : children } else { unreachable( 'Unexpected value `' + diff --git a/package.json b/package.json index dc1b8b9..7b049d3 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "hast-util-to-jsx-runtime": "^2.0.0", "html-url-attributes": "^3.0.0", "mdast-util-to-hast": "^13.0.0", + "react-markdown-autolink": "^0.0.1", "remark-parse": "^11.0.0", "remark-rehype": "^11.0.0", "unified": "^11.0.0",