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
.
# 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…
yarn add -D remark-truncate-links
# or
npm i -D remark-truncate-links
{
style: `smart`, // one of [`smart`, `middle`, `end`]
length: 30,
}
// showing default options
// 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' },
],
],
},
}
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 })
import mdx from '@mdx-js/mdx'
import { remarkTruncateLinks } from 'remark-truncate-links'
const options = { length: 60 }
mdx(`mdxString`, { remarkPlugins: [[remarkTruncateLinks, options]] })
- Truncate based on host, for example truncate GitHub repos to repo name like GaiAma/Coding4GaiAma
- Check out https://github.com/williambelle/crop-url
- 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.
- Autolinker.js - is used for actual truncation
- Unified & Remark
MIT