Fix syntax highlighting and rendering issues. (#7759)

Co-authored-by: Miguel Solorio <miguelsolorio@google.com>
This commit is contained in:
Jacob Richman
2025-09-05 15:29:54 -07:00
committed by GitHub
parent c1b8708ef5
commit d8dbe6271f
4 changed files with 120 additions and 45 deletions

View File

@@ -9,10 +9,11 @@ export type HighlightToken = {
type: 'default' | 'command' | 'file';
};
const HIGHLIGHT_REGEX = /(\/[a-zA-Z0-9_-]+|@[a-zA-Z0-9_./-]+)/g;
const HIGHLIGHT_REGEX = /(^\/[a-zA-Z0-9_-]+|@(?:\\ |[a-zA-Z0-9_./-])+)/g;
export function parseInputForHighlighting(
text: string,
index: number,
): readonly HighlightToken[] {
if (!text) {
return [{ text: '', type: 'default' }];
@@ -36,10 +37,18 @@ export function parseInputForHighlighting(
// Add the matched token
const type = fullMatch.startsWith('/') ? 'command' : 'file';
tokens.push({
text: fullMatch,
type,
});
// Only highlight slash commands if the index is 0.
if (type === 'command' && index !== 0) {
tokens.push({
text: fullMatch,
type: 'default',
});
} else {
tokens.push({
text: fullMatch,
type,
});
}
lastIndex = matchIndex + fullMatch.length;
}