Skip to content

Commit bfe4b3a

Browse files
zackkatzclaude
andcommitted
fix: Preserve backslash in type links
When linking types like `\GF_Field_Address`, preserve the original format including the leading backslash in the displayed text. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 538d320 commit bfe4b3a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

scripts/generate-hooks.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,17 @@ function linkParameterTypes(outputDir) {
296296
for (const [typeName, url] of Object.entries(typeLinks)) {
297297
// Match `TypeName` or `\TypeName` in parameter tables
298298
// The backticks indicate it's a type in the markdown table
299-
const patterns = [
300-
new RegExp('`\\\\?' + escapeRegExp(typeName) + '`', 'g'),
301-
];
302-
303-
for (const pattern of patterns) {
304-
if (pattern.test(content)) {
305-
// Replace with linked version, preserving the backticks around the link
306-
content = content.replace(pattern, `[\`${typeName}\`](${url})`);
307-
modified = true;
308-
}
299+
// Capture the optional backslash to preserve it in the output
300+
const pattern = new RegExp('`(\\\\?)' + escapeRegExp(typeName) + '`', 'g');
301+
302+
if (pattern.test(content)) {
303+
// Reset lastIndex after test() for replace() to work correctly
304+
pattern.lastIndex = 0;
305+
// Replace with linked version, preserving the original format (with or without backslash)
306+
content = content.replace(pattern, (match, backslash) => {
307+
return `[\`${backslash}${typeName}\`](${url})`;
308+
});
309+
modified = true;
309310
}
310311
}
311312

0 commit comments

Comments
 (0)