From d432e7e24e9a6b8d7161baf40594524537ce3765 Mon Sep 17 00:00:00 2001 From: nokhnaton Date: Tue, 29 Oct 2024 00:47:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=81=AE=E5=89=8D=E3=81=AB:=E3=81=8C=E3=81=A4?= =?UTF-8?q?=E3=81=8F=E3=81=A8=E3=83=A1=E3=83=B3=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/markdown/internalLinkEmbedder.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/markdown/internalLinkEmbedder.ts b/src/lib/markdown/internalLinkEmbedder.ts index da2724194..04b99564b 100644 --- a/src/lib/markdown/internalLinkEmbedder.ts +++ b/src/lib/markdown/internalLinkEmbedder.ts @@ -2,7 +2,7 @@ * https://github.com/traPtitech/traQ/blob/master/utils/message/replacer.goと同様 */ -const mentionRegex = /:?[@@]([^\s@@]{0,31}[^\s@@:])/g +const mentionRegex = /:?[@@]([^\s@@]{0,31}[^\s@@:]:?)/g const userStartsRegex = /^[@@]([a-zA-Z0-9_-]{1,32})/g const channelRegex = /[##]([a-zA-Z0-9_/-]+)/g @@ -114,21 +114,28 @@ const replaceAll = (m: string, getters: Readonly) => { const replaceMention = (m: string, getters: Readonly) => { return m.replace(mentionRegex, s => { - // 始まりが:なものを除外 - if (s.startsWith(':')) { + const isStartsWithColon = s.startsWith(':') + + // 始まりと終わりが:なものを除外 + if (isStartsWithColon && s.endsWith(':')) { return s } + const sColonRemoved = isStartsWithColon ? s.slice(1) : s.slice(0) - // .slice(1)は先頭の@を消すため + // .slice(1)は先頭の@および:@を消すため // 小文字化はgetter内で行う - const name = s.slice(1) + const name = sColonRemoved.slice(1) const uid = getters.getUser(name)?.id if (uid) { - return `!{"type":"user","raw":"${s}","id":"${uid}"}` + return `${ + isStartsWithColon ? ':' : '' + }!{"type":"user","raw":"${sColonRemoved}","id":"${uid}"}` } const gid = getters.getGroup(name)?.id if (gid) { - return `!{"type":"group","raw":"${s}","id":"${gid}"}` + return `${ + isStartsWithColon ? ':' : '' + }!{"type":"group","raw":"${sColonRemoved}","id":"${gid}"}` } return s.replace(userStartsRegex, s => { From 20d1bf3302b9475bb92f81575e1d64b534595d63 Mon Sep 17 00:00:00 2001 From: nokhnaton Date: Tue, 29 Oct 2024 01:59:04 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8A=E6=89=8B=E3=81=8F=E7=BD=AE?= =?UTF-8?q?=E6=8F=9B=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=83=91=E3=82=BF?= =?UTF-8?q?=E3=83=BC=E3=83=B3=E3=82=92=E6=BD=B0=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/markdown/internalLinkEmbedder.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/markdown/internalLinkEmbedder.ts b/src/lib/markdown/internalLinkEmbedder.ts index 04b99564b..899c907f4 100644 --- a/src/lib/markdown/internalLinkEmbedder.ts +++ b/src/lib/markdown/internalLinkEmbedder.ts @@ -2,7 +2,8 @@ * https://github.com/traPtitech/traQ/blob/master/utils/message/replacer.goと同様 */ -const mentionRegex = /:?[@@]([^\s@@]{0,31}[^\s@@:]:?)/g +const mentionRegex = + /([@@]([^\s@@]{0,31}[^\s@@:]))|(:[@@]([^\s@@]{0,31}[^\s@@:]:))/g const userStartsRegex = /^[@@]([a-zA-Z0-9_-]{1,32})/g const channelRegex = /[##]([a-zA-Z0-9_/-]+)/g @@ -114,6 +115,7 @@ const replaceAll = (m: string, getters: Readonly) => { const replaceMention = (m: string, getters: Readonly) => { return m.replace(mentionRegex, s => { + console.log(s) const isStartsWithColon = s.startsWith(':') // 始まりと終わりが:なものを除外 From c1e75293d397ed38a129a55bec1323c4cafa2e75 Mon Sep 17 00:00:00 2001 From: nokhnaton Date: Tue, 29 Oct 2024 02:13:05 +0900 Subject: [PATCH 3/3] =?UTF-8?q?console=E3=82=92=E6=BD=B0=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/markdown/internalLinkEmbedder.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/markdown/internalLinkEmbedder.ts b/src/lib/markdown/internalLinkEmbedder.ts index 899c907f4..210f75a75 100644 --- a/src/lib/markdown/internalLinkEmbedder.ts +++ b/src/lib/markdown/internalLinkEmbedder.ts @@ -115,7 +115,6 @@ const replaceAll = (m: string, getters: Readonly) => { const replaceMention = (m: string, getters: Readonly) => { return m.replace(mentionRegex, s => { - console.log(s) const isStartsWithColon = s.startsWith(':') // 始まりと終わりが:なものを除外