Skip to content

Commit

Permalink
chore: 🔧 improve emoji hook n update emoji regex
Browse files Browse the repository at this point in the history
  • Loading branch information
themashcodee committed Jul 12, 2024
1 parent 99de837 commit a615b0c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions src/components/blocks/rich_text/rich_text_section_emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<span className="slack_blocks_to_jsx__rich_text_section_element_emoji">{custom_emoji}</span>
);
}
return (
<span className="slack_blocks_to_jsx__rich_text_section_element_emoji">
{hooks.emoji(name, (name) => parseEmojis(`:${name}:`))}
</span>
);
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/store/useGlobalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/utils/markdown_parser/sub_elements/slack_emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span className="slack_emoji">{parseEmojis(`:${element.value}:`)}</span>;
};
2 changes: 1 addition & 1 deletion src/utils/markdown_parser/tokenizers/slack_emoji/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const parse: IParseInlineHookCreator<T, IToken, INode, IThis> = function
const nodePoints: ReadonlyArray<INodePoint> = 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;
Expand Down

0 comments on commit a615b0c

Please sign in to comment.