Allow disabling filepath links (#200577)

* add setting to enable/disable linkifying filepaths

* implement linkify setting

* update setting without reload

* switch casing style
This commit is contained in:
Aaron Munger
2023-12-11 15:47:06 -08:00
committed by GitHub
parent 4c5336dae1
commit d5d1424296
13 changed files with 130 additions and 49 deletions

View File

@@ -15,27 +15,32 @@ suite('Notebook builtin output link detection', () => {
LinkDetector.injectedHtmlCreator = (value: string) => value;
test('no links', () => {
const htmlWithLinks = linkify('hello', true, undefined, true);
const htmlWithLinks = linkify('hello', { linkifyFilePaths: true, trustHtml: true }, true);
assert.equal(htmlWithLinks.innerHTML, 'hello');
});
test('web link detection', () => {
const htmlWithLinks = linkify('something www.example.com something', true, undefined, true);
const htmlWithLinks = linkify('something www.example.com something', { linkifyFilePaths: true, trustHtml: true }, true);
const htmlWithLinks2 = linkify('something www.example.com something', { linkifyFilePaths: false, trustHtml: false }, true);
assert.equal(htmlWithLinks.innerHTML, 'something <a href="www.example.com">www.example.com</a> something');
assert.equal(htmlWithLinks.textContent, 'something www.example.com something');
assert.equal(htmlWithLinks2.innerHTML, 'something <a href="www.example.com">www.example.com</a> something');
assert.equal(htmlWithLinks2.textContent, 'something www.example.com something');
});
test('html link detection', () => {
const htmlWithLinks = linkify('something <a href="www.example.com">link</a> something', true, undefined, true);
const htmlWithLinks = linkify('something <a href="www.example.com">link</a> something', { linkifyFilePaths: true, trustHtml: true }, true);
const htmlWithLinks2 = linkify('something <a href="www.example.com">link</a> something', { linkifyFilePaths: false, trustHtml: true }, true);
assert.equal(htmlWithLinks.innerHTML, 'something <span><a href="www.example.com">link</a></span> something');
assert.equal(htmlWithLinks.textContent, 'something link something');
assert.equal(htmlWithLinks2.innerHTML, 'something <span><a href="www.example.com">link</a></span> something');
assert.equal(htmlWithLinks2.textContent, 'something link something');
});
test('html link without trust', () => {
const trustHtml = false;
const htmlWithLinks = linkify('something <a href="file.py">link</a> something', true, undefined, trustHtml);
const htmlWithLinks = linkify('something <a href="file.py">link</a> something', { linkifyFilePaths: true, trustHtml: false }, true);
assert.equal(htmlWithLinks.innerHTML, 'something &lt;a href="file.py"&gt;link&lt;/a&gt; something');
assert.equal(htmlWithLinks.textContent, 'something <a href="file.py">link</a> something');

View File

@@ -273,6 +273,36 @@ suite('Notebook builtin output renderer', () => {
assert.ok(inserted.innerHTML.indexOf('shouldBeTruncated') === -1, `Beginning content should be truncated`);
});
test(`Render filepath links in text output when enabled`, async () => {
LinkDetector.injectedHtmlCreator = (value: string) => value;
const context = createContext({ outputWordWrap: true, outputScrolling: true, linkifyFilePaths: true });
const renderer = await activate(context);
assert.ok(renderer, 'Renderer not created');
const outputElement = new OutputHtml().getFirstOuputElement();
const outputItem = createOutputItem('./dir/file.txt', stdoutMimeType);
await renderer!.renderOutputItem(outputItem, outputElement);
const inserted = outputElement.firstChild as HTMLElement;
assert.ok(inserted, `nothing appended to output element: ${outputElement.innerHTML}`);
assert.ok(outputElement.innerHTML.indexOf('<a href="./dir/file.txt">') !== -1, `inner HTML:\n ${outputElement.innerHTML}`);
});
test(`No filepath links in text output when disabled`, async () => {
LinkDetector.injectedHtmlCreator = (value: string) => value;
const context = createContext({ outputWordWrap: true, outputScrolling: true, linkifyFilePaths: false });
const renderer = await activate(context);
assert.ok(renderer, 'Renderer not created');
const outputElement = new OutputHtml().getFirstOuputElement();
const outputItem = createOutputItem('./dir/file.txt', stdoutMimeType);
await renderer!.renderOutputItem(outputItem, outputElement);
const inserted = outputElement.firstChild as HTMLElement;
assert.ok(inserted, `nothing appended to output element: ${outputElement.innerHTML}`);
assert.ok(outputElement.innerHTML.indexOf('<a href="./dir/file.txt">') === -1, `inner HTML:\n ${outputElement.innerHTML}`);
});
test(`Render with wordwrap and scrolling for error output`, async () => {
LinkDetector.injectedHtmlCreator = (value: string) => value;
const context = createContext({ outputWordWrap: true, outputScrolling: true });
@@ -474,7 +504,6 @@ suite('Notebook builtin output renderer', () => {
const inserted = outputElement.firstChild as HTMLElement;
assert.ok(inserted, `nothing appended to output element: ${outputElement.innerHTML}`);
//assert.ok(false, `TextContent:\n ${outputElement.textContent}`);
assert.ok(outputElement.innerHTML.indexOf('class="code-background-colored"') === -1, `inner HTML:\n ${outputElement.innerHTML}`);
});