forked from phanan/vue-linkify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (30 loc) · 868 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*global define*/
import * as linkify from 'linkifyjs'
import linkifyHtml from 'linkifyjs/html'
import hashtag from 'linkifyjs/plugins/hashtag'
import mention from 'linkifyjs/plugins/mention'
hashtag(linkify); mention(linkify);
(function () {
function install (el, binding) {
el.innerHTML = linkifyHtml(el.innerHTML, {
nl2br: true, // optional
formatHref: {
hashtag: href => `/hashtag/${href.replace('#', '')}`,
mention: href => `/mention${href.replace('@', '')}`
},
className: {
hashtag: 'hashtag',
mention: 'mention'
}
})
}
if (typeof exports === 'object') {
module.exports = install
} else if (typeof define === 'function' && define.amd) {
define([], function () {
return install
})
} else if (window.Vue) {
window.Vue.directive('linkified', install)
}
})()