fix: a renderer isExternal var, remove redundant casts, add li comments

This commit is contained in:
2026-04-10 01:00:43 +02:00
parent 39cb194b5b
commit f914d14f15

View File

@@ -215,11 +215,13 @@ const components: Components = {
const firstHast = node?.children?.[0]; const firstHast = node?.children?.[0];
const isKeyValue = const isKeyValue =
firstHast?.type === "element" && firstHast?.type === "element" &&
(firstHast as Element).tagName === "strong"; firstHast.tagName === "strong";
if (isKeyValue) { if (isKeyValue) {
const keyText = extractHastText(firstHast as Element); const keyText = extractHastText(firstHast);
// Skip the first rendered child (the <strong>) — we replace it with KeyBadge. // Skip index 0 (the rendered <strong> element) — works because react-markdown
// emits strong as child[0] for tight lists with the `- **Key:** value` pattern.
// Tight lists only: loose lists wrap content in <p>, changing the HAST structure.
const rest = React.Children.toArray(children).slice(1); const rest = React.Children.toArray(children).slice(1);
return ( return (
<li <li
@@ -253,11 +255,13 @@ const components: Components = {
); );
}, },
a: ({ href, children }) => ( a: ({ href, children }) => {
const isExternal = !!href && /^https?:\/\//.test(href);
return (
<a <a
href={href} href={href}
target={href && /^https?:\/\//.test(href) ? "_blank" : undefined} target={isExternal ? "_blank" : undefined}
rel={href && /^https?:\/\//.test(href) ? "noopener noreferrer" : undefined} rel={isExternal ? "noopener noreferrer" : undefined}
style={{ style={{
background: "linear-gradient(90deg, #facc15, #60a5fa)", background: "linear-gradient(90deg, #facc15, #60a5fa)",
WebkitBackgroundClip: "text", WebkitBackgroundClip: "text",
@@ -271,7 +275,8 @@ const components: Components = {
> >
{children} {children}
</a> </a>
), );
},
strong: ({ children }) => ( strong: ({ children }) => (
<strong style={{ color: "#fde68a", fontWeight: 700 }}>{children}</strong> <strong style={{ color: "#fde68a", fontWeight: 700 }}>{children}</strong>