diff --git a/src/linkify-matrix.ts b/src/linkify-matrix.ts index c42d98d326..7935f5d037 100644 --- a/src/linkify-matrix.ts +++ b/src/linkify-matrix.ts @@ -225,6 +225,8 @@ export const options = { rel: 'noreferrer noopener', }, + ignoreTags: ['pre', 'code'], + className: 'linkified', target: function(href: string, type: Type | string): string { diff --git a/test/components/views/messages/TextualBody-test.tsx b/test/components/views/messages/TextualBody-test.tsx index 371c372196..fe4dbf9946 100644 --- a/test/components/views/messages/TextualBody-test.tsx +++ b/test/components/views/messages/TextualBody-test.tsx @@ -216,6 +216,26 @@ describe("", () => { ''); }); + 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: "

Visit https://matrix.org/

\n
https://matrix.org/\n
\n", + }, + event: true, + }); + + const wrapper = getComponent({ mxEvent: ev }, matrixClient); + expect(wrapper.text()).toBe("Visit https://matrix.org/\n1https://matrix.org/\n\n"); + const content = wrapper.find(".mx_EventTile_body"); + expect(content.html()).toMatchSnapshot(); + }); + // 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({ diff --git a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap index 9d481765e1..15d3b7e208 100644 --- a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap @@ -1,5 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[` renders formatted m.text correctly linkification is not applied to code blocks 1`] = ` +"

Visit https://matrix.org/

+
1https://matrix.org/
+
+
" +`; + exports[` renders formatted m.text correctly pills do not appear in code blocks 1`] = ` "

@room

1@room