1 import { Injectable } from '@angular/core'
2 import { getAbsoluteAPIUrl } from '@app/helpers/utils'
5 export class LinkifierService {
6 static CLASSNAME = 'linkified'
8 private linkifyModule: any
9 private linkifyHtmlModule: any
11 private linkifyOptions = {
13 mention: LinkifierService.CLASSNAME + '-mention',
14 url: LinkifierService.CLASSNAME + '-url'
17 mention: (href: string) => {
18 return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + href.substr(1)
23 async linkify (text: string) {
24 if (!this.linkifyModule) {
25 const result = await Promise.all([
27 import('linkify-plugin-mention'),
28 import('linkify-html').then(m => (m as any).default)
31 this.linkifyModule = result[0]
32 this.linkifyHtmlModule = result[2]
35 return this.linkifyHtmlModule(text, this.linkifyOptions)