From 78f15c54c2e0d1f61abc9eec4d88ee020b191e95 Mon Sep 17 00:00:00 2001
From: "Thomas F. K. Jorna" <hello@tefkah.com>
Date: Tue, 2 Nov 2021 23:24:07 +0100
Subject: Feat/collapse: add collapsible/toggleable headers and outline layout
 in the preview panel (#139)

* feat(preview): collapsible headings

* feat(preview): collapsible headings

* feat(collapse): change icons for headings

* feat(collapse):

* feat(collapse): use new uniorg and better looks

* feat(collapse): fix typescript errors

* fix(ci): better filter

* feat(collapse): more small adjustments

* feat(collapse): collapse all button

* fix(collapse): fix global css

* fix(cd): remove yarn and add export

* fix(collapse): type-errors

* fix(cd): fix format-all fucking up yml
---
 util/processOrg.tsx | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

(limited to 'util/processOrg.tsx')

diff --git a/util/processOrg.tsx b/util/processOrg.tsx
index 6d3a380..84eb280 100644
--- a/util/processOrg.tsx
+++ b/util/processOrg.tsx
@@ -8,15 +8,16 @@ import attachments from 'uniorg-attach'
 // rehypeHighlight does not have any types
 // add error thing here
 // import highlight from 'rehype-highlight'
-//import sectionParent from '@agentofuser/rehype-section'
 import katex from 'rehype-katex'
 import 'katex/dist/katex.css'
 import rehype2react from 'rehype-react'
 
 import { PreviewLink } from '../components/Sidebar/Link'
 import { NodeByCite, NodeById } from '../pages'
-import React, { useMemo } from 'react'
+import React, { createContext, ReactNode, useMemo } from 'react'
 import { OrgImage } from '../components/Sidebar/OrgImage'
+import { Section } from '../components/Sidebar/Section'
+import { NoteContext } from './NoteContext'
 
 export interface ProcessedOrgProps {
   nodeById: NodeById
@@ -26,6 +27,8 @@ export interface ProcessedOrgProps {
   nodeByCite: NodeByCite
   setSidebarHighlightedNode: any
   openContextMenu: any
+  outline: boolean
+  collapse: boolean
 }
 
 export const ProcessedOrg = (props: ProcessedOrgProps) => {
@@ -37,17 +40,17 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
     nodeByCite,
     previewNode,
     openContextMenu,
+    outline,
+    collapse,
   } = props
 
-  //const section = sectionParent.default
   const processor = unified()
     .use(uniorgParse)
     .use(extractKeywords)
     .use(attachments)
     .use(uniorgSlug)
-    .use(uniorg2rehype)
+    .use(uniorg2rehype, { useSections: true })
     //.data('settings', { fragment: true })
-    //.use(section)
     // .use(highlight)
     .use(katex)
     .use(rehype2react, {
@@ -63,17 +66,28 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
               nodeById={nodeById}
               setPreviewNode={setPreviewNode}
               openContextMenu={openContextMenu}
+              outline={outline}
             >
               {children}
             </PreviewLink>
           )
         },
         img: ({ src }) => {
-          return <OrgImage src={src as string} file={previewNode.file} />
+          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>
         },
       },
     })
 
   const text = useMemo(() => processor.processSync(previewText).result, [previewText])
-  return <>{text}</>
+  return (
+    <NoteContext.Provider value={{ collapse, outline }}>{text as ReactNode}</NoteContext.Provider>
+  )
 }
-- 
cgit v1.2.3

