技术控

    今日:190| 主题:57880
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Convert Url Text to Hiperlink

[复制链接]
致命的是习惯 投递于 2016-10-3 00:31:40
105 2
text-to-link

  text-to-link is a small JavaScript and npm module that takes a string of text, finds URLs within it, and hyperlinks them.
  Basic Usage

  text-to-link adds an autoLink() method to JavaScript's String prototype, so you can use it on any JavaScript string. Take a look at the tests, but essentially, after including either autolink.js or autolink-min.js to your page, it works like this:
  1. // Input
  2. let textTolink = require('text-to-link')
  3. textTolink("This is a link to Google http://google.com")
  4. // Output
  5. "This is a link to Google <a href='http://google.com'>http://google.com</a>"
复制代码
Additional Options

  You can pass any additional HTML attributes to the anchor tag with a JavaScript object, like this:
  1. // Input
  2. let textTolink = require('text-to-link')
  3. textTolink("This is a link to Google http://google.com", { target: "_blank", rel: "nofollow", id: "1" })
  4. // Output
  5. "This is a link to Google <a href='http://google.com' target='_blank' rel='nofollow' id='1'>http://google.com</a>"
复制代码
Callback

  Callback option can be used to redefine how links will be rendered.
  1. // Input
  2. let textTolink = require('text-to-link')
  3. textTolink("This is a link to Google http://google.com", {
  4.   callback: function(url) {
  5.     return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null;
  6.   }
  7. })
  8. // Output
  9. "This is a link to image <img src='http://example.com/logo.png'>"
复制代码



上一篇:Documenting your Angular app using Dgeni in 10 easy steps
下一篇:js-next: a JavaScript next generation apps scaffolder
我叫mt 投递于 2016-10-25 02:21:06
朋友妻不可欺睡睡觉还可以
回复 支持 反对

使用道具 举报

董旭 投递于 2016-10-25 10:19:43
你长的拖慢网速,你长的太耗内存,大哥,把你脸上的分辨率调低点好吗?国际脸孔世界通用。
回复 支持 反对

使用道具 举报

我要投稿

回页顶回复上一篇下一篇回列表
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表