From c475122f76370718dc5fdcb18006c1921d9a58e8 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sat, 29 Jan 2022 15:31:51 +0100 Subject: feat(preview): remove heading if heading is title --- util/processOrg.tsx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'util/processOrg.tsx') diff --git a/util/processOrg.tsx b/util/processOrg.tsx index e139c41..aa0118d 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 } from '@chakra-ui/react' + export interface ProcessedOrgProps { nodeById: NodeById previewNode: OrgRoamNode @@ -63,6 +67,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { macros, attachDir, } = props + if (!previewNode || !linksByNodeId) { return null } @@ -96,7 +101,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { } const wikiLinkProcessor = (wikiLink: string): string => { - console.log(wikiLink) return `id:${wikiLink}` } @@ -160,11 +164,18 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { img: ({ src }) => { return }, - section: ({ children, className }) => ( -
- {children} -
- ), + section: ({ children, className }) => { + console.log(className) + console.log(previewNode.level) + if (className && (className as string).slice(-1) === `${previewNode.level}`) { + return {(children as React.ReactElement[]).slice(1)} + } + return ( +
+ {children} +
+ ) + }, p: ({ children }) => { return

{children as ReactNode}

}, @@ -178,6 +189,3 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { {text as ReactNode} ) } -function useCallBack(arg0: () => unified.Processor) { - throw new Error('Function not implemented.') -} -- cgit v1.2.3