Nertivia-Client/src/utils/markdown-rules/link.js
2019-11-12 17:47:51 -05:00

41 lines
No EOL
688 B
JavaScript

import * as SimpleMarkdown from 'simple-markdown'
import LinkifyIt from 'linkify-it'
const linkify = LinkifyIt()
export default (order) => { return {
order: order++,
match: function(source) {
const match = linkify.match(source)
if(match === null) {
return null
}
const converted = [
match[0].raw,
match[0].text,
match[0].url,
]
return converted
},
parse: function(capture, parse, state) {
return {
content: {
type: 'text',
content: capture[1]
},
url: capture[2]
}
},
html: function(node, output) {
return SimpleMarkdown.htmlTag("a", output(node.content), {
href: node.url,
class: "msg-link",
target: "_blank"
})
}
}}