From 292269467809906d6a852b7702d38a9c0d24d63e Mon Sep 17 00:00:00 2001 From: Patrick O'Sullivan Date: Wed, 7 Feb 2024 13:45:00 -0600 Subject: [PATCH] notebooks: properly handle code blocks Fixes LAND-1404 by making sure we send code blocks as `blocks` in notebook posts. Only handled as blocks in notebook posts, nothing changes for chat posts. Inline and block code still render correctly in chat messages, and now both render correctly in notebook posts. --- ui/src/diary/diary-add-note.tsx | 2 +- ui/src/types/channel.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ui/src/diary/diary-add-note.tsx b/ui/src/diary/diary-add-note.tsx index f27302a52f..9075214c3f 100644 --- a/ui/src/diary/diary-add-note.tsx +++ b/ui/src/diary/diary-add-note.tsx @@ -129,7 +129,7 @@ export default function DiaryAddNote() { const data = JSONToInlines(editor?.getJSON(), false, true); const values = getValues(); - const noteContent = constructStory(data); + const noteContent = constructStory(data, true); const now = Date.now(); const cacheId = { author: window.our, diff --git a/ui/src/types/channel.ts b/ui/src/types/channel.ts index a19e098d6d..631dd0803e 100644 --- a/ui/src/types/channel.ts +++ b/ui/src/types/channel.ts @@ -552,7 +552,10 @@ export const emptyReply: Reply = { }, }; -export function constructStory(data: (Inline | Block)[]): Story { +export function constructStory( + data: (Inline | Block)[], + codeAsBlock?: boolean +): Story { const isBlock = (c: Inline | Block) => [ 'image', @@ -564,6 +567,7 @@ export function constructStory(data: (Inline | Block)[]): Story { 'header', 'rule', 'cite', + codeAsBlock ? 'code' : '', ].some((k) => typeof c !== 'string' && k in c); const postContent: Story = []; let index = 0;