JSPM

remark-linkify

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18077
  • Score
    100M100P100Q140705F
  • License MIT

A remark plugin to automatically convert URLs and email addresses into links.

Package Exports

  • remark-linkify

Readme

remark-linkify

NPM version Downloads Bundle size Build Status Coverage Status License

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-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

pnpm add remark-linkify
yarn add remark-linkify
npm install remark-linkify

Usage

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;

License

MIT