fix: a renderer isExternal var, remove redundant casts, add li comments
This commit is contained in:
@@ -215,11 +215,13 @@ const components: Components = {
|
||||
const firstHast = node?.children?.[0];
|
||||
const isKeyValue =
|
||||
firstHast?.type === "element" &&
|
||||
(firstHast as Element).tagName === "strong";
|
||||
firstHast.tagName === "strong";
|
||||
|
||||
if (isKeyValue) {
|
||||
const keyText = extractHastText(firstHast as Element);
|
||||
// Skip the first rendered child (the <strong>) — we replace it with KeyBadge.
|
||||
const keyText = extractHastText(firstHast);
|
||||
// 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);
|
||||
return (
|
||||
<li
|
||||
@@ -253,11 +255,13 @@ const components: Components = {
|
||||
);
|
||||
},
|
||||
|
||||
a: ({ href, children }) => (
|
||||
a: ({ href, children }) => {
|
||||
const isExternal = !!href && /^https?:\/\//.test(href);
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
target={href && /^https?:\/\//.test(href) ? "_blank" : undefined}
|
||||
rel={href && /^https?:\/\//.test(href) ? "noopener noreferrer" : undefined}
|
||||
target={isExternal ? "_blank" : undefined}
|
||||
rel={isExternal ? "noopener noreferrer" : undefined}
|
||||
style={{
|
||||
background: "linear-gradient(90deg, #facc15, #60a5fa)",
|
||||
WebkitBackgroundClip: "text",
|
||||
@@ -271,7 +275,8 @@ const components: Components = {
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
strong: ({ children }) => (
|
||||
<strong style={{ color: "#fde68a", fontWeight: 700 }}>{children}</strong>
|
||||
|
||||
Reference in New Issue
Block a user