Skip to content

Commit

Permalink
Fix type of EnrichedBlockCode
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Dec 17, 2024
1 parent d707a42 commit f21f3ef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion db/model/Gdoc/enrichedToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
5 changes: 4 additions & 1 deletion db/model/Gdoc/enrichedToRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions db/model/Gdoc/exampleEnrichedBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ export const enrichedBlockExamples: Record<
type: "code",
text: [
{
type: "text",
value: '<iframe src="https://ourworldindata.org/grapher/children-per-woman-un?region=Africa&tab=map" loading="lazy" style="width: 100%; height: 600px; border: 0px none;" allow="web-share; clipboard-write"></iframe>',
type: "simple-text",
value: {
spanType: "span-simple-text",
text: '<iframe src="https://ourworldindata.org/grapher/children-per-woman-un?region=Africa&tab=map" loading="lazy" style="width: 100%; height: 600px; border: 0px none;" allow="web-share; clipboard-write"></iframe>',
},
parseErrors: [],
},
],
parseErrors: [],
Expand Down
8 changes: 6 additions & 2 deletions db/model/Gdoc/rawToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type RawBlockCode = {

export type EnrichedBlockCode = {
type: "code"
text: RawBlockText[]
text: EnrichedBlockSimpleText[]
} & EnrichedBlockWithParseErrors

export type RawBlockDonorList = {
Expand Down Expand Up @@ -368,6 +368,7 @@ export type EnrichedBlockSimpleText = {
type: "simple-text"
value: SpanSimpleText
} & EnrichedBlockWithParseErrors

export type RawBlockHtml = {
type: "html"
value: string
Expand Down
2 changes: 1 addition & 1 deletion site/gdocs/components/ArticleBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default function ArticleBlock({
.with({ type: "code" }, (block) => (
<CodeSnippet
className={getLayout("code-snippet", containerType)}
code={block.text.map((text) => text.value).join("\n")}
code={block.text.map((text) => text.value.text).join("\n")}
/>
))
.with({ type: "donors" }, (_block) => (
Expand Down

0 comments on commit f21f3ef

Please sign in to comment.