import ReactMarkdown from "react-markdown"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import rehypeExternalLinks from "rehype-external-links"; import { Button, View, Image, Flex } from "@aws-amplify/ui-react"; import { useState } from "react"; import { CopyToClipboard } from "react-copy-to-clipboard"; import type { ComponentPropsWithoutRef, ElementType } from "react"; import type { ReactMarkdownProps } from "react-markdown/lib/complex-types"; import styles from "./LearnMarkdown.module.scss"; type PropsHelper = ComponentPropsWithoutRef & ReactMarkdownProps; function CodeBlock({ node, children, inline, className, ...props }: { node: any; children: any; inline?: any; className?: any; }) { const match = /language-(\w+)/.exec(className || ""); const [showButton, setShowButton] = useState(false); const [copied, setCopied] = useState(false); // Custom wrapper around `code` const PreTag = ({ children, ...rest }: { children: any }) => ( {children} ); return match ? (
{ setShowButton(true); }} onMouseLeave={() => { setShowButton(false); setCopied(false); }} > {showButton && ( { setCopied(true); }} > )} {String(children).replace(/\n$/, "")} {" "}
) : ( {children} ); } function Paragraph({ node, children }: PropsHelper<"p">) { if ( node.children[0].type === "element" && node.children[0].tagName === "img" ) { const image = node.children[0]; const alt = image?.properties?.alt; const src = image?.properties?.src; if ( typeof src === "string" && (typeof alt === "string" || typeof alt === "undefined") ) { return ( {alt ); } } return

{children}

; } export function LearnMarkdown({ markdownContent, }: { markdownContent: string; }) { return ( {markdownContent} ); }