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: remarkTruncateLinks // providing options resolve: `gatsby-plugin-mdx` options: remarkPlugins: remarkTruncateLinks style: 'middle'
Using Unified
// with default options // providing options
As MDX plugin
const options = length: 60
Ideas
- Truncate based on host, for example truncate GitHub repos to repo name like GaiAma/Coding4GaiAma
- Check out https://github.com/williambelle/crop-url
Used in
- gatsby-transformer-leasot - make your TODOs and FIXMEs from comments in your files queryable via GraphQL
- coding4.gaiama.org - As MDX plugin to truncate all links not manually named.
Credits
- Autolinker.js - is used for actual truncation
- Unified & Remark
Mentioned in
License
MIT