remark-linkify
Version:
A remark plugin to automatically convert URLs and email addresses into links.
103 lines (77 loc) • 2.81 kB
Markdown
[](https://www.npmjs.com/package/remark-linkify)
[](https://www.npmjs.com/package/remark-linkify)
[](https://bundlephobia.com/package/remark-linkify)
[](https://github.com/hoqua/remark-linkify/actions/workflows/ci.yml)
[](./coverage/coverage-summary.json)
[](LICENSE)
A [remark](https://github.com/remarkjs/remark) plugin to automatically detect URLs and email addresses in text and turn them into Markdown links.
* Automatically converts URLs (like `http://example.com`) and emails (`user@example.com`) into links.
* Uses the robust `linkify-it` library for accurate detection.
* Integrates seamlessly with the `remark`/`unified` ecosystem.
* Avoids linkifying text within existing links or code blocks (by default behavior of `unist-util-visit`).
* Supports ESM and CJS.
## Installation
```bash
pnpm add remark-linkify
```
```bash
yarn add remark-linkify
```
```bash
npm install remark-linkify
```
## Usage
### With `remark`
```javascript
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();
```
```jsx
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;
```
This plugin currently does not accept any options.
```typescript
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;
```
[](LICENSE)