Package Exports
- remark-linkify
Readme
remark-linkify
A remark plugin to automatically detect URLs and email addresses in text and turn them into Markdown links.
Features
- Automatically converts URLs (like
http://example.com) and emails (user@example.com) into links. - Uses the robust
linkify-itlibrary for accurate detection. - Integrates seamlessly with the
remark/unifiedecosystem. - Avoids linkifying text within existing links or code blocks (by default behavior of
unist-util-visit). - Supports ESM and CJS.
Installation
pnpm add remark-linkifyyarn add remark-linkifynpm install remark-linkifyUsage
With remark
import { remark } from 'remark';
import remarkLinkify from 'remark-linkify'; // Note: Default export
const markdownInput = `
Visit example.com or contact user@example.com.
Also check https://another.example.org.
`;
async function processMarkdown() {
const file = await remark()
.use(remarkLinkify)
.process(markdownInput);
console.log(String(file));
/*
Output:
Visit [example.com](http://example.com) or contact [user@example.com](mailto:user@example.com).
Also check [https://another.example.org](https://another.example.org).
*/
}
processMarkdown();With react-markdown
import ReactMarkdown from 'react-markdown';
import remarkLinkify from 'remark-linkify';
import remarkGfm from 'remark-gfm'; // Example other plugin
const markdown = "Go to example.com or email info@example.com.";
function MyComponent() {
return (
<ReactMarkdown
remarkPlugins={[remarkGfm, remarkLinkify]}
>
{markdown}
</ReactMarkdown>
);
}
export default MyComponent;API
This plugin currently does not accept any options.
import type { Transformer } from 'unified';
import type { Root } from 'mdast';
/**
* A remark plugin to automatically detect URLs and email addresses in text
* and turn them into Markdown links.
*/
declare function remarkLinkify(): Transformer<Root, Root>;
export default remarkLinkify;