aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/angular.json1
-rw-r--r--client/package.json4
-rw-r--r--client/src/app/core/renderer/linkifier.service.ts102
-rw-r--r--client/yarn.lock18
4 files changed, 27 insertions, 98 deletions
diff --git a/client/angular.json b/client/angular.json
index 69de2e784..1dd745f09 100644
--- a/client/angular.json
+++ b/client/angular.json
@@ -156,6 +156,7 @@
156 "chart.js", 156 "chart.js",
157 "htmlparser2", 157 "htmlparser2",
158 "markdown-it-emoji/light", 158 "markdown-it-emoji/light",
159 "linkifyjs/lib/linkify-html",
159 "sanitize-html", 160 "sanitize-html",
160 "debug", 161 "debug",
161 "@peertube/p2p-media-loader-hlsjs", 162 "@peertube/p2p-media-loader-hlsjs",
diff --git a/client/package.json b/client/package.json
index 8e06b63d7..ac85366c3 100644
--- a/client/package.json
+++ b/client/package.json
@@ -102,7 +102,9 @@
102 "html-webpack-plugin": "^5.3.1", 102 "html-webpack-plugin": "^5.3.1",
103 "https-browserify": "^1.0.0", 103 "https-browserify": "^1.0.0",
104 "jschannel": "^1.0.2", 104 "jschannel": "^1.0.2",
105 "linkifyjs": "^2.1.5", 105 "linkify-html": "^3.0.2",
106 "linkify-plugin-mention": "^3.0.2",
107 "linkifyjs": "^3.0.2",
106 "lodash-es": "^4.17.4", 108 "lodash-es": "^4.17.4",
107 "markdown-it": "12.2.0", 109 "markdown-it": "12.2.0",
108 "mini-css-extract-plugin": "^2.2.0", 110 "mini-css-extract-plugin": "^2.2.0",
diff --git a/client/src/app/core/renderer/linkifier.service.ts b/client/src/app/core/renderer/linkifier.service.ts
index db9326d63..78df92cc9 100644
--- a/client/src/app/core/renderer/linkifier.service.ts
+++ b/client/src/app/core/renderer/linkifier.service.ts
@@ -12,110 +12,26 @@ export class LinkifierService {
12 className: { 12 className: {
13 mention: LinkifierService.CLASSNAME + '-mention', 13 mention: LinkifierService.CLASSNAME + '-mention',
14 url: LinkifierService.CLASSNAME + '-url' 14 url: LinkifierService.CLASSNAME + '-url'
15 },
16 formatHref: {
17 mention: (href: string) => {
18 return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + href.substr(1)
19 }
15 } 20 }
16 } 21 }
17 22
18 async linkify (text: string) { 23 async linkify (text: string) {
19 if (!this.linkifyModule) { 24 if (!this.linkifyModule) {
20 const result = await Promise.all([ 25 const result = await Promise.all([
21 import('linkifyjs'), // ES module 26 import('linkifyjs'),
22 import('linkifyjs/html').then(m => m.default) 27 import('linkify-plugin-mention'),
28 import('linkify-html').then(m => (m as any).default)
23 ]) 29 ])
24 30
25 this.linkifyModule = result[0] 31 this.linkifyModule = result[0]
26 this.linkifyHtmlModule = result[1] 32 this.linkifyHtmlModule = result[2]
27
28 this.mentionWithDomainPlugin()
29 } 33 }
30 34
31 return this.linkifyHtmlModule(text, this.linkifyOptions) 35 return this.linkifyHtmlModule(text, this.linkifyOptions)
32 } 36 }
33
34 private mentionWithDomainPlugin () {
35 const TT = this.linkifyModule.scanner.TOKENS // Text tokens
36 const { TOKENS: MT, State } = this.linkifyModule.parser // Multi tokens, state
37 const MultiToken = MT.Base
38 const S_START = this.linkifyModule.parser.start
39
40 const TT_AT = TT.AT
41 const TT_DOMAIN = TT.DOMAIN
42 const TT_LOCALHOST = TT.LOCALHOST
43 const TT_NUM = TT.NUM
44 const TT_COLON = TT.COLON
45 const TT_SLASH = TT.SLASH
46 const TT_TLD = TT.TLD
47 const TT_UNDERSCORE = TT.UNDERSCORE
48 const TT_DOT = TT.DOT
49
50 function MENTION (this: any, value: any) {
51 this.v = value
52 }
53
54 this.linkifyModule.inherits(MultiToken, MENTION, {
55 type: 'mentionWithDomain',
56 isLink: true,
57 toHref () {
58 return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + this.toString().substr(1)
59 }
60 })
61
62 const S_AT = S_START.jump(TT_AT) // @
63 const S_AT_SYMS = new State()
64 const S_MENTION = new State(MENTION)
65 const S_MENTION_DIVIDER = new State()
66 const S_MENTION_DIVIDER_SYMS = new State()
67
68 // @_,
69 S_AT.on(TT_UNDERSCORE, S_AT_SYMS)
70
71 // @_*
72 S_AT_SYMS
73 .on(TT_UNDERSCORE, S_AT_SYMS)
74 .on(TT_DOT, S_AT_SYMS)
75
76 // Valid mention (not made up entirely of symbols)
77 S_AT
78 .on(TT_DOMAIN, S_MENTION)
79 .on(TT_LOCALHOST, S_MENTION)
80 .on(TT_TLD, S_MENTION)
81 .on(TT_NUM, S_MENTION)
82
83 S_AT_SYMS
84 .on(TT_DOMAIN, S_MENTION)
85 .on(TT_LOCALHOST, S_MENTION)
86 .on(TT_TLD, S_MENTION)
87 .on(TT_NUM, S_MENTION)
88
89 // More valid mentions
90 S_MENTION
91 .on(TT_DOMAIN, S_MENTION)
92 .on(TT_LOCALHOST, S_MENTION)
93 .on(TT_TLD, S_MENTION)
94 .on(TT_COLON, S_MENTION)
95 .on(TT_NUM, S_MENTION)
96 .on(TT_UNDERSCORE, S_MENTION)
97
98 // Mention with a divider
99 S_MENTION
100 .on(TT_AT, S_MENTION_DIVIDER)
101 .on(TT_SLASH, S_MENTION_DIVIDER)
102 .on(TT_DOT, S_MENTION_DIVIDER)
103
104 // Mention _ trailing stash plus syms
105 S_MENTION_DIVIDER.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS)
106 S_MENTION_DIVIDER_SYMS.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS)
107
108 // Once we get a word token, mentions can start up again
109 S_MENTION_DIVIDER
110 .on(TT_DOMAIN, S_MENTION)
111 .on(TT_LOCALHOST, S_MENTION)
112 .on(TT_TLD, S_MENTION)
113 .on(TT_NUM, S_MENTION)
114
115 S_MENTION_DIVIDER_SYMS
116 .on(TT_DOMAIN, S_MENTION)
117 .on(TT_LOCALHOST, S_MENTION)
118 .on(TT_TLD, S_MENTION)
119 .on(TT_NUM, S_MENTION)
120 }
121} 37}
diff --git a/client/yarn.lock b/client/yarn.lock
index 0bd325ae9..44ec1bfe6 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -7852,6 +7852,11 @@ lines-and-columns@^1.1.6:
7852 resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" 7852 resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
7853 integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= 7853 integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=
7854 7854
7855linkify-html@^3.0.2:
7856 version "3.0.2"
7857 resolved "https://registry.yarnpkg.com/linkify-html/-/linkify-html-3.0.2.tgz#d9cd1bbb8afa54560d35427a22dbf2018ea44eb8"
7858 integrity sha512-vHIFhMjEFptdaRqk6wfNmtoBKkFPAkZGUwsThMafSnkqc02gZc6+bfAAxVgMZAn7NTxDYgSW2q04kmVAzYtEaA==
7859
7855linkify-it@^3.0.1: 7860linkify-it@^3.0.1:
7856 version "3.0.3" 7861 version "3.0.3"
7857 resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-3.0.3.tgz#a98baf44ce45a550efb4d49c769d07524cc2fa2e" 7862 resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-3.0.3.tgz#a98baf44ce45a550efb4d49c769d07524cc2fa2e"
@@ -7859,10 +7864,15 @@ linkify-it@^3.0.1:
7859 dependencies: 7864 dependencies:
7860 uc.micro "^1.0.1" 7865 uc.micro "^1.0.1"
7861 7866
7862linkifyjs@^2.1.5: 7867linkify-plugin-mention@^3.0.2:
7863 version "2.1.9" 7868 version "3.0.2"
7864 resolved "https://registry.yarnpkg.com/linkifyjs/-/linkifyjs-2.1.9.tgz#af06e45a2866ff06c4766582590d098a4d584702" 7869 resolved "https://registry.yarnpkg.com/linkify-plugin-mention/-/linkify-plugin-mention-3.0.2.tgz#ecb29e5840532e86c33007c54b210e5b5de266e9"
7865 integrity sha512-74ivurkK6WHvHFozVaGtQWV38FzBwSTGNmJolEgFp7QgR2bl6ArUWlvT4GcHKbPe1z3nWYi+VUdDZk16zDOVug== 7870 integrity sha512-NWYZLFyZV5uJWETHpNzsFZO+gk22hu5sbj8rndthfv5t+hQTozYkKt13b5nugvk30QSRQ4ULvhsTrEA8ohceOA==
7871
7872linkifyjs@^3.0.2:
7873 version "3.0.2"
7874 resolved "https://registry.yarnpkg.com/linkifyjs/-/linkifyjs-3.0.2.tgz#f1d300300ef21dab0eaabdd8a661186723f924ba"
7875 integrity sha512-PSHDxSAWkZQ208W4PI/+yo9NHSI6NAHKmazMtyRavyibJgrPOioPIjQn7zyapASQlKoPmAV+tOlqzTqX3XFWXQ==
7866 7876
7867load-ip-set@^2.2.1: 7877load-ip-set@^2.2.1:
7868 version "2.2.1" 7878 version "2.2.1"