diff --git a/site/src/components/Markdown/Markdown.tsx b/site/src/components/Markdown/Markdown.tsx index ba7bcbf29a903..6423f33d1ce00 100644 --- a/site/src/components/Markdown/Markdown.tsx +++ b/site/src/components/Markdown/Markdown.tsx @@ -163,7 +163,7 @@ interface InlineMarkdownProps { /** * Additional element types to allow. * Allows italic, bold, links, and inline code snippets by default. - * eg. `["ol", "ul", "li"]` to support lists. + * eg. ["ol", "ul", "li"] to support lists. */ allowedElements?: readonly string[]; @@ -251,9 +251,14 @@ function parseChildrenAsAlertContent( return null; } - const mainParentNode = jsxChildren.find((node): node is ReactElement => - isValidElement(node), + // Identify the first element (usually a

) which contains the marker like [!NOTE] + const firstElementIndex = jsxChildren.findIndex( + (node): node is ReactElement => isValidElement(node), ); + const mainParentNode = + firstElementIndex >= 0 + ? (jsxChildren[firstElementIndex] as ReactElement) + : undefined; let parentChildren = mainParentNode?.props.children; if (typeof parentChildren === "string") { // Children will only be an array if the parsed text contains other @@ -301,7 +306,7 @@ function parseChildrenAsAlertContent( }, }; }); - const [firstEl, ...remainingChildren] = outputContent; + const [firstEl, ...firstParagraphRemainder] = outputContent; if (typeof firstEl !== "string") { return null; } @@ -317,14 +322,21 @@ function parseChildrenAsAlertContent( } const hasLeadingLinebreak = - isValidElement(remainingChildren[0]) && remainingChildren[0].type === "br"; + isValidElement(firstParagraphRemainder[0]) && + firstParagraphRemainder[0].type === "br"; if (hasLeadingLinebreak) { - remainingChildren.shift(); + firstParagraphRemainder.shift(); } + // Include all sibling nodes after the first paragraph so that additional + // content (including links) renders inside the alert. + const trailingSiblings = jsxChildren + .slice(firstElementIndex + 1) + .filter((el) => !(typeof el === "string" && el.trim() === "")); + return { type: alertType, - children: remainingChildren, + children: [...firstParagraphRemainder, ...trailingSiblings], }; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy