diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-09-27 13:36:58 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-09-27 13:36:58 +0200 |
commit | ec6f3e51bb7f33594c7d0151fc3bf1f09db4115a (patch) | |
tree | af8925f3a75c6b5454ac5005a4263c2446e0d351 /pages | |
parent | cb29db132f79f9d35b323ae12524137cf5985018 (diff) |
feat: get org text from emacs
Diffstat (limited to 'pages')
-rw-r--r-- | pages/index.tsx | 14 | ||||
-rw-r--r-- | pages/uniorg.tsx | 25 |
2 files changed, 39 insertions, 0 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index c7713ed..fa15758 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -84,6 +84,11 @@ export function GraphPage() { const [emacsNodeId, setEmacsNodeId] = useState<string | null>(null) const [behavior, setBehavior] = usePersistantState('behavior', initialBehavior) const [mouse, setMouse] = usePersistantState('mouse', initialMouse) + const [orgText, setOrgText] = useState('') + + useEffect(() => { + console.log(orgText) + }, [orgText]) const nodeByIdRef = useRef<NodeById>({}) const linksByNodeIdRef = useRef<LinksByNodeId>({}) @@ -358,6 +363,8 @@ export function GraphPage() { switch (message.type) { case 'graphdata': return updateGraphData(message.data) + case 'orgText': + return setOrgText(message.data) case 'theme': return setEmacsTheme(message.data) case 'command': @@ -518,6 +525,11 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { const sendMessageToEmacs = (command: string, data: {}) => { webSocket.send(JSON.stringify({ command: command, data: data })) } + + const getOrgText = (node: OrgRoamNode) => { + sendMessageToEmacs('getText', { id: node.id }) + } + const openNodeInEmacs = (node: OrgRoamNode) => { sendMessageToEmacs('open', { id: node.id }) } @@ -947,6 +959,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { () => getThemeColor(visuals.labelTextColor), [visuals.labelTextColor, emacsTheme], ) + const labelBackgroundColor = useMemo( () => getThemeColor(visuals.labelBackgroundColor), [visuals.labelBackgroundColor, emacsTheme], @@ -1182,6 +1195,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { openNodeInEmacs={openNodeInEmacs} deleteNodeInEmacs={deleteNodeInEmacs} createNodeInEmacs={createNodeInEmacs} + getOrgText={getOrgText} /> )} {threeDim ? ( diff --git a/pages/uniorg.tsx b/pages/uniorg.tsx new file mode 100644 index 0000000..65786c9 --- /dev/null +++ b/pages/uniorg.tsx @@ -0,0 +1,25 @@ +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 rehype2react from 'rehype-react' +import React from 'react' + +export interface uniorgProps { + orgText: string +} + +const UniOrg = (props: uniorgProps) => { + const { orgText } = props + const processor = unified() + .use(uniorgParse) + .use(uniorg2rehype) + .use(katex) + .use(rehype2react, { createElement: React.createElement }) + + return <div>processor.processSync(orgText)</div> +} + +export default UniOrg |