MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / addCrossLinks

Function addCrossLinks

scripts/generate-docs.ts:67–93  ·  view source on GitHub ↗
(text: string, tools: ToolWithAnnotations[])

Source from the content-addressed store, hash-verified

65}
66
67function addCrossLinks(text: string, tools: ToolWithAnnotations[]): string {
68 let result = text;
69
70 // Create a set of all tool names for efficient lookup
71 const toolNames = new Set(tools.map(tool => tool.name));
72
73 // Sort tool names by length (descending) to match longer names first
74 const sortedToolNames = Array.from(toolNames).sort(
75 (a, b) => b.length - a.length,
76 );
77
78 for (const toolName of sortedToolNames) {
79 // Create regex to match tool name (case insensitive, word boundaries)
80 const regex = new RegExp(`\\b${toolName}\\b`, 'gi');
81
82 result = result.replace(regex, match => {
83 // Only create link if the match isn't already inside a link
84 if (result.indexOf(`[${match}]`) !== -1) {
85 return match; // Already linked
86 }
87 const anchorLink = toolName.toLowerCase();
88 return `[\`${match}\`](#${anchorLink})`;
89 });
90 }
91
92 return result;
93}
94
95function sortTools(a: ToolWithAnnotations, b: ToolWithAnnotations): number {
96 const aHasConditions = Boolean(a.annotations?.conditions?.length > 0);

Callers 1

generateReferenceFunction · 0.85

Calls 3

sortMethod · 0.80
toLowerCaseMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected