summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/processOrg.tsx121
-rw-r--r--util/uniorg.tsx10
-rw-r--r--util/variablesContext.tsx12
3 files changed, 99 insertions, 44 deletions
diff --git a/util/processOrg.tsx b/util/processOrg.tsx
index 26d9377..fa135a1 100644
--- a/util/processOrg.tsx
+++ b/util/processOrg.tsx
@@ -33,6 +33,10 @@ import { Section } from '../components/Sidebar/Section'
import { NoteContext } from './NoteContext'
import { OrgRoamLink, OrgRoamNode } from '../api'
+// @ts-expect-error non-ESM unified means no types
+import { toString } from 'hast-util-to-string'
+import { Box, chakra } from '@chakra-ui/react'
+
export interface ProcessedOrgProps {
nodeById: NodeById
previewNode: OrgRoamNode
@@ -44,6 +48,8 @@ export interface ProcessedOrgProps {
outline: boolean
collapse: boolean
linksByNodeId: LinksByNodeId
+ macros: { [key: string]: string } | {}
+ attachDir: string
}
export const ProcessedOrg = (props: ProcessedOrgProps) => {
@@ -58,9 +64,10 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
outline,
collapse,
linksByNodeId,
+ macros,
+ attachDir,
} = props
- console.log(linksByNodeId)
- console.log(previewNode)
+
if (!previewNode || !linksByNodeId) {
return null
}
@@ -68,7 +75,9 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
const orgProcessor = unified()
.use(uniorgParse)
.use(extractKeywords)
- .use(attachments)
+ .use(attachments, {
+ idDir: attachDir || undefined,
+ })
.use(uniorgSlug)
.use(uniorg2rehype, { useSections: true })
@@ -85,8 +94,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
const linkEntries = Object.entries(nodesInNote)
const wikiLinkResolver = (wikiLink: string): string[] => {
const entry = linkEntries.find((idNodeArray) => {
- console.log(idNodeArray)
- console.log(wikiLink)
return idNodeArray?.[1]?.title === wikiLink
})
const id = entry?.[0] ?? ''
@@ -94,7 +101,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
}
const wikiLinkProcessor = (wikiLink: string): string => {
- console.log(wikiLink)
return `id:${wikiLink}`
}
@@ -117,43 +123,77 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
const isMarkdown = previewNode?.file?.slice(-3) === '.md'
const baseProcessor = isMarkdown ? mdProcessor : orgProcessor
+ console.log(macros)
const processor = useMemo(
() =>
- baseProcessor.use(katex).use(rehype2react, {
- createElement: React.createElement,
- // eslint-disable-next-line react/display-name
- components: {
- a: ({ children, href }) => {
- return (
- <PreviewLink
- nodeByCite={nodeByCite}
- setSidebarHighlightedNode={setSidebarHighlightedNode}
- href={`${href as string}`}
- nodeById={nodeById}
- linksByNodeId={linksByNodeId}
- setPreviewNode={setPreviewNode}
- openContextMenu={openContextMenu}
- outline={outline}
- previewNode={previewNode}
- isWiki={isMarkdown}
- >
- {children}
- </PreviewLink>
- )
+ baseProcessor
+ .use(katex, {
+ trust: (context) => ['\\htmlId', '\\href'].includes(context.command),
+ macros: {
+ '\\eqref': '\\href{###1}{(\\text{#1})}',
+ '\\ref': '\\href{###1}{\\text{#1}}',
+ '\\label': '\\htmlId{#1}{}',
+ // '\\weird': '\\textbf{#1}',
+ ...macros,
},
- img: ({ src }) => {
- return <OrgImage src={src as string} file={previewNode?.file} />
- },
- section: ({ children, className }) => (
- <Section {...{ outline, collapse }} className={className as string}>
- {children}
- </Section>
- ),
- p: ({ children }) => {
- return <p lang="en">{children as ReactNode}</p>
+ })
+ .use(rehype2react, {
+ createElement: React.createElement,
+ // eslint-disable-next-line react/display-name
+ components: {
+ a: ({ children, href }) => {
+ return (
+ <PreviewLink
+ nodeByCite={nodeByCite}
+ setSidebarHighlightedNode={setSidebarHighlightedNode}
+ href={`${href as string}`}
+ nodeById={nodeById}
+ linksByNodeId={linksByNodeId}
+ setPreviewNode={setPreviewNode}
+ openContextMenu={openContextMenu}
+ outline={outline}
+ previewNode={previewNode}
+ isWiki={isMarkdown}
+ macros={macros}
+ attachDir={attachDir}
+ >
+ {children}
+ </PreviewLink>
+ )
+ },
+ img: ({ src }) => {
+ return <OrgImage src={src as string} file={previewNode?.file} />
+ },
+ section: ({ children, className }) => {
+ if (className && (className as string).slice(-1) === `${previewNode.level}`) {
+ return <Box>{(children as React.ReactElement[]).slice(1)}</Box>
+ }
+ return (
+ <Section {...{ outline, collapse }} className={className as string}>
+ {children}
+ </Section>
+ )
+ },
+ blockquote: ({ children }) => (
+ <chakra.blockquote
+ color="gray.800"
+ bgColor="gray.300"
+ pt={4}
+ pb={2}
+ mb={4}
+ mt={3}
+ pl={4}
+ borderLeftWidth={4}
+ borderLeftColor="gray.700"
+ >
+ {children as React.ReactElement[]}
+ </chakra.blockquote>
+ ),
+ p: ({ children }) => {
+ return <p lang="en">{children as ReactNode}</p>
+ },
},
- },
- }),
+ }),
[previewNode?.id],
)
@@ -162,6 +202,3 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
<NoteContext.Provider value={{ collapse, outline }}>{text as ReactNode}</NoteContext.Provider>
)
}
-function useCallBack(arg0: () => unified.Processor<unified.Settings>) {
- throw new Error('Function not implemented.')
-}
diff --git a/util/uniorg.tsx b/util/uniorg.tsx
index 7ffd3b8..6580b9c 100644
--- a/util/uniorg.tsx
+++ b/util/uniorg.tsx
@@ -13,6 +13,8 @@ export interface UniOrgProps {
outline: boolean
collapse: boolean
linksByNodeId: LinksByNodeId
+ macros?: { [key: string]: string }
+ attachDir: string
}
export const UniOrg = (props: UniOrgProps) => {
@@ -26,13 +28,15 @@ export const UniOrg = (props: UniOrgProps) => {
outline,
collapse,
linksByNodeId,
+ macros,
+ attachDir,
} = props
const [previewText, setPreviewText] = useState('')
- const file = encodeURIComponent(encodeURIComponent(previewNode.file))
+ const id = encodeURIComponent(encodeURIComponent(previewNode.id))
useEffect(() => {
- fetch(`http://localhost:35901/file/${file}`)
+ fetch(`http://localhost:35901/node/${id}`)
.then((res) => {
return res.text()
})
@@ -67,7 +71,9 @@ export const UniOrg = (props: UniOrgProps) => {
outline,
collapse,
linksByNodeId,
+ attachDir,
}}
+ macros={macros || {}}
/>
)}
</>
diff --git a/util/variablesContext.tsx b/util/variablesContext.tsx
new file mode 100644
index 0000000..5fd34b8
--- /dev/null
+++ b/util/variablesContext.tsx
@@ -0,0 +1,12 @@
+import { createContext } from 'react'
+import { EmacsVariables } from '../pages'
+
+type Theme = [name: string, themeObject: { [color: string]: string }]
+
+const VariablesContext = createContext<EmacsVariables>({
+ subDirs: ['dailies', '.attach'],
+ attachDir: '.attach',
+ roamDir: '~/org',
+ dailyDir: 'dailies',
+})
+export { VariablesContext }