Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/egoist/autolink.js
Auto-link url and images, email, video, music, <br/> in text.
https://github.com/egoist/autolink.js
Last synced: about 2 months ago
JSON representation
Auto-link url and images, email, video, music, <br/> in text.
- Host: GitHub
- URL: https://github.com/egoist/autolink.js
- Owner: egoist
- License: mit
- Created: 2015-11-30T06:25:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T14:10:48.000Z (over 2 years ago)
- Last Synced: 2024-07-22T04:37:28.661Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://autolink.netlify.com
- Size: 68.4 KB
- Stars: 78
- Watchers: 3
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# autolink.js [![Build Status](https://img.shields.io/circleci/project/egoist/autolink.js/master.svg?style=flat-square)](https://circleci.com/gh/egoist/autolink.js/tree/master)
Auto-link url and images, email, video, music, `
` in text.## Installation
CDN: https://unpkg.com/autolink.js/dist/autolink.min.js
```bash
npm install --save autolink.js
```## Example
```javascript
import autoLink from 'autolink.js'
// link URL and Images/Emails
// `https?://` is optional
// normal link is transformed to
// image address(png|gif|jpe?g) is transformed to
autoLink(text, {
// default options:
email: true,
image: true,
// \n to
br: true
})
// 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, {
// add attributes for image only
imageAttr: {
'data-image': true
},
// add attributes for link only
linkAttr: {
'data-link': true
},
// add attributes for both
sharedAttr: {
'data-shared': 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})
// enable to transform all embedable url
// eg: youtube/kickstarter/cloudmusic
autoLink(text, {
// enable all
embed: true,
// or just enable some of them
youtube: true,
kickstarter: true
})
// escape HTML tags, false by default
autoLink(text, {safe: true})
```## Embed
Feel free to send a PR for supporting more embed-able links.
Now we support:
- Youtube, eg `https://www.youtube.com/watch?v=5vOAxP-u5KA`
- Kickstarter, eg: `https://www.kickstarter.com/projects/1546683916/treasures-of-the-universe-unique-astrophotography?ref=home_popular`
- Cloudmusic, eg: `http://music.163.com/#/song?id=36103237`
- Youku, eg: `http://v.youku.com/v_show/id_XMTQwMDUzODM0MA==.html?f=23710673#paction`
- Vimeo, eg: `https://vimeo.com/channels/staffpicks/253396666`## License
MIT © [EGOIST](https://github.com/egoist)