Skip to content

Commit c1d7c00

Browse files
simonwclaude
andcommitted
Fix internal links in search results to include page file
Internal anchor links (like timestamp links) in cloned message blocks now correctly point to page-xxx.html#msg-XXX instead of just #msg-XXX. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7627e60 commit c1d7c00

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/claude_code_transcripts/templates/search.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@
8181
});
8282
}
8383

84+
function fixInternalLinks(element, pageFile) {
85+
// Update all internal anchor links to include the page file
86+
var links = element.querySelectorAll('a[href^="#"]');
87+
links.forEach(function(link) {
88+
var href = link.getAttribute('href');
89+
link.setAttribute('href', pageFile + href);
90+
});
91+
}
92+
8493
function processPage(pageFile, html, query) {
8594
var parser = new DOMParser();
8695
var doc = parser.parseFromString(html, 'text/html');
@@ -99,6 +108,8 @@
99108

100109
// Clone the message HTML and highlight matches
101110
var clone = msg.cloneNode(true);
111+
// Fix internal links to include the page file
112+
fixInternalLinks(clone, pageFile);
102113
highlightTextNodes(clone, query);
103114

104115
var resultDiv = document.createElement('div');

tests/__snapshots__/test_generate_html/TestGenerateHtml.test_generates_index_html.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ <h1>Claude Code transcript</h1>
284284
});
285285
}
286286

287+
function fixInternalLinks(element, pageFile) {
288+
// Update all internal anchor links to include the page file
289+
var links = element.querySelectorAll('a[href^="#"]');
290+
links.forEach(function(link) {
291+
var href = link.getAttribute('href');
292+
link.setAttribute('href', pageFile + href);
293+
});
294+
}
295+
287296
function processPage(pageFile, html, query) {
288297
var parser = new DOMParser();
289298
var doc = parser.parseFromString(html, 'text/html');
@@ -302,6 +311,8 @@ <h1>Claude Code transcript</h1>
302311

303312
// Clone the message HTML and highlight matches
304313
var clone = msg.cloneNode(true);
314+
// Fix internal links to include the page file
315+
fixInternalLinks(clone, pageFile);
305316
highlightTextNodes(clone, query);
306317

307318
var resultDiv = document.createElement('div');

tests/__snapshots__/test_generate_html/TestParseSessionFile.test_jsonl_generates_html.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ <h1>Claude Code transcript</h1>
275275
});
276276
}
277277

278+
function fixInternalLinks(element, pageFile) {
279+
// Update all internal anchor links to include the page file
280+
var links = element.querySelectorAll('a[href^="#"]');
281+
links.forEach(function(link) {
282+
var href = link.getAttribute('href');
283+
link.setAttribute('href', pageFile + href);
284+
});
285+
}
286+
278287
function processPage(pageFile, html, query) {
279288
var parser = new DOMParser();
280289
var doc = parser.parseFromString(html, 'text/html');
@@ -293,6 +302,8 @@ <h1>Claude Code transcript</h1>
293302

294303
// Clone the message HTML and highlight matches
295304
var clone = msg.cloneNode(true);
305+
// Fix internal links to include the page file
306+
fixInternalLinks(clone, pageFile);
296307
highlightTextNodes(clone, query);
297308

298309
var resultDiv = document.createElement('div');

0 commit comments

Comments
 (0)