From c8a7958d05cae3de170b079ab18d01ecafc7c049 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 5227f4263b8..bc27e3356ed 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 ebef8ce7685..7e37a16bc27 100644 --- a/db/model/Gdoc/exampleEnrichedBlocks.ts +++ b/db/model/Gdoc/exampleEnrichedBlocks.ts @@ -125,8 +125,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 dd7dd7990fb..a60bd1f4e79 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 d1a89ff651d..cbb50d10c51 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 = { @@ -368,6 +368,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 6f3b20da71a..b4998618028 100644 --- a/site/gdocs/components/ArticleBlock.tsx +++ b/site/gdocs/components/ArticleBlock.tsx @@ -249,7 +249,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) => (