Skip to content

Commit abdfbbc

Browse files
Fix: Version numbering automatically updates again
We only conditionally replace this _if_ there is a version number in the code block, because this breaks syntax highlighting. This is kind of a cheap hack, and we should really be replacing the strings with version numbers further upstream before they get broken into syntax highlighting chunks, that way we get to keep both working version numbers, as well as syntax highlighting.
1 parent 35b7f12 commit abdfbbc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/components/PreCodeBlock.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,15 @@ export async function PreCodeBlock({ children, ...props }: PreProps) {
7272

7373
const version = await getLatestVersion()
7474
const version_no_v = trimPrefix(version, "v")
75+
let mustReplaceVersions = false
76+
if (codeContent.includes("{CURRENT_VERSION}") || codeContent.includes("{CURRENT_VERSION_NO_V}")) {
77+
mustReplaceVersions = true
78+
}
7579
codeContent = codeContent.replace(/{CURRENT_VERSION}/g, version)
7680
codeContent = codeContent.replace(/{CURRENT_VERSION_NO_V}/g, version_no_v)
81+
if (mustReplaceVersions) {
82+
children = codeContent
83+
}
7784

7885
return (
7986
<div className="relative">

0 commit comments

Comments
 (0)