From cef72dca61ad8e65e2e81efbd37127cfc571e0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 24 Oct 2023 14:00:57 +0200 Subject: [PATCH] Start marks and fix h3 --- src/components/DocumentView/Block.tsx | 5 +-- src/components/DocumentView/Heading.tsx | 2 +- src/components/DocumentView/Text.tsx | 43 +++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/components/DocumentView/Block.tsx b/src/components/DocumentView/Block.tsx index 3e8adcb21..ed9cb6dd3 100644 --- a/src/components/DocumentView/Block.tsx +++ b/src/components/DocumentView/Block.tsx @@ -5,6 +5,7 @@ import { ListOrdered } from './ListOrdered'; import { ListUnordered } from './ListUnordered'; import { ListItem } from './ListItem'; import { CodeBlock } from './CodeBlock'; +import clsx from 'clsx'; export interface BlockProps { block: T; @@ -12,7 +13,7 @@ export interface BlockProps { } export function Block(props: BlockProps) { - const { block } = props; + const { block, style } = props; switch (block.type) { case 'paragraph': @@ -30,6 +31,6 @@ export function Block(props: BlockProps) { case 'code': return ; default: - return
Unsupported block {block.type}
; + return
Unsupported block {block.type}
; } } diff --git a/src/components/DocumentView/Heading.tsx b/src/components/DocumentView/Heading.tsx index f5cf0b589..e3c85eef4 100644 --- a/src/components/DocumentView/Heading.tsx +++ b/src/components/DocumentView/Heading.tsx @@ -25,6 +25,6 @@ const STYLES = { }, 'heading-3': { tag: 'h4', - className: ['text-3xl', 'font-semibold'], + className: ['text-base', 'font-semibold'], }, }; diff --git a/src/components/DocumentView/Text.tsx b/src/components/DocumentView/Text.tsx index 552fde952..60625b748 100644 --- a/src/components/DocumentView/Text.tsx +++ b/src/components/DocumentView/Text.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx'; import React from 'react'; export function Text(props: { text: any }) { @@ -6,9 +7,47 @@ export function Text(props: { text: any }) { return ( <> {text.leaves.map((leaf, index) => { - // TODO: marks - return {leaf.text}; + return leaf.marks.reduce((children, mark) => { + const Mark = MARK_STYLES[mark.type]; + + if (!Mark) { + return children; + } + + return ( + + {children} + + ); + }, leaf.text); })} ); } + +const MARK_STYLES = { + bold: Bold, + italic: Italic, + code: Code, +}; + +interface MarkedLeafProps { + mark: any; + children: React.ReactNode; +} + +function Bold(props: MarkedLeafProps) { + return {props.children}; +} + +function Italic(props: MarkedLeafProps) { + return {props.children}; +} + +function Code(props: MarkedLeafProps) { + return ( + + {props.children} + + ); +}