Skip to content

Auto-link url and images, email, video, music, <br/> in text.

License

Notifications You must be signed in to change notification settings

Comdex/autolink.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autolink.js Build Status

Auto-link url and images, email, video, music, <br/> in text.

Installation

CDN: https://npmcdn.com/autolink.js/autolink.min.js

npm install --save autolink.js

Example

import autoLink from 'autolink.js'
// link URL and Images/Emails
// `https?://` is optional
// normal link is transformed to <a>
// image address(png|gif|jpe?g) is transformed to <img>
autoLink(text, {
  // default options:
  email: true,
  image: true,
  // \n to <br/>
  br: true
})
// link URL only
// then it would regard image address as normal link using <a>
// instead of using <img> 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
// '<a href="http://github.com">github.com</a>'
// wow, without `http://` in the text
autoLink(text, {removeHTTP: true})
// enable to transform all embedable url
// eg: youtube/kickstarter/cloudmusic
autoLink(text, {embed: 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

License

MIT © EGOIST

About

Auto-link url and images, email, video, music, <br/> in text.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 71.9%
  • HTML 28.1%