diff --git a/src/components/GitHubCode.astro b/src/components/GitHubCode.astro index 47ef6ab0a93a82d..2ab28e2e992a129 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 ca038adab5fb40f..3e653c7c4650796 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"; ```