Skip to content

Commit 89b565d

Browse files
committed
[Docs Site] Remove docs-tag lines from rendered output in GitHubCode
1 parent b3d8d59 commit 89b565d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/components/GitHubCode.astro

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,20 @@ if (!res.ok) {
3333
throw new Error(`[GitHubCode] Received ${res.status} from Worker.`);
3434
}
3535
36-
let content = await res.text();
36+
const content = await res.text();
37+
let contentLines = content.split("\n");
3738
3839
if (lines) {
3940
const [start, end] = lines;
4041
41-
const contentLines = content.split("\n");
42-
4342
if (contentLines.length < end - 1) {
4443
throw new Error(
4544
`[GitHubCode] End line requested is beyond content length (${contentLines.length}).`,
4645
);
4746
}
4847
49-
content = contentLines.slice(start - 1, end).join("\n");
48+
contentLines = contentLines.slice(start - 1, end);
5049
} else if (tag) {
51-
const contentLines = content.split("\n");
52-
5350
const startTag = contentLines.findIndex((x) =>
5451
x.includes(`<docs-tag name="${tag}">`),
5552
);
@@ -61,8 +58,12 @@ if (lines) {
6158
throw new Error(`[GitHubCode] Unable to find a region using tag "${tag}".`);
6259
}
6360
64-
content = contentLines.slice(startTag + 1, endTag).join("\n");
61+
contentLines = contentLines.slice(startTag + 1, endTag);
6562
}
63+
64+
contentLines = contentLines.filter(
65+
(line) => !/<[\/]?docs-tag name=".*">/.test(line),
66+
);
6667
---
6768

68-
<Code code={content} lang={lang} />
69+
<Code code={contentLines.join("\n")} lang={lang} />

src/content/docs/style-guide/components/github-code.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { GitHubCode } from "~/components";
1818
import { GitHubCode } from "~/components";
1919

2020
<GitHubCode
21-
repo="cloudflare/workers-rs"
22-
file="templates/hello-world/src/lib.rs"
23-
commit="ab3951b5c95329a600a7baa9f9bb1a7a95f1aeaa"
24-
lang="rs"
21+
repo="cloudflare/workflows-starter"
22+
file="src/index.ts"
23+
commit="a844e629ec80968118d4b116d4b26f5dcb107137"
24+
lang="ts"
2525
/>
2626
```
2727

0 commit comments

Comments
 (0)