fix exact search (#4640)

* disable select all text when clicked

* fix exact match search

* small fixes

* improve fuzzy search

* ignore invisible characters in search

* feature to navigate and scroll multiple search results in the same section

* add keyboard shortcut for highlight matches and also combine nearby highlighted matches

* comments

---------

Co-authored-by: nbats <44333466+nbats@users.noreply.github.com>
This commit is contained in:
bread
2026-01-26 04:37:10 -08:00
committed by GitHub
parent 7e37eb3ed3
commit dea24a8b93
8 changed files with 456 additions and 69 deletions

View File

@@ -105,13 +105,49 @@ files.forEach(file => {
}
}
}
// Check 8: Asymmetric spaces around slash
// We must exclude URLs (http://...)
const lineWithoutLinks = line.replace(/https?:\/\/[^\s)]+/g, 'LINK_PLACEHOLDER');
// Ignore VitePress sidebar links (e.g. "link: /foo")
if (!/^\s*link:/i.test(line)) {
// A. Missing space after slash: " /Word"
// Exception: /> (HTML close tag)
// Exception: /Word/ (Path/Board e.g. /co/)
const missingSpaceAfter = lineWithoutLinks.matchAll(/\s\/([^\s]+)/g);
for (const match of missingSpaceAfter) {
const wordAfter = match[1];
if (wordAfter.startsWith('>')) continue; // Ignore />
// Ignore paths (e.g. /bin), subreddits (/r/foo), or compound words (Word/Word)
if (wordAfter.includes('/')) continue;
errors.push(`Missing space after slash (e.g. "Word /Word"): "${match[0]}"`);
break;
}
// B. Missing space before slash: "Word/ "
// Exceptions: w/ (with), r/ (reddit), u/ (user), c/ (community)
// Exception: /Word/ (Path/Board e.g. /b/)
const missingSpaceBefore = lineWithoutLinks.matchAll(/([^\s]+)\/\s/g);
for (const match of missingSpaceBefore) {
const wordBefore = match[1];
// Allow common abbreviations: w/, r/, u/, c/
if (/^(w|r|u|c)$/i.test(wordBefore)) continue;
// Allow paths ending in slash or containing slash: /b/ or [/int
if (wordBefore.includes('/')) continue;
errors.push(`Missing space before slash (e.g. "Word/ Word"): "${match[0]}"`);
break;
}
}
if (errors.length > 0) {
hasErrors = true;
errors.forEach(err => {
console.log(`${relativePath}:${lineNum} - ${err}`);
console.log(` Line: ${line.trim()}`);
// file:line - Error (in red/cyan)
console.log(`\x1b[36m${relativePath}:${lineNum}\x1b[0m - \x1b[31m${err}\x1b[0m`);
// Source line (dimmed)
console.log(` \x1b[90m${line.trim()}\x1b[0m`);
});
}
});