]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/renderer/linkifier.service.ts
Support bulk registration request removal
[github/Chocobozzz/PeerTube.git] / client / src / app / core / renderer / linkifier.service.ts
1 import { Injectable } from '@angular/core'
2 import { getAbsoluteAPIUrl } from '@app/helpers/utils'
3
4 @Injectable()
5 export class LinkifierService {
6 static CLASSNAME = 'linkified'
7
8 private linkifyModule: any
9 private linkifyHtmlModule: any
10
11 private linkifyOptions = {
12 className: {
13 mention: LinkifierService.CLASSNAME + '-mention',
14 url: LinkifierService.CLASSNAME + '-url'
15 },
16 formatHref: {
17 mention: (href: string) => {
18 return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + href.substring(1)
19 }
20 }
21 }
22
23 async linkify (text: string) {
24 if (!this.linkifyModule) {
25 const result = await Promise.all([
26 import('linkifyjs'),
27 import('linkify-plugin-mention'),
28 import('linkify-html').then(m => (m as any).default)
29 ])
30
31 this.linkifyModule = result[0]
32 this.linkifyHtmlModule = result[2]
33 }
34
35 return this.linkifyHtmlModule(text, this.linkifyOptions)
36 }
37 }