autolink.js:自动转义图片和网址

1,201 阅读1分钟

Auto-link url and images in text.

Installation

npm install --save autolink.js

Example

import autoLink from 'autolink.js'
// link URL and Images
// normal link is transformed to 
// image address(png|gif|jpe?g) is transformed to 
autoLink(text)
// link URL only
// then it would regard image address as normal link using 
// instead of using  tag
autoLink(text, {image: false})
// link-ify and add DOM attributes
autoLink(text, {
  pattern: '[a-zA-Z0-9]',
  'data-lazyload': true
})
// show URL path only for normal links
// eg: 'http://github.com' is transformed to
// 'github.com'
// wow, without `http://` in the text
autoLink(text, {removeHTTP: true})

License

MIT © EGOIST