import { Box, Button, Popover, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverHeader, PopoverTrigger, Portal, Text, } from '@chakra-ui/react' import React, { useState } from 'react' import UniOrg from '../../util/uniorg' import unified from 'unified' //import createStream from 'unified-stream' import uniorgParse from 'uniorg-parse' import uniorg2rehype from 'uniorg-rehype' //import highlight from 'rehype-highlight' import katex from 'rehype-katex' import 'katex/dist/katex.css' import rehype2react from 'rehype-react' export interface LinkProps { href: string children: any testProp: string getText: any previewNode?: any setPreviewNode: any } export const PreviewLink = (props: any) => { const { href, children, nodeById, getText, previewNode, setPreviewNode } = props const [previewText, setPreviewText] = useState('') const [whatever, type, uri] = [...href.matchAll(/(.*?)\:(.*)/g)][0] const processor = unified().use(uniorgParse).use(uniorg2rehype).use(katex).use(rehype2react, { createElement: React.createElement, // eslint-disable-next-line react/display-name }) type === 'id' && getText(uri, setPreviewText) return ( <> {children} {uri && {processor.processSync(previewText).result}} ) }