Skip to content

Commit abca622

Browse files
committed
init
1 parent f0641a3 commit abca622

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
/* eslint-disable sonarjs/no-commented-code */
12
import MarkdownIt from 'markdown-it';
23
import { lineBreak } from './plugins/line-break';
34

45
export class MarkdownItWrapper extends MarkdownIt {
56
constructor() {
67
super('zero');
8+
9+
// rendered links should open in a new tab
10+
this.renderer.rules.link_open = (tokens, idx) => {
11+
const href = tokens[idx].attrGet('href');
12+
13+
return `<a href="${href}" target="_blank" rel="noopener noreferrer">`;
14+
};
715
}
816

917
/**

0 commit comments

Comments
 (0)