Skip to content

Commit

Permalink
Merge pull request #148 from basehub-ai/rich-text-highlight-support
Browse files Browse the repository at this point in the history
Add highlight mark handlers
  • Loading branch information
moransantiago authored Feb 5, 2025
2 parents 12ca751 + 3026a06 commit 6483846
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-guests-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"basehub": patch
---

Add highlight mark handlers
2 changes: 2 additions & 0 deletions .github/workflows/sdk-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- run: npm install -g corepack@latest

- run: corepack enable
- uses: actions/setup-node@v4
with:
Expand Down
10 changes: 10 additions & 0 deletions packages/basehub/src/react/rich-text/primitive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Marks = Array<Mark>;
type Handlers = {
p: (props: { children: ReactNode }) => ReactNode;
b: (props: { children: ReactNode }) => ReactNode;
highlight: (props: { children: ReactNode }) => ReactNode;
em: (props: { children: ReactNode }) => ReactNode;
s: (props: { children: ReactNode }) => ReactNode;
kbd: (props: { children: ReactNode }) => ReactNode;
Expand Down Expand Up @@ -220,6 +221,7 @@ const defaultHandlers: Handlers = {
}) as Handlers["a"],
p: ({ children }) => <p>{children}</p>,
b: ({ children }) => <b>{children}</b>,
highlight: ({ children }) => <span>{children}</span>,
em: ({ children }) => <em>{children}</em>,
s: ({ children }) => <s>{children}</s>,
kbd: ({ children }) => <kbd>{children}</kbd>,
Expand Down Expand Up @@ -575,6 +577,14 @@ const Marks = ({
(disableDefaultComponents ? () => <></> : defaultHandlers.b);
props = { children } satisfies ExtractPropsForHandler<Handlers["b"]>;
break;
case "highlight":
Handler =
components?.highlight ??
(disableDefaultComponents ? () => <></> : defaultHandlers.highlight);
props = { children } satisfies ExtractPropsForHandler<
Handlers["highlight"]
>;
break;
case "italic":
Handler =
components?.em ??
Expand Down

0 comments on commit 6483846

Please sign in to comment.