From 0f815f6ed34a9050b5097cbdf1679ec489f4eea0 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Wed, 29 Nov 2023 02:02:45 +0900 Subject: [PATCH 1/4] feat(frontend,mfm): allow RGBA8888 for fg.color and bg.color close misskey-dev#10683 --- .../src/components/global/MkMisskeyFlavoredMarkdown.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 9eab85500400..06ef593bf8f0 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -62,12 +62,14 @@ export default function(props: MfmProps, context: SetupContext) { if (t == null) return null; return t.match(/^[0-9.]+s$/) ? t : null; }; - + const validColor = (c: string | null | undefined): string | null => { if (c == null) return null; - return c.match(/^[0-9a-f]{3,6}$/i) ? c : null; + // https://www.debuggex.com/r/Bb7wXENuNZZzUb2G + const rgbaPattern = /^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; + return c.match(rgbaPattern) ? c : null; }; - + const useAnim = defaultStore.state.advancedMfm && defaultStore.state.animatedMfm; /** From a5ef0c70222e4d2af7dd6234a2c28922021597c0 Mon Sep 17 00:00:00 2001 From: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:41:33 +0900 Subject: [PATCH 2/4] refactor: shorten regexp apply diff from review --- .../src/components/global/MkMisskeyFlavoredMarkdown.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 06ef593bf8f0..9efc953629e6 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -65,8 +65,8 @@ export default function(props: MfmProps, context: SetupContext) { const validColor = (c: string | null | undefined): string | null => { if (c == null) return null; - // https://www.debuggex.com/r/Bb7wXENuNZZzUb2G - const rgbaPattern = /^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; + // https://www.debuggex.com/r/rm2GyVlKprvXbs35 + const rgbaPattern = /^([\da-f]{3}|([\da-f]{2}){2,4})$/i; return c.match(rgbaPattern) ? c : null; }; From f3a053d5cc469f13a9f28e65cca600bd083e8fbe Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Wed, 29 Nov 2023 02:02:45 +0900 Subject: [PATCH 3/4] feat(frontend,mfm): allow RGBA8888 for fg.color and bg.color close misskey-dev#10683 --- .../src/components/global/MkMisskeyFlavoredMarkdown.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index b234144c137d..5e986bd8edac 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -65,7 +65,9 @@ export default function(props: MfmProps, context: SetupContext) { const validColor = (c: string | null | undefined): string | null => { if (c == null) return null; - return c.match(/^[0-9a-f]{3,6}$/i) ? c : null; + // https://www.debuggex.com/r/Bb7wXENuNZZzUb2G + const rgbaPattern = /^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; + return c.match(rgbaPattern) ? c : null; }; const useAnim = defaultStore.state.advancedMfm && defaultStore.state.animatedMfm; From 4c79209d13b44ef4db2524c0d97d34a03da70ee7 Mon Sep 17 00:00:00 2001 From: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:41:33 +0900 Subject: [PATCH 4/4] refactor: shorten regexp apply diff from review --- .../src/components/global/MkMisskeyFlavoredMarkdown.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 5e986bd8edac..3c3eb75e9040 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -65,8 +65,8 @@ export default function(props: MfmProps, context: SetupContext) { const validColor = (c: string | null | undefined): string | null => { if (c == null) return null; - // https://www.debuggex.com/r/Bb7wXENuNZZzUb2G - const rgbaPattern = /^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; + // https://www.debuggex.com/r/rm2GyVlKprvXbs35 + const rgbaPattern = /^([\da-f]{3}|([\da-f]{2}){2,4})$/i; return c.match(rgbaPattern) ? c : null; };