Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/core/src/lib/components/internal/rich-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Text({ props }: { props: TextArgs }) {
].filter(Boolean);

const renderText = (source: string): React.ReactNode => {
return types.reduce(
const wrapped = types.reduce(
(acc, type) => {
switch (type) {
case "link":
Expand All @@ -64,6 +64,29 @@ function Text({ props }: { props: TextArgs }) {
},
<span className={`${getColorCss(color)} notion-span`}>{source}</span>,
);

if (href) {
const isExternalLink =
href &&
!href.startsWith("/") &&
!href.includes(window.location.hostname);
return isExternalLink ? (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="notion-link notion-link-external"
>
{wrapped} <span className="notion-external-icon">↗</span>
</a>
) : (
<a href={href} className="notion-link">
{wrapped}
</a>
);
}

return wrapped;
};

return <>{renderText(content)}</>;
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions packages/story/src/stories/internal/rich-text.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta, StoryObj } from "@storybook/react";
import Component from "../../lib/Notion";
import json from "./rich-text.json";

const blocks = json.blocks as any;

const meta: Meta<typeof Component> = {
title: "Blocks/Internal/RichText",
component: Component,
};

export default meta;
type Story = StoryObj<typeof Component>;

export const RichText: Story = {
args: {
title: "Rich Text",
blocks: blocks.filter((block: any) => block.type !== "external-page-link"),
},
};

export const ExternalPageLink: Story = {
args: {
title: "External Page Link",
blocks: blocks.filter((block: any) => block.type === "external-page-link"),
},
};