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 , useEffect , useMemo , useState } from 'react'
31
+ import React , { createContext , ReactNode , useMemo } 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,7 +38,6 @@ 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'
42
41
43
42
export interface ProcessedOrgProps {
44
43
nodeById : NodeById
@@ -73,8 +72,13 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
73
72
useInheritance,
74
73
} = props
75
74
75
+ if ( ! previewNode || ! linksByNodeId ) {
76
+ return null
77
+ }
78
+
76
79
const orgProcessor = unified ( )
77
80
. use ( uniorgParse )
81
+ . data ( 'settings' , { fragment : true } )
78
82
. use ( extractKeywords )
79
83
. use ( attachments , {
80
84
idDir : attachDir || undefined ,
@@ -123,11 +127,11 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
123
127
// .use(highlight)
124
128
125
129
const isMarkdown = previewNode ?. file ?. slice ( - 3 ) === '.md'
126
- // const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
130
+ const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
127
131
128
132
const processor = useMemo (
129
133
( ) =>
130
- orgProcessor
134
+ baseProcessor
131
135
. use ( katex , {
132
136
trust : ( context ) => [ '\\htmlId' , '\\href' ] . includes ( context . command ) ,
133
137
macros : {
@@ -138,12 +142,9 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
138
142
...macros ,
139
143
} ,
140
144
} )
141
- // @ts -ignore
142
145
. 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
147
148
components : {
148
149
a : ( { children, href } ) => {
149
150
return (
@@ -166,8 +167,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
166
167
</ PreviewLink >
167
168
)
168
169
} ,
169
- img : ( org ) => {
170
- return < OrgImage org = { org } file = { previewNode ?. file } />
170
+ img : ( { src } ) => {
171
+ return < OrgImage src = { src as string } file = { previewNode ?. file } />
171
172
} ,
172
173
section : ( { children, className } ) => {
173
174
if ( className && ( className as string ) . slice ( - 1 ) === `${ previewNode . level } ` ) {
@@ -219,10 +220,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
219
220
)
220
221
221
222
const text = useMemo ( ( ) => processor . processSync ( previewText ) . result , [ previewText ] )
222
- if ( ! previewNode || ! linksByNodeId ) {
223
- return null
224
- }
225
-
226
223
return (
227
224
< NoteContext . Provider value = { { collapse, outline } } > { text as ReactNode } </ NoteContext . Provider >
228
225
)
0 commit comments