1
- import unified from 'unified'
1
+ import { unified } from 'unified'
2
2
//import createStream from 'unified-stream'
3
3
import uniorgParse from 'uniorg-parse'
4
4
import uniorg2rehype from 'uniorg-rehype'
@@ -28,7 +28,7 @@ import remarkRehype from 'remark-rehype'
28
28
29
29
import { PreviewLink } from '../components/Sidebar/Link'
30
30
import { LinksByNodeId , NodeByCite , NodeById } from '../pages'
31
- import React , { createContext , ReactNode , useMemo } from 'react'
31
+ import React , { createContext , ReactNode , useEffect , useMemo , useState } from 'react'
32
32
import { OrgImage } from '../components/Sidebar/OrgImage'
33
33
import { Section } from '../components/Sidebar/Section'
34
34
import { NoteContext } from './NoteContext'
@@ -38,6 +38,7 @@ import { OrgRoamLink, OrgRoamNode } from '../api'
38
38
import { toString } from 'hast-util-to-string'
39
39
import { Box , chakra } from '@chakra-ui/react'
40
40
import { normalizeLinkEnds } from './normalizeLinkEnds'
41
+ import * as prod from 'react/jsx-runtime'
41
42
42
43
export interface ProcessedOrgProps {
43
44
nodeById : NodeById
@@ -72,13 +73,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
72
73
useInheritance,
73
74
} = props
74
75
75
- if ( ! previewNode || ! linksByNodeId ) {
76
- return null
77
- }
78
-
79
76
const orgProcessor = unified ( )
80
77
. use ( uniorgParse )
81
- . data ( 'settings' , { fragment : true } )
82
78
. use ( extractKeywords )
83
79
. use ( attachments , {
84
80
idDir : attachDir || undefined ,
@@ -127,11 +123,11 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
127
123
// .use(highlight)
128
124
129
125
const isMarkdown = previewNode ?. file ?. slice ( - 3 ) === '.md'
130
- const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
126
+ // const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
131
127
132
128
const processor = useMemo (
133
129
( ) =>
134
- baseProcessor
130
+ orgProcessor
135
131
. use ( katex , {
136
132
trust : ( context ) => [ '\\htmlId' , '\\href' ] . includes ( context . command ) ,
137
133
macros : {
@@ -142,9 +138,12 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
142
138
...macros ,
143
139
} ,
144
140
} )
141
+ // @ts -ignore
145
142
. use ( rehype2react , {
143
+ Fragment : prod . Fragment ,
144
+ jsx : prod . jsx ,
145
+ jsxs : prod . jsxs ,
146
146
createElement : React . createElement ,
147
- // eslint-disable-next-line react/display-name
148
147
components : {
149
148
a : ( { children, href } ) => {
150
149
return (
@@ -167,8 +166,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
167
166
</ PreviewLink >
168
167
)
169
168
} ,
170
- img : ( { src } ) => {
171
- return < OrgImage src = { src as string } file = { previewNode ?. file } />
169
+ img : ( org ) => {
170
+ return < OrgImage org = { org } file = { previewNode ?. file } />
172
171
} ,
173
172
section : ( { children, className } ) => {
174
173
if ( className && ( className as string ) . slice ( - 1 ) === `${ previewNode . level } ` ) {
@@ -220,6 +219,10 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
220
219
)
221
220
222
221
const text = useMemo ( ( ) => processor . processSync ( previewText ) . result , [ previewText ] )
222
+ if ( ! previewNode || ! linksByNodeId ) {
223
+ return null
224
+ }
225
+
223
226
return (
224
227
< NoteContext . Provider value = { { collapse, outline } } > { text as ReactNode } </ NoteContext . Provider >
225
228
)
0 commit comments