Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapirrone committed Dec 16, 2024
2 parents f2f3b74 + 418dc1d commit aa41d54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 13 additions & 0 deletions apps/storybook/stories/Markdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ export const MarkdownSizes = bind(
)

MarkdownSizes.storyName = 'Different Markdown Sizes'

const PLAYER_REGEX = '^https://my\\.learnn\\.com/player/.*$'
export const MarkdownOpenLinks = bind(
<AppShell theme={defaultTheme}>
<HorizontalStack justifyContent='space-evenly'>
<Markdown size='sm' opensInSameTabRegex={PLAYER_REGEX}>[Open in the same tab](https://my.learnn.com/player/7164/?t=14) </Markdown>
<Markdown size='sm'>[Open in a new tab](https://my.learnn.com/player/7164/?t=14)</Markdown>
<Markdown size='sm' opensInSameTabRegex={PLAYER_REGEX}>[Open in the same tab](https://my.learnn.com/player/7164)</Markdown>
</HorizontalStack>
</AppShell>,
)

MarkdownOpenLinks.storyName = 'Different Markdown Opening links'
15 changes: 8 additions & 7 deletions packages/designn/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ export type MarkdownProps = {
size?: Size
/** Markdown Overrides */
overrides?: MarkdownOverrides
/** If the regex matches the link, opens it in the same tab */
opensInSameTabRegex?: string
}

export const Markdown = ({ children, overrides, ...props }: MarkdownProps & SpaceProps & LayoutProps) => {
export const Markdown = ({ children, overrides, opensInSameTabRegex, ...props }: MarkdownProps & SpaceProps & LayoutProps) => {
return (
<StyledMarkdown {...props}>
<ReactMarkdown
renderers={{
link: props => (
<a href={props.node.url} target='_blank'>
{props.children}
</a>
),
}}
link: (props: any) => {
const target = opensInSameTabRegex && new RegExp(opensInSameTabRegex).test(props.node.url) ? '' : '_blank'
return <a href={props.node.url} target={target}>{props.children}</a>
},
}}
{...overrides?.reactMarkdownProps}
>
{children}
Expand Down

0 comments on commit aa41d54

Please sign in to comment.