Skip to content

Commit 28a1de0

Browse files
authored
Merge pull request #11 from ikoamu/support-html-attr
Support html attr
2 parents 518a459 + ad343e1 commit 28a1de0

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

components/Sidebar/Link.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export const PreviewLink = (props: LinkProps) => {
155155
const type = href.replaceAll(/(.*?)\:.*/g, '$1')
156156

157157
const extraNoteStyle = outline ? outlineNoteStyle : viewerNoteStyle
158-
console.log(previewNode)
159158
const getText = () => {
160159
fetch(`notes/${id}`)
161160
.then((res) => {

components/Sidebar/OrgImage.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export const OrgImage = (props: OrgImageProps) => {
8282
const fullPath =
8383
path.isAbsolute(srcName) || srcName.slice(0, 1) === '~' ? srcName : path.join(dir, srcName)
8484
const encodedPath = encodeURIComponent(encodeURIComponent(fullPath))
85-
console.log(srcName, " is ", "local")
8685
return (
8786
<Container my={4} position="relative">
8887
<img {...attr} alt={attr.alt ?? "Wow, an image."} src={fullPath} />

components/Sidebar/Section.tsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Box, Flex, IconButton } from '@chakra-ui/react'
2-
import React, { ReactChild, useContext, useEffect, useState } from 'react'
2+
import React, { FC, PropsWithChildren, ReactChild, useContext, useEffect, useState } from 'react'
33
import { VscCircleFilled, VscCircleOutline } from 'react-icons/vsc'
44
import { ChevronDownIcon, ChevronUpIcon } from '@chakra-ui/icons'
55
import { NoteContext } from '../../util/NoteContext'
66

77
export interface SectionProps {
8-
children: any
98
className: string
109
}
1110

12-
export const Section = (props: SectionProps) => {
11+
export const Section: FC<PropsWithChildren<SectionProps>> = (props) => {
1312
const {
1413
children,
1514
className, // outline
@@ -20,15 +19,28 @@ export const Section = (props: SectionProps) => {
2019
setOpen(!collapse)
2120
}, [collapse])
2221

22+
if (!children) {
23+
return null
24+
}
25+
26+
2327
if (className === 'h0Wrapper headingWrapper') {
2428
return <Box className="preHeadingContent"> {children}</Box>
2529
}
26-
const kids = children as ReactChild[]
30+
31+
if (typeof children === 'string') {
32+
return <Box className="sectionContent">{children}</Box>
33+
}
34+
35+
if (!Array.isArray(children)) {
36+
return <Box className="sectionContent">{children}</Box>
37+
}
38+
2739
return (
2840
<Box className={'sec'}>
2941
<Box display="block">
3042
<Flex className="headingFlex" alignItems="baseline">
31-
{open && kids.length > 0 ? (
43+
{open && children.length > 0 ? (
3244
<>
3345
<IconButton
3446
className="viewerHeadingButton"
@@ -87,10 +99,10 @@ export const Section = (props: SectionProps) => {
8799
/>
88100
</>
89101
)}
90-
{kids[0]}
102+
{children[0]}
91103
</Flex>
92104
</Box>
93-
{open && <Box className="sectionContent">{kids.slice(1)}</Box>}
105+
{open && <Box className="sectionContent">{children?.slice(1)}</Box>}
94106
</Box>
95107
)
96108
}

util/processOrg.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
170170
return <OrgImage org={org} file={previewNode?.file} />
171171
},
172172
section: ({ children, className }) => {
173-
if (className && (className as string).slice(-1) === `${previewNode.level}`) {
174-
return <Box>{(children as React.ReactElement[]).slice(1)}</Box>
173+
if (className && className?.slice(-1) === `${previewNode.level}`) {
174+
return <Box>{children}</Box>
175175
}
176176
return (
177-
<Section {...{ outline, collapse }} className={className as string}>
177+
<Section {...{ outline, collapse }} className={className ?? ""}>
178178
{children}
179179
</Section>
180180
)
@@ -191,7 +191,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
191191
borderLeftWidth={4}
192192
borderLeftColor="gray.700"
193193
>
194-
{children as React.ReactElement[]}
194+
{children}
195195
</chakra.blockquote>
196196
),
197197
p: ({ children }) => {
@@ -207,7 +207,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
207207
color="gray.800"
208208
bgColor="gray.300"
209209
>
210-
{children as any}
210+
{children}
211211
</chakra.code>
212212
}
213213
return children;

0 commit comments

Comments
 (0)