Skip to content

Commit 894a454

Browse files
authored
CCM-10140: message content preview links should open in new tab (#510)
1 parent d27fe0c commit 894a454

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

frontend/src/__tests__/utils/markdownit/__snapshots__/index.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports[`renderEmailMarkdown should only process email markdown rules 1`] = `
1212
<li>ordered list item 1</li>
1313
<li>ordered list item 2</li>
1414
</ol>
15-
<p><a href="https://www.nhs.uk/example">Read more</a></p>
15+
<p><a href="https://www.nhs.uk/example" target="_blank" rel="noopener noreferrer">Read more</a></p>
1616
<p>https://www.nhs.uk/example</p>
1717
<p>Before page break</p>
1818
<hr>
@@ -38,7 +38,7 @@ exports[`renderNHSAppMarkdown should only process nhs app markdown rules 1`] = `
3838
<li>ordered list item 1</li>
3939
<li>ordered list item 2</li>
4040
</ol>
41-
<p><a href="https://www.nhs.uk/example">Read more</a></p>
41+
<p><a href="https://www.nhs.uk/example" target="_blank" rel="noopener noreferrer">Read more</a></p>
4242
<p>https://www.nhs.uk/example</p>
4343
<p>Before page break
4444
***

frontend/src/utils/markdownit/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { lineBreak } from './plugins/line-break';
44
export class MarkdownItWrapper extends MarkdownIt {
55
constructor() {
66
super('zero');
7+
8+
// rendered links should open in a new tab
9+
this.renderer.rules.link_open = (tokens, idx) => {
10+
const href = tokens[idx].attrGet('href');
11+
12+
return `<a href="${href}" target="_blank" rel="noopener noreferrer">`;
13+
};
714
}
815

916
/**

0 commit comments

Comments
 (0)