From 96482ca99cba602632b29555c1dc5a253e3e3bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Fincato?= Date: Mon, 18 Apr 2022 14:55:03 +0200 Subject: [PATCH] groups: correctly display blockquote content in full as of now, a blockquote would discard any other content after a URL and would put it on a new line. eg '> some text https://urbit.org this is urbit' would be rendered as ``` > some text https://urbit.org this is urbit ``` this commit joins all content inside of a blockquote as one block. --- .../components/Graph/GraphContent.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx index 9aa6eda33..c2c1ace43 100644 --- a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx +++ b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx @@ -218,7 +218,7 @@ function getChildren(node: T): AstContent[] { } export function asParent(node: T): Parent | undefined { - return ['paragraph', 'heading', 'list', 'listItem', 'table'].includes( + return ['paragraph', 'heading', 'list', 'listItem', 'table', 'blockquote'].includes( node.type ) ? (node as Parent) @@ -242,6 +242,20 @@ function stitchMerge(a: Root, b: Root) { children: [...aChildren.slice(0, -1), mergedPara, ...bChildren.slice(1)] }; } + + // example of joining blockquote made of several types + // eg: text, url, text + // this might be a bit naive as we check only for paragraphs + if (lastType === 'blockquote' && bChildren[0]?.type === 'paragraph') { + let grandChildren = getChildren(last(aChildren)); + grandChildren[0].children.push(getChildren(last(bChildren))[0]); + + return { + ...last(aChildren), + children: grandChildren, + }; + } + return { ...a, children: [...aChildren, ...bChildren] }; } @@ -260,7 +274,7 @@ function stitchAsts(asts: [StitchMode, GraphAstNode][]) { return _.reduce( asts, ([prevMode, ast], [mode, val]): [StitchMode, GraphAstNode] => { - if (prevMode === 'block') { + if (prevMode === 'block' || prevMode === 'inline') { if (mode === 'inline') { return [mode, stitchInlineAfterBlock(ast, val?.children ?? [])]; }