From 3f0dbdfb01ac0cbec16dcabbd9bac5178e88614f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ra=C4=8D=C3=A1k?= Date: Fri, 13 Dec 2024 15:52:35 +0100 Subject: [PATCH] Fix type of EnrichedBlockCode --- db/model/Gdoc/enrichedToMarkdown.ts | 4 +++- db/model/Gdoc/enrichedToRaw.ts | 5 ++++- db/model/Gdoc/exampleEnrichedBlocks.ts | 8 ++++++-- db/model/Gdoc/rawToEnriched.ts | 8 ++++++-- .../types/src/gdocTypes/ArchieMlComponents.ts | 3 ++- site/gdocs/components/ArticleBlock.tsx | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/db/model/Gdoc/enrichedToMarkdown.ts b/db/model/Gdoc/enrichedToMarkdown.ts index a186f859300..2556f74ef2b 100644 --- a/db/model/Gdoc/enrichedToMarkdown.ts +++ b/db/model/Gdoc/enrichedToMarkdown.ts @@ -129,7 +129,9 @@ ${items} ) .with({ type: "code" }, (b): string | undefined => { return ( - "```\n" + b.text.map((text) => text.value).join("\n") + "\n```" + "```\n" + + b.text.map((text) => text.value.text).join("\n") + + "\n```" ) }) .with({ type: "donors" }, (_): string | undefined => diff --git a/db/model/Gdoc/enrichedToRaw.ts b/db/model/Gdoc/enrichedToRaw.ts index db819e092e4..51d771941d8 100644 --- a/db/model/Gdoc/enrichedToRaw.ts +++ b/db/model/Gdoc/enrichedToRaw.ts @@ -127,7 +127,10 @@ export function enrichedBlockToRawBlock( { type: "code" }, (b): RawBlockCode => ({ type: b.type, - value: b.text, + value: b.text.map((text) => ({ + type: "text", + value: text.value.text, + })), }) ) .with( diff --git a/db/model/Gdoc/exampleEnrichedBlocks.ts b/db/model/Gdoc/exampleEnrichedBlocks.ts index f6189a6cc4b..01a45f6fd0a 100644 --- a/db/model/Gdoc/exampleEnrichedBlocks.ts +++ b/db/model/Gdoc/exampleEnrichedBlocks.ts @@ -96,8 +96,12 @@ export const enrichedBlockExamples: Record< type: "code", text: [ { - type: "text", - value: '', + type: "simple-text", + value: { + spanType: "span-simple-text", + text: '', + }, + parseErrors: [], }, ], parseErrors: [], diff --git a/db/model/Gdoc/rawToEnriched.ts b/db/model/Gdoc/rawToEnriched.ts index 5cb8230ea2a..bae5d4e3b7f 100644 --- a/db/model/Gdoc/rawToEnriched.ts +++ b/db/model/Gdoc/rawToEnriched.ts @@ -500,8 +500,12 @@ const parseCode = (raw: RawBlockCode): EnrichedBlockCode => { return { type: "code", text: raw.value.map((text) => ({ - type: "text", - value: toAsciiQuotes(text.value), + type: "simple-text", + value: { + spanType: "span-simple-text", + text: toAsciiQuotes(text.value), + }, + parseErrors: [], })), parseErrors: [], } diff --git a/packages/@ourworldindata/types/src/gdocTypes/ArchieMlComponents.ts b/packages/@ourworldindata/types/src/gdocTypes/ArchieMlComponents.ts index 90ea4c7c8ef..90aa20c4299 100644 --- a/packages/@ourworldindata/types/src/gdocTypes/ArchieMlComponents.ts +++ b/packages/@ourworldindata/types/src/gdocTypes/ArchieMlComponents.ts @@ -93,7 +93,7 @@ export type RawBlockCode = { export type EnrichedBlockCode = { type: "code" - text: RawBlockText[] + text: EnrichedBlockSimpleText[] } & EnrichedBlockWithParseErrors export type RawBlockDonorList = { @@ -366,6 +366,7 @@ export type EnrichedBlockSimpleText = { type: "simple-text" value: SpanSimpleText } & EnrichedBlockWithParseErrors + export type RawBlockHtml = { type: "html" value: string diff --git a/site/gdocs/components/ArticleBlock.tsx b/site/gdocs/components/ArticleBlock.tsx index c644ec1c3cc..c0471598197 100644 --- a/site/gdocs/components/ArticleBlock.tsx +++ b/site/gdocs/components/ArticleBlock.tsx @@ -248,7 +248,7 @@ export default function ArticleBlock({ .with({ type: "code" }, (block) => ( text.value).join("\n")} + code={block.text.map((text) => text.value.text).join("\n")} /> )) .with({ type: "donors" }, (_block) => (