diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-10-07 01:42:14 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-10-07 01:42:14 +0200 |
commit | fd4edbd6a854275c10c5b21173f0875921d547d1 (patch) | |
tree | ae25a9a95609636be0fadf79f70f4ef8eb01b4b5 /util/processOrg.tsx | |
parent | 33839479e269bed905f9eefc374060b9d3ee7e19 (diff) |
feat(preview): hover links + ui upgrade
Diffstat (limited to 'util/processOrg.tsx')
-rw-r--r-- | util/processOrg.tsx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/util/processOrg.tsx b/util/processOrg.tsx new file mode 100644 index 0000000..df6007e --- /dev/null +++ b/util/processOrg.tsx @@ -0,0 +1,46 @@ +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' + +import { PreviewLink } from '../components/Sidebar/Link' +import { NodeById } from '../pages' +import React from 'react' + +export interface ProcessedOrgProps { + nodeById: NodeById + previewNode: any + setPreviewNode: any + getText: any + previewText: any +} + +export const ProcessedOrg = (props: ProcessedOrgProps) => { + const { nodeById, previewNode, setPreviewNode, getText, previewText } = props + console.log(previewText) + const processor = unified() + .use(uniorgParse) + .use(uniorg2rehype) + .use(katex) + .use(rehype2react, { + createElement: React.createElement, + // eslint-disable-next-line react/display-name + components: { + a: ({ props, children, href }) => ( + <PreviewLink + getText={getText} + nodeById={nodeById} + previewNode={previewNode} + setPreviewNode={setPreviewNode} + {...{ children, href }} + /> + ), + }, + }) + + return <div>{processor.processSync(previewText).result}</div> +} |