mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
DevServer: source map and error modal improvements (#17476)
This commit is contained in:
@@ -562,6 +562,24 @@ export class DraculaSyntaxHighlighter {
|
||||
return this.buildHtmlElement("pre", { "class": classAttr }, result);
|
||||
}
|
||||
|
||||
public highlightLine() {
|
||||
let lineContent = "";
|
||||
|
||||
for (const token of this.tokenize()) {
|
||||
if (token.type === TokenType.Newline) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token.tokenClass) {
|
||||
lineContent += this.wrap(token.value, token.tokenClass);
|
||||
} else {
|
||||
lineContent += this.escapeHtml(token.value);
|
||||
}
|
||||
}
|
||||
|
||||
return lineContent;
|
||||
}
|
||||
|
||||
private escapeHtml(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, "&")
|
||||
@@ -794,3 +812,7 @@ export class DraculaSyntaxHighlighter {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function syntaxHighlight(code: string) {
|
||||
return new DraculaSyntaxHighlighter(code).highlightLine();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user