From a615b0cbd911e64050e879a336a17e798d40f1a0 Mon Sep 17 00:00:00 2001 From: themashcodee Date: Fri, 12 Jul 2024 21:33:51 +0530 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=94=A7=20improve=20emoji=20hook?= =?UTF-8?q?=20n=20update=20emoji=20regex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- .../blocks/rich_text/rich_text_section_emoji.tsx | 11 +++++------ src/store/useGlobalData.ts | 2 +- .../markdown_parser/sub_elements/slack_emoji.tsx | 5 +---- .../markdown_parser/tokenizers/slack_emoji/parse.ts | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 6116330..bcccd71 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ ], "repository": "https://github.com/themashcodee/slack-blocks-to-jsx.git", "license": "MIT", - "version": "0.3.9", + "version": "0.3.10", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", diff --git a/src/components/blocks/rich_text/rich_text_section_emoji.tsx b/src/components/blocks/rich_text/rich_text_section_emoji.tsx index bb881e7..7ae2a9c 100644 --- a/src/components/blocks/rich_text/rich_text_section_emoji.tsx +++ b/src/components/blocks/rich_text/rich_text_section_emoji.tsx @@ -9,12 +9,11 @@ export const RichTextSectionEmoji = (props: Props) => { const { hooks } = useGlobalData(); if (hooks.emoji) { - const custom_emoji = hooks.emoji(name); - if (custom_emoji !== "fallback") { - return ( - {custom_emoji} - ); - } + return ( + + {hooks.emoji(name, (name) => parseEmojis(`:${name}:`))} + + ); } return ( diff --git a/src/store/useGlobalData.ts b/src/store/useGlobalData.ts index 71c8362..31aa100 100644 --- a/src/store/useGlobalData.ts +++ b/src/store/useGlobalData.ts @@ -23,7 +23,7 @@ type Hooks = { atChannel?: () => ReactNode; atEveryone?: () => ReactNode; atHere?: () => ReactNode; - emoji?: (name: string) => ReactNode | "fallback"; + emoji?: (name: string, parse: (name: string) => string) => ReactNode; date?: (data: { timestamp: string; format: string; diff --git a/src/utils/markdown_parser/sub_elements/slack_emoji.tsx b/src/utils/markdown_parser/sub_elements/slack_emoji.tsx index d7573b5..1933cf9 100644 --- a/src/utils/markdown_parser/sub_elements/slack_emoji.tsx +++ b/src/utils/markdown_parser/sub_elements/slack_emoji.tsx @@ -10,10 +10,7 @@ export const SlackEmoji = (props: Props) => { const { element } = props; const { hooks } = useGlobalData(); - if (hooks.emoji) { - const custom_emoji = hooks.emoji(element.value); - if (custom_emoji !== "fallback") return <>{custom_emoji}; - } + if (hooks.emoji) return hooks.emoji(element.value, (name) => parseEmojis(`:${name}:`)); return {parseEmojis(`:${element.value}:`)}; }; diff --git a/src/utils/markdown_parser/tokenizers/slack_emoji/parse.ts b/src/utils/markdown_parser/tokenizers/slack_emoji/parse.ts index 4c4e107..591042e 100644 --- a/src/utils/markdown_parser/tokenizers/slack_emoji/parse.ts +++ b/src/utils/markdown_parser/tokenizers/slack_emoji/parse.ts @@ -10,7 +10,7 @@ export const parse: IParseInlineHookCreator = function const nodePoints: ReadonlyArray = api.getNodePoints(); const fullString = calcStringFromNodePoints(nodePoints, token.startIndex, token.endIndex); - const emojiPattern = /^:([\w-]+):$/; + const emojiPattern = /^:([a-zA-Z0-9_\-+']+):$/; const match = emojiPattern.exec(fullString); let value = fullString;