fix: extract CodeRenderer as named component, fix external link detection
This commit is contained in:
@@ -72,6 +72,41 @@ function extractHastText(node: Element): string {
|
||||
.trim();
|
||||
}
|
||||
|
||||
function CodeRenderer({ children }: { children?: React.ReactNode }) {
|
||||
const insidePre = useContext(InsidePreContext);
|
||||
|
||||
if (insidePre) {
|
||||
return (
|
||||
<code
|
||||
style={{
|
||||
fontFamily: "var(--font-mono, 'Geist Mono', monospace)",
|
||||
fontSize: "0.9rem",
|
||||
color: "#e2e8f0",
|
||||
lineHeight: 1.65,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<code
|
||||
style={{
|
||||
background: "rgba(250, 204, 21, 0.1)",
|
||||
border: "1px solid rgba(250, 204, 21, 0.3)",
|
||||
borderRadius: 5,
|
||||
padding: "1px 7px",
|
||||
color: "#fde68a",
|
||||
fontFamily: "var(--font-mono, 'Geist Mono', monospace)",
|
||||
fontSize: "0.875em",
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
}
|
||||
|
||||
const components: Components = {
|
||||
h1: ({ children }) => (
|
||||
<h1
|
||||
@@ -221,8 +256,8 @@ const components: Components = {
|
||||
a: ({ href, children }) => (
|
||||
<a
|
||||
href={href}
|
||||
target={href?.startsWith("http") ? "_blank" : undefined}
|
||||
rel={href?.startsWith("http") ? "noopener noreferrer" : undefined}
|
||||
target={href && /^https?:\/\//.test(href) ? "_blank" : undefined}
|
||||
rel={href && /^https?:\/\//.test(href) ? "noopener noreferrer" : undefined}
|
||||
style={{
|
||||
background: "linear-gradient(90deg, #facc15, #60a5fa)",
|
||||
WebkitBackgroundClip: "text",
|
||||
@@ -266,41 +301,7 @@ const components: Components = {
|
||||
</InsidePreContext.Provider>
|
||||
),
|
||||
|
||||
code: ({ children }) => {
|
||||
const insidePre = useContext(InsidePreContext);
|
||||
|
||||
if (insidePre) {
|
||||
return (
|
||||
<code
|
||||
style={{
|
||||
fontFamily: "var(--font-mono, 'Geist Mono', monospace)",
|
||||
fontSize: "0.9rem",
|
||||
color: "#e2e8f0",
|
||||
lineHeight: 1.65,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
}
|
||||
|
||||
// Inline code
|
||||
return (
|
||||
<code
|
||||
style={{
|
||||
background: "rgba(250, 204, 21, 0.1)",
|
||||
border: "1px solid rgba(250, 204, 21, 0.3)",
|
||||
borderRadius: 5,
|
||||
padding: "1px 7px",
|
||||
color: "#fde68a",
|
||||
fontFamily: "var(--font-mono, 'Geist Mono', monospace)",
|
||||
fontSize: "0.875em",
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
},
|
||||
code: CodeRenderer,
|
||||
};
|
||||
|
||||
export default function MarkdownContent({ content }: { content: string }) {
|
||||
|
||||
Reference in New Issue
Block a user