remark-truncate-links
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

remark-truncate-links

shortens plain links in markdown you haven't wrapped in []()

Actually it'll shorten [auto] linked URLs where the URL and the text are equal as in [example.com](example.com)
So this plugin doesn't work if you want to show a full URL longer than length. Written in Typescript.

Examples

# input 
https://github.com/GaiAma/Coding4GaiAma/tree/master/packages/remark-truncate-links
# smart 
github.com/GaiAma/C…te-links
# middle 
https://github…runcate-links
# end 
https://github.com/GaiAma/C…

Install

yarn add -D remark-truncate-links
# or 
npm i -D remark-truncate-links

Options

{
  style: `smart`, // one of [`smart`, `middle`, `end`]
  length: 30,
}
// showing default options

Usage

In gatsby-plugin-mdx

// default options
{
  resolve: `gatsby-plugin-mdx`,
  options: {
    remarkPlugins: [
      require('remark-truncate-links').remarkTruncateLinks,
    ],
  },
}
 
// providing options
{
  resolve: `gatsby-plugin-mdx`,
  options: {
    remarkPlugins: [
      [
        require('remark-truncate-links').remarkTruncateLinks,
        { style: 'middle' },
      ],
    ],
  },
}

Using Unified

import unified from 'unified'
import remarkParse from 'remark-parse'
import stringify from 'remark-stringify'
import { remarkTruncateLinks } from 'remark-truncate-links'
 
// with default options
unified()
  .use(remarkParse)
  .use(remarkTruncateLinks)
 
// providing options
unified()
  .use(remarkParse)
  .use(remarkTruncateLinks, { style: `middle`, length: 40 })

As MDX plugin

import mdx from '@mdx-js/mdx'
import { remarkTruncateLinks } from 'remark-truncate-links'
const options = { length: 60 }
 
mdx(`mdxString`, { remarkPlugins: [[remarkTruncateLinks, options]] })

Ideas

Used in

Credits

Mentioned in

License

MIT

Package Sidebar

Install

npm i remark-truncate-links

Weekly Downloads

20

Version

1.0.3

License

MIT

Unpacked Size

7.1 kB

Total Files

5

Last publish

Collaborators

  • canrau