mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
add title for svgs
This commit is contained in:
parent
7cb0a11e36
commit
24842542bf
|
@ -33,9 +33,9 @@ function renderImage(outputInfo: OutputItem, element: HTMLElement): IDisposable
|
|||
|
||||
const image = document.createElement('img');
|
||||
image.src = src;
|
||||
const metadata = outputInfo.metadata;
|
||||
if (typeof metadata === 'object' && metadata && 'altText' in metadata && typeof metadata.altText === 'string') {
|
||||
image.alt = metadata.altText;
|
||||
const alt = getAltText(outputInfo);
|
||||
if (alt) {
|
||||
image.alt = alt;
|
||||
}
|
||||
const display = document.createElement('div');
|
||||
display.classList.add('display');
|
||||
|
@ -68,12 +68,33 @@ const domEval = (container: Element) => {
|
|||
}
|
||||
};
|
||||
|
||||
function getAltText(outputInfo: OutputItem) {
|
||||
const metadata = outputInfo.metadata;
|
||||
if (typeof metadata === 'object' && metadata && 'altText' in metadata && typeof metadata.altText === 'string') {
|
||||
return metadata.altText;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function injectTitleForSvg(outputInfo: OutputItem, element: HTMLElement) {
|
||||
if (outputInfo.mime.indexOf('svg') > -1) {
|
||||
const svgElement = element.querySelector('svg');
|
||||
const altText = getAltText(outputInfo);
|
||||
if (svgElement && altText) {
|
||||
const title = document.createElement('title');
|
||||
title.innerText = altText;
|
||||
svgElement.prepend(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function renderHTML(outputInfo: OutputItem, container: HTMLElement, signal: AbortSignal, hooks: Iterable<HtmlRenderingHook>): Promise<void> {
|
||||
clearContainer(container);
|
||||
let element: HTMLElement = document.createElement('div');
|
||||
const htmlContent = outputInfo.text();
|
||||
const trustedHtml = ttPolicy?.createHTML(htmlContent) ?? htmlContent;
|
||||
element.innerHTML = trustedHtml as string;
|
||||
injectTitleForSvg(outputInfo, element);
|
||||
|
||||
for (const hook of hooks) {
|
||||
element = (await hook.postRender(outputInfo, element, signal)) ?? element;
|
||||
|
|
Loading…
Reference in a new issue