Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
21 changes: 15 additions & 6 deletions site/src/components/Markdown/InlineMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from "@mui/material/Link";
import isEqual from "lodash/isEqual";
import { type FC, memo } from "react";
import ReactMarkdown, { type Options } from "react-markdown";
import { Link } from "#/components/Link/Link";

interface InlineMarkdownProps {
/**
Expand Down Expand Up @@ -48,11 +48,20 @@ export const InlineMarkdown: FC<InlineMarkdownProps> = (props) => {
components={{
p: ({ children }) => <>{children}</>,

a: ({ href, target, children }) => (
<Link href={href} target={target}>
{children}
</Link>
),
a: ({ href, children }) => {
const isExternal = href?.startsWith("http");

return (
<Link
href={href}
target={isExternal ? "_blank" : undefined}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add interaction coverage for the new link behavior

For external links rendered through InlineMarkdown, this now sets target="_blank" and changes the rendered link primitive, but the existing WithLink story only supplies args and has no play assertion. Add Storybook interaction coverage that locates the link semantically and verifies the external and internal target behavior, as FE1 requires user-visible behavior changes to be exercised by a story's play function.

AGENTS.md reference: site/AGENTS.md:L9-L10

Useful? React with 👍 / 👎.

showExternalIcon={isExternal}
className="text-[length:inherit] p-0"
>
{children}
</Link>
);
},

code: ({ node, className, children, style, ...props }) => (
<code
Expand Down
84 changes: 22 additions & 62 deletions site/src/components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Interpolation, Theme } from "@emotion/react";
import isEqual from "lodash/isEqual";
import {
createElement,
Expand All @@ -21,7 +20,6 @@ import {
TableHeader,
TableRow,
} from "#/components/Table/Table";
import colors from "#/theme/tailwindColors";
import { cn } from "#/utils/cn";

interface MarkdownProps {
Expand All @@ -43,15 +41,19 @@ export const Markdown: FC<MarkdownProps> = (props) => {

return (
<ReactMarkdown
css={markdownStyles}
className={className}
className={cn(markdownClassName, className)}
remarkPlugins={[gfm]}
components={{
a: ({ href, children }) => {
const isExternal = href?.startsWith("http");

return (
<Link href={href} target={isExternal ? "_blank" : undefined}>
<Link
href={href}
target={isExternal ? "_blank" : undefined}
showExternalIcon={isExternal}
className="text-[length:inherit] p-0"
>
{children}
</Link>
);
Expand Down Expand Up @@ -328,60 +330,18 @@ const MarkdownGfmAlert: FC<MarkdownGfmAlertProps> = ({
);
};

const markdownStyles: Interpolation<Theme> = (theme: Theme) => ({
fontSize: 16,
lineHeight: "24px",

"& h1, & h2, & h3, & h4, & h5, & h6": {
marginTop: 32,
marginBottom: 16,
lineHeight: "1.25",
},

"& p": {
marginTop: 0,
marginBottom: 16,
},

"& p:only-child": {
marginTop: 0,
marginBottom: 0,
},

"& ul, & ol": {
display: "flex",
flexDirection: "column",
gap: 8,
marginBottom: 16,
},

"& li > ul, & li > ol": {
marginTop: 16,
},

"& li > p": {
marginBottom: 0,
},

"& .prismjs": {
background:
theme.palette.mode === "dark"
? colors.zinc[950]
: theme.palette.background.paper,
borderRadius: 8,
padding: "16px 24px",
overflowX: "auto",

"& code": {
color: theme.palette.text.secondary,
},

"& .key, & .property, & .inserted, .keyword": {
color: colors.teal[300],
},

"& .deleted": {
color: theme.palette.error.light,
},
},
});
const markdownClassName = cn(
"text-base",
"[&_:is(h1,h2,h3,h4,h5,h6)]:mt-8",
"[&_:is(h1,h2,h3,h4,h5,h6)]:mb-4",
"[&_:is(h1,h2,h3,h4,h5,h6)]:leading-tight",
"[&_p]:mt-0 [&_p]:mb-4 [&_p:only-child]:my-0",
"[&_ul]:mb-4 [&_ul]:flex [&_ul]:flex-col [&_ul]:gap-2",
"[&_ol]:mb-4 [&_ol]:flex [&_ol]:flex-col [&_ol]:gap-2",
"[&_li>ul]:mt-4 [&_li>ol]:mt-4 [&_li>p]:mb-0",
"[&_.prismjs]:overflow-x-auto [&_.prismjs]:rounded-lg [&_.prismjs]:bg-surface-secondary [&_.prismjs]:px-6 [&_.prismjs]:py-4",
"[&_.prismjs_code]:text-content-secondary",
"[&_.prismjs_.key]:text-syntax-key [&_.prismjs_.property]:text-syntax-key",
"[&_.prismjs_.inserted]:text-syntax-key [&_.prismjs_.keyword]:text-syntax-key",
"[&_.prismjs_.deleted]:text-content-destructive",
);
Comment on lines +333 to +347

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holy tailwind selectors. Can we inline this at usage? Non-blocking just not sure we need it to be defined here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agreedly hate this, but the alternative is to import a CSS file (gross? idk), I will come back to this post-MUI 🙏🏻

Loading