Re #131239. Add html link and auto link detection support. (#169577)

This commit is contained in:
Peng Lyu
2022-12-19 13:55:35 -08:00
committed by GitHub
parent 2b4fcbbb54
commit f2e35ef4ce
2 changed files with 14 additions and 2 deletions

View File

@@ -379,6 +379,11 @@ export function handleANSIOutput(text: string): HTMLSpanElement {
}
}
const ttPolicy = window.trustedTypes?.createPolicy('notebookRenderer', {
createHTML: value => value,
createScript: value => value,
});
export function appendStylizedStringToContainer(
root: HTMLElement,
stringContent: string,
@@ -392,7 +397,14 @@ export function appendStylizedStringToContainer(
return;
}
const container = linkify(stringContent, true, workspaceFolder);
let container = document.createElement('span');
const trustedHtml = ttPolicy?.createHTML(stringContent) ?? stringContent;
container.innerHTML = trustedHtml as string;
if (container.childElementCount === 0) {
// plain text
container = linkify(stringContent, true, workspaceFolder);
}
container.className = cssClasses.join(' ');
if (customTextColor) {

View File

@@ -922,7 +922,7 @@ var requirejs = (function() {
if (lineMatch) {
const parsedLineNumber = parseInt(lineMatch[1], 10);
if (!isNaN(parsedLineNumber)) {
lineNumber = parsedLineNumber;
lineNumber = parsedLineNumber + 1;
column = 1;
uri = uri.with({ fragment: `L${lineNumber}` });
}