import { marked } from "marked" import Image from "next/image" import Highlight, { defaultProps, Language } from "prism-react-renderer" // // image sizes. DDoS Safe? // const imageSizeLink = /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|[^\[\]\\])*?)\]\(\s*(<(?:\\[<>]?|[^\s<>\\])*>|(?:\\[()]?|\([^\s\x00-\x1f()\\]*\)|[^\s\x00-\x1f()\\])*?(?:\s+=(?:[\w%]+)?x(?:[\w%]+)?)?)(?:\s+("(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)))?\s*\)/; // //@ts-ignore // Lexer.rules.inline.normal.link = imageSizeLink; // //@ts-ignore // Lexer.rules.inline.gfm.link = imageSizeLink; // //@ts-ignore // Lexer.rules.inline.breaks.link = imageSizeLink; //@ts-ignore delete defaultProps.theme // import linkStyles from '../components/link/link.module.css' const renderer = new marked.Renderer() // @ts-ignore // renderer.heading = (text, level, raw, slugger) => { // const id = slugger.slug(text) // const Component = `h${level}` // return ( // // // {text} // // // ) // } // renderer.link = (href, _, text) => { // const isHrefLocal = href?.startsWith("/") || href?.startsWith("#") // if (isHrefLocal) { // return {text} // } // // dirty hack // // if text contains elements, render as html // return ( // // ) // } // @ts-ignore renderer.image = function (href, _, text) { return ${text} } // renderer.checkbox = () => "" // @ts-ignore renderer.listitem = (text, task, checked) => { if (task) { return (
  • ${text}
  • ) } return
  • {text}
  • } // @ts-ignore renderer.code = (code: string, language: string) => { const component =
    			
    			)
    		
    return component } marked.setOptions({ gfm: true, breaks: true, headerIds: true, renderer }) const markdown = (markdown: string) => marked(markdown) export default markdown const Code = ({ code, language, highlight, title, ...props }: { code: string language: string highlight?: string title?: string }) => { if (!language) return ( <> ) const highlightedLines = highlight ? //@ts-ignore highlight.split(",").reduce((lines, h) => { if (h.includes("-")) { // Expand ranges like 3-5 into [3,4,5] const [start, end] = h.split("-").map(Number) const x = Array(end - start + 1) .fill(undefined) .map((_, i) => i + start) return [...lines, ...x] } return [...lines, Number(h)] }, []) : "" // https://mdxjs.com/guides/syntax-harkedighlighting#all-together return ( <> {({ className, style, tokens, getLineProps, getTokenProps }: { className: string style: any tokens: any getLineProps: any getTokenProps: any }) => ( {tokens.map((line: string[], i: number) => (
    {line.map((token: string, key: number) => ( ))}
    ))}
    )}
    <> ) }