fix: tweak the label for citations for better rendering (#919)

Adds a space so that sequential citations have some more breathing room.

As I had to update the tests for this change, I also introduced a
`toDiffableString()` helper to make the test easier to update as we make
formatting changes to the output.
This commit is contained in:
Michael Bolin
2025-05-13 12:46:21 -07:00
committed by GitHub
parent 1ff3e14d5a
commit 0ac7e8d55b
2 changed files with 20 additions and 4 deletions

View File

@@ -334,6 +334,11 @@ function rewriteFileCitations(
return markdown.replace(citationRegex, (_match, file, start, _end) => {
const absPath = path.resolve(cwd, file);
const uri = `${fileOpener}://file${absPath}:${start}`;
return `[${file}](${uri})`;
const label = `${file}:${start}`;
// In practice, sometimes multiple citations for the same file, but with a
// different line number, are shown sequentially, so we:
// - include the line number in the label to disambiguate them
// - add a space after the link to make it easier to read
return `[${label}](${uri}) `;
});
}