Skip to content

Commit 009e0f8

Browse files
authored
Revert "Revert "support org-html""
1 parent 5bd43fc commit 009e0f8

12 files changed

+907
-211
lines changed

components/Search/SearchContent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const SearchContent: React.FC<{
6464
autoHeight={true}
6565
autoHide={true}
6666
autoHeightMax={500}
67-
renderThumbVertical={({ style, ...props }) => (
67+
renderThumbVertical={({ style, ...props }: { style: React.CSSProperties }) => (
6868
<Box
6969
style={{
7070
...style,

components/Sidebar/Link.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export const PreviewLink = (props: LinkProps) => {
270270
autoHeight
271271
autoHeightMax={300}
272272
autoHide
273-
renderThumbVertical={({ style, ...props }) => (
273+
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
274274
<Box
275275
style={{
276276
...style,

components/Sidebar/OrgImage.tsx

+49-18
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,34 @@ import path from 'path'
55
import { Container } from '@chakra-ui/react'
66
//import '../../../public/placeholder.png'
77

8+
const convertToNextImageAttr = (value: string | number | undefined): number | undefined => {
9+
if (value === undefined) {
10+
return undefined
11+
}
12+
13+
if (typeof value === 'number' || !isNaN(Number(value))) {
14+
return Number(value)
15+
}
16+
17+
if (value.endsWith('px')) {
18+
return Number(value.replace('px', ''))
19+
}
20+
21+
return undefined
22+
}
23+
824
export interface OrgImageProps {
9-
src: string
25+
org: React.ClassAttributes<HTMLImageElement> & React.ImgHTMLAttributes<HTMLImageElement>
1026
file: string
1127
}
1228

1329
export const OrgImage = (props: OrgImageProps) => {
14-
const { src, file } = props
15-
16-
// const [image, setImage] = useState<any>(null)
30+
const { org, file } = props
31+
const { src, ...attr } = org
1732

18-
/* )
19-
* .then((res) => res.blob())
20-
* .then((res) => setImage(res))
21-
* .catch((e) => {
22-
* setImage(null)
23-
* console.error(e)
24-
* })
25-
}, [fullPath]) */
33+
if (!src) {
34+
return null
35+
}
2636

2737
const dumbLoader = ({ src, width, quality }: { [key: string]: string | number }) => {
2838
return `${src}`
@@ -31,17 +41,38 @@ export const OrgImage = (props: OrgImageProps) => {
3141
return `img/${src}`
3242
}
3343

34-
if (src.startsWith("file:")) {
44+
if (src?.startsWith("file:")) {
3545
const srcName = src.replace(/file:/g, './')
46+
const attrWidth = convertToNextImageAttr(attr.width)
47+
const attrHeight = convertToNextImageAttr(attr.height)
48+
const layout = attrWidth || attrHeight ? undefined : "responsive"
3649
return (
37-
<Image layout="responsive" loader={dumbLoader} src={srcName} alt="" />
50+
<Image
51+
{...attr}
52+
layout={layout}
53+
loader={dumbLoader}
54+
src={srcName}
55+
width={attrWidth}
56+
height={attrHeight}
57+
alt={attr.alt ?? "Wow, an image."}
58+
/>
3859
)
3960
}
4061

4162
if (/(http)?.*/g.test(src.replace(/(http)?.*/g, '$1'))) {
42-
console.log(src.replace(/(http)?.*/g, '$1'))
63+
const attrWidth = convertToNextImageAttr(attr.width)
64+
const attrHeight = convertToNextImageAttr(attr.height)
65+
const layout = attrWidth || attrHeight ? undefined : "responsive"
4366
return (
44-
<Image layout="responsive" loader={dumbLoader} src={src} alt="" />
67+
<Image
68+
{...attr}
69+
layout={layout}
70+
loader={dumbLoader}
71+
src={src}
72+
width={attrWidth}
73+
height={attrHeight}
74+
alt={attr.alt ?? "Wow, an image."}
75+
/>
4576
)
4677
}
4778

@@ -51,10 +82,10 @@ export const OrgImage = (props: OrgImageProps) => {
5182
const fullPath =
5283
path.isAbsolute(srcName) || srcName.slice(0, 1) === '~' ? srcName : path.join(dir, srcName)
5384
const encodedPath = encodeURIComponent(encodeURIComponent(fullPath))
54-
85+
console.log(srcName, " is ", "local")
5586
return (
5687
<Container my={4} position="relative">
57-
<img alt="Wow, an image." src={fullPath} />
88+
<img {...attr} alt={attr.alt ?? "Wow, an image."} src={fullPath} />
5889
</Container>
5990
)
6091
}

components/Sidebar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const Sidebar = (props: SidebarProps) => {
193193
//autoHeight
194194
//autoHeightMax={600}
195195
autoHide
196-
renderThumbVertical={({ style, ...props }) => (
196+
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
197197
<Box
198198
style={{
199199
...style,

components/Tweaks/DropDownMenu.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export const DropDownMenu = (props: DropDownMenuProps) => {
1818
<Portal>
1919
{' '}
2020
<MenuList zIndex="popover">
21-
{textArray.map((option, i) => {
22-
;<MenuItem onClick={onClickArray[i]}> {option} </MenuItem>
23-
})}
21+
{textArray.map((option, i) => (
22+
<MenuItem key={i} onClick={onClickArray[i]}> {option} </MenuItem>
23+
))}
2424
</MenuList>
2525
</Portal>
2626
</Menu>

components/Tweaks/Visual/ColorMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ColorMenu = (props: ColorMenuProps) => {
2929
const { label, colorList, value, visValue, setVisuals, noEmpty } = props
3030

3131
const clickCallback = useCallback(
32-
(color) =>
32+
(color: any) =>
3333
setVisuals((curr: typeof initialVisuals) => {
3434
return {
3535
...curr,

components/Tweaks/Visual/ThemeSelect.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ThemeSelect = () => {
2929
color="black"
3030
rightIcon={<ChevronDownIcon />}
3131
>
32-
{emacsTheme[0]}
32+
{String(emacsTheme[0])}
3333
</MenuButton>
3434
<MenuList minW={10} zIndex="popover" bgColor="gray.200">
3535
<MenuItem

components/Tweaks/Visual/VisualsPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const VisualsPanel = (props: VisualsPanelProps) => {
4545
setHighlightColor,
4646
threeDim,
4747
} = props
48-
const setVisualsCallback = useCallback((val) => setVisuals(val), [])
48+
const setVisualsCallback = useCallback((val: any) => setVisuals(val), [])
4949
return (
5050
<VStack justifyContent="flex-start" align="stretch">
5151
<ThemeSelect />

components/Tweaks/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const Tweaks = (props: TweakProps) => {
155155
autoHeight
156156
autoHeightMax={0.85 * globalThis.innerHeight}
157157
autoHide
158-
renderThumbVertical={({ style, ...props }) => (
158+
renderThumbVertical={({ style, ...props }: { style: any, [key: string]: any }) => (
159159
<Box
160160
{...props}
161161
style={{

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"react-resizable": "^3.0.4",
4747
"react-spring": "^9.2.4",
4848
"reconnecting-websocket": "^4.4.0",
49-
"rehype": "^11.0.0",
49+
"rehype": "^13.0.0",
5050
"rehype-highlight": "^4.1.0",
51-
"rehype-katex": "^5.0.0",
52-
"rehype-react": "^6.2.1",
51+
"rehype-katex": "^7.0.0",
52+
"rehype-react": "^8.0.0",
5353
"remark-extract-frontmatter": "^3.2.0",
5454
"remark-frontmatter": "^3.0.0",
5555
"remark-gfm": "^1.0.0",
@@ -64,12 +64,12 @@
6464
"three-spritetext": "^1.6.2",
6565
"through": "^2.3.8",
6666
"to-vfile": "^6.1.0",
67-
"unified": "^9.2.2",
68-
"uniorg": "^0.4.0",
67+
"unified": "^11.0.4",
68+
"uniorg": "^1.1.1",
6969
"uniorg-attach": "^0.4.5",
7070
"uniorg-extract-keywords": "^0.4.5",
71-
"uniorg-parse": "^0.4.5",
72-
"uniorg-rehype": "^0.4.8",
71+
"uniorg-parse": "^2.1.1",
72+
"uniorg-rehype": "^1.1.1",
7373
"uniorg-slug": "^0.4.8",
7474
"unist-util-find-after": "^3.0.0",
7575
"unist-util-is": "^4.1.0",
@@ -83,7 +83,8 @@
8383
"@types/d3-interpolate": "^3.0.1",
8484
"@types/mapbox__rehype-prism": "^0.8.3",
8585
"@types/node": "20.12.11",
86-
"@types/react": "17.0.14",
86+
"@types/react": "^18.2.66",
87+
"@types/react-dom": "^18.2.22",
8788
"eslint": "7.31.0",
8889
"eslint-config-next": "^14.2.3",
8990
"next-compose-plugins": "^2.2.1",

util/processOrg.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unified from 'unified'
1+
import { unified } from 'unified'
22
//import createStream from 'unified-stream'
33
import uniorgParse from 'uniorg-parse'
44
import uniorg2rehype from 'uniorg-rehype'
@@ -28,7 +28,7 @@ import remarkRehype from 'remark-rehype'
2828

2929
import { PreviewLink } from '../components/Sidebar/Link'
3030
import { LinksByNodeId, NodeByCite, NodeById } from '../pages'
31-
import React, { createContext, ReactNode, useMemo } from 'react'
31+
import React, { createContext, ReactNode, useEffect, useMemo, useState } from 'react'
3232
import { OrgImage } from '../components/Sidebar/OrgImage'
3333
import { Section } from '../components/Sidebar/Section'
3434
import { NoteContext } from './NoteContext'
@@ -38,6 +38,7 @@ import { OrgRoamLink, OrgRoamNode } from '../api'
3838
import { toString } from 'hast-util-to-string'
3939
import { Box, chakra } from '@chakra-ui/react'
4040
import { normalizeLinkEnds } from './normalizeLinkEnds'
41+
import * as prod from 'react/jsx-runtime'
4142

4243
export interface ProcessedOrgProps {
4344
nodeById: NodeById
@@ -72,13 +73,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
7273
useInheritance,
7374
} = props
7475

75-
if (!previewNode || !linksByNodeId) {
76-
return null
77-
}
78-
7976
const orgProcessor = unified()
8077
.use(uniorgParse)
81-
.data('settings', { fragment: true })
8278
.use(extractKeywords)
8379
.use(attachments, {
8480
idDir: attachDir || undefined,
@@ -127,11 +123,11 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
127123
// .use(highlight)
128124

129125
const isMarkdown = previewNode?.file?.slice(-3) === '.md'
130-
const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
126+
// const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
131127

132128
const processor = useMemo(
133129
() =>
134-
baseProcessor
130+
orgProcessor
135131
.use(katex, {
136132
trust: (context) => ['\\htmlId', '\\href'].includes(context.command),
137133
macros: {
@@ -142,9 +138,12 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
142138
...macros,
143139
},
144140
})
141+
// @ts-ignore
145142
.use(rehype2react, {
143+
Fragment: prod.Fragment,
144+
jsx: prod.jsx,
145+
jsxs: prod.jsxs,
146146
createElement: React.createElement,
147-
// eslint-disable-next-line react/display-name
148147
components: {
149148
a: ({ children, href }) => {
150149
return (
@@ -167,8 +166,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
167166
</PreviewLink>
168167
)
169168
},
170-
img: ({ src }) => {
171-
return <OrgImage src={src as string} file={previewNode?.file} />
169+
img: (org) => {
170+
return <OrgImage org={org} file={previewNode?.file} />
172171
},
173172
section: ({ children, className }) => {
174173
if (className && (className as string).slice(-1) === `${previewNode.level}`) {
@@ -220,6 +219,10 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
220219
)
221220

222221
const text = useMemo(() => processor.processSync(previewText).result, [previewText])
222+
if (!previewNode || !linksByNodeId) {
223+
return null
224+
}
225+
223226
return (
224227
<NoteContext.Provider value={{ collapse, outline }}>{text as ReactNode}</NoteContext.Provider>
225228
)

0 commit comments

Comments
 (0)