Notebook Markdown email rendering fix (#16417)

* fix email WYSIWYG rendering
This commit is contained in:
Vasu Bhog
2021-07-23 15:24:34 -07:00
committed by GitHub
parent 66c62fcce3
commit 151522013f
2 changed files with 25 additions and 5 deletions

View File

@@ -134,11 +134,16 @@ export class NotebookMarkdownRenderer {
} else {
// HTML Encode href
href = href.replace(/&(?!amp;)/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
let uri = URI.parse(href);
// mailto uris do not need additional encoding of &, otherwise it would not render properly
if (uri.scheme !== 'mailto') {
href = href.replace(/&(?!amp;)/g, '&amp;');
} else {
href = href.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
return `<a href=${href} data-href="${href}" title="${title || href}">${text}</a>`;
}
};

View File

@@ -69,6 +69,21 @@ suite('NotebookMarkdownRenderer', () => {
assert.strict(markedPath, '<p>....\test.ipynb</p>');
});
test('email in markdown format renders properly', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `[test@email.com](mailto:test@email.com)`, isTrusted: true });
assert.strictEqual(result.innerHTML, `<p><a href="mailto:test@email.com" data-href="mailto:test@email.com" title="mailto:test@email.com">test@email.com</a></p>`);
});
test('email inserted directly renders properly', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `test@email.com`, isTrusted: true });
assert.strictEqual(result.innerHTML, `<p><a href="mailto:test@email.com" data-href="mailto:test@email.com" title="mailto:test@email.com">test@email.com</a></p>`);
});
test('link to https with query parameters', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `[test](https://www.test.com?test=&test2=)`, isTrusted: true });
assert.strictEqual(result.innerHTML, `<p><a href="https://www.test.com?test=&amp;test2=" data-href="https://www.test.com?test=&amp;test2=" title="https://www.test.com?test=&amp;test2=">test</a></p>`);
});
test('cell attachment image', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `![altText](attachment:ads.png)`, isTrusted: true }, { cellAttachments: JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
assert.strictEqual(result.innerHTML, `<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggg==" alt="altText"></p>`, 'Cell attachment basic test failed when trusted');