mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
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:
@@ -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 <a href="file.py">link</a> something');
|
||||
assert.equal(htmlWithLinks.textContent, 'something <a href="file.py">link</a> something');
|
||||
|
||||
@@ -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}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user