]>
Commit | Line | Data |
---|---|---|
e8cb4409 | 1 | import { Injectable } from '@angular/core' |
67ed6552 | 2 | import { getAbsoluteAPIUrl } from '@app/helpers/utils' |
e8cb4409 C |
3 | |
4 | @Injectable() | |
5 | export class LinkifierService { | |
e8cb4409 C |
6 | static CLASSNAME = 'linkified' |
7 | ||
b355b394 C |
8 | private linkifyModule: any |
9 | private linkifyHtmlModule: any | |
10 | ||
e8cb4409 C |
11 | private linkifyOptions = { |
12 | className: { | |
13 | mention: LinkifierService.CLASSNAME + '-mention', | |
14 | url: LinkifierService.CLASSNAME + '-url' | |
f8ddccf2 C |
15 | }, |
16 | formatHref: { | |
17 | mention: (href: string) => { | |
cd940f40 | 18 | return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + href.substring(1) |
f8ddccf2 | 19 | } |
e8cb4409 C |
20 | } |
21 | } | |
22 | ||
b355b394 C |
23 | async linkify (text: string) { |
24 | if (!this.linkifyModule) { | |
25 | const result = await Promise.all([ | |
f8ddccf2 C |
26 | import('linkifyjs'), |
27 | import('linkify-plugin-mention'), | |
28 | import('linkify-html').then(m => (m as any).default) | |
b355b394 C |
29 | ]) |
30 | ||
31 | this.linkifyModule = result[0] | |
f8ddccf2 | 32 | this.linkifyHtmlModule = result[2] |
b355b394 | 33 | } |
e8cb4409 | 34 | |
b355b394 | 35 | return this.linkifyHtmlModule(text, this.linkifyOptions) |
e8cb4409 | 36 | } |
e8cb4409 | 37 | } |