Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Don't linkify code blocks #7859

Merged
merged 9 commits into from
May 3, 2022
Merged
2 changes: 2 additions & 0 deletions src/linkify-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export const options = {
rel: 'noreferrer noopener',
},

ignoreTags: ['pre', 'code'],

className: 'linkified',

target: function(href: string, type: Type | string): string {
Expand Down
27 changes: 27 additions & 0 deletions test/components/views/messages/TextualBody-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,33 @@ describe("<TextualBody />", () => {
'</span></span></span>');
});

it("linkification is not applied to code blocks", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
user: "sender",
content: {
body: "Visit `https://matrix.org/`\n```\nhttps://matrix.org/\n```",
msgtype: "m.text",
format: "org.matrix.custom.html",
formatted_body: "<p>Visit <code>https://matrix.org/</code></p>\n<pre>https://matrix.org/\n</pre>\n",
},
event: true,
});

const wrapper = mount(<TextualBody mxEvent={ev} />);
expect(wrapper.text()).toBe("Visit https://matrix.org/\n1https://matrix.org/\n\n");
const content = wrapper.find(".mx_EventTile_body");
expect(content.html()).toBe('<span class="mx_EventTile_body markdown-body" dir="auto">' +
'<p>Visit <code>https://matrix.org/</code></p>\n' +
'<div class="mx_EventTile_pre_container">' +
'<pre class="mx_EventTile_collapsedCodeBlock">' +
'<span class="mx_EventTile_lineNumbers"><span>1</span></span>' +
'<code>https://matrix.org/\n</code><span></span></pre>' +
'<span class="mx_EventTile_button mx_EventTile_copyButton ">' +
'</span></div>\n</span>');
robintown marked this conversation as resolved.
Show resolved Hide resolved
});

// If pills were rendered within a Portal/same shadow DOM then it'd be easier to test
it("pills get injected correctly into the DOM", () => {
const ev = mkEvent({
Expand Down