Skip to content

Commit

Permalink
Revert "Prevent dragging of links in rendered markdown (microsoft#168232
Browse files Browse the repository at this point in the history
)" (microsoft#174274)

This reverts commit 7981d7f.
  • Loading branch information
sbatten authored and c-claeys committed Feb 16, 2023
1 parent 05427e6 commit 99e4564
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/vs/base/browser/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: MarkdownRende
markdownHtmlDoc.body.querySelectorAll('a')
.forEach(a => {
const href = a.getAttribute('href'); // Get the raw 'href' attribute value as text, not the resolved 'href'
a.removeAttribute('href'); // Clear out href. We use the `data-href` for handling clicks instead
a.setAttribute('href', ''); // Clear out href. We use the `data-href` for handling clicks instead
if (
!href
|| /^data:|javascript:/i.test(href)
Expand Down
6 changes: 3 additions & 3 deletions src/vs/base/test/browser/markdownRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ suite('MarkdownRenderer', () => {
mds.appendMarkdown(`[$(zap)-link](#link)`);

const result: HTMLElement = renderMarkdown(mds).element;
assert.strictEqual(result.innerHTML, `<p><a data-href="#link" title="#link"><span class="codicon codicon-zap"></span>-link</a></p>`);
assert.strictEqual(result.innerHTML, `<p><a data-href="#link" href="" title="#link"><span class="codicon codicon-zap"></span>-link</a></p>`);
});

test('render icon in table', () => {
Expand All @@ -181,7 +181,7 @@ suite('MarkdownRenderer', () => {
</thead>
<tbody><tr>
<td><span class="codicon codicon-zap"></span></td>
<td><a data-href="#link" title="#link"><span class="codicon codicon-zap"></span>-link</a></td>
<td><a data-href="#link" href="" title="#link"><span class="codicon codicon-zap"></span>-link</a></td>
</tr>
</tbody></table>
`);
Expand Down Expand Up @@ -248,7 +248,7 @@ suite('MarkdownRenderer', () => {
});

const result: HTMLElement = renderMarkdown(md).element;
assert.strictEqual(result.innerHTML, `<p><a data-href="command:doFoo" title="command:doFoo">command1</a> <a data-href="command:doFoo">command2</a></p>`);
assert.strictEqual(result.innerHTML, `<p><a data-href="command:doFoo" href="" title="command:doFoo">command1</a> <a data-href="command:doFoo" href="">command2</a></p>`);
});

suite('PlaintextMarkdownRender', () => {
Expand Down

0 comments on commit 99e4564

Please sign in to comment.