From 89b565db7005f4b8a7ea0d62a89a36cfb749a0f5 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Wed, 4 Dec 2024 16:38:11 +0000 Subject: [PATCH] [Docs Site] Remove docs-tag lines from rendered output in GitHubCode --- src/components/GitHubCode.astro | 17 +++++++++-------- .../docs/style-guide/components/github-code.mdx | 8 ++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/GitHubCode.astro b/src/components/GitHubCode.astro index 47ef6ab0a93a82..2ab28e2e992a12 100644 --- a/src/components/GitHubCode.astro +++ b/src/components/GitHubCode.astro @@ -33,23 +33,20 @@ if (!res.ok) { throw new Error(`[GitHubCode] Received ${res.status} from Worker.`); } -let content = await res.text(); +const content = await res.text(); +let contentLines = content.split("\n"); if (lines) { const [start, end] = lines; - const contentLines = content.split("\n"); - if (contentLines.length < end - 1) { throw new Error( `[GitHubCode] End line requested is beyond content length (${contentLines.length}).`, ); } - content = contentLines.slice(start - 1, end).join("\n"); + contentLines = contentLines.slice(start - 1, end); } else if (tag) { - const contentLines = content.split("\n"); - const startTag = contentLines.findIndex((x) => x.includes(``), ); @@ -61,8 +58,12 @@ if (lines) { throw new Error(`[GitHubCode] Unable to find a region using tag "${tag}".`); } - content = contentLines.slice(startTag + 1, endTag).join("\n"); + contentLines = contentLines.slice(startTag + 1, endTag); } + +contentLines = contentLines.filter( + (line) => !/<[\/]?docs-tag name=".*">/.test(line), +); --- - + diff --git a/src/content/docs/style-guide/components/github-code.mdx b/src/content/docs/style-guide/components/github-code.mdx index ca038adab5fb40..3e653c7c465079 100644 --- a/src/content/docs/style-guide/components/github-code.mdx +++ b/src/content/docs/style-guide/components/github-code.mdx @@ -18,10 +18,10 @@ import { GitHubCode } from "~/components"; import { GitHubCode } from "~/components"; ```