Skip to content

Commit 73a5f8b

Browse files
committed
CCM-8125: test fixture fix
1 parent da6279f commit 73a5f8b

File tree

8 files changed

+87
-35
lines changed

8 files changed

+87
-35
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ indent_size = 4
2828

2929
[{Makefile,*.mk,go.mod,go.sum,*.go,.gitmodules}]
3030
indent_style = tab
31+
32+
[frontend/src/__tests__/utils/markdownit/fixtures/index.ts]
33+
trim_trailing_whitespace = false

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

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
2020
<h1>Headings</h1>
2121
<h1>Heading 1</h1>
2222
<h2>Heading 2</h2>
23-
<p>Heading 3</h3>
24-
<p>Heading 4</h4>
23+
<p>Heading 3</p>
24+
<p>Heading 4</p>
25+
<p>Heading 5</p>
26+
<p>Heading 6</p>
27+
<p>####### Heading 7</p>
28+
<p>## Indented Heading</p>
2529
<h1>Heading no space</h1>
30+
<h1>Hashes at the end of the line get trimmed</h1>
2631
<h2>Heading directly above a paragraph</h2>
2732
<p>Aenean congue venenatis rutrum. Suspendisse vehicula finibus volutpat. Nunc lacinia rhoncus nibh.</p>
2833
<h1>Bold and italics</h1>
@@ -86,6 +91,8 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
8691
<hr>
8792
<p>Horizontal line using 3 underscores</p>
8893
<hr>
94+
<p>Horizontal line with less than 3 doesn't render</p>
95+
<p>__</p>
8996
"
9097
`;
9198
@@ -96,8 +103,8 @@ exports[`renderNHSAppMarkdown should render markdown matching NHSApp email rules
96103
Line 2
97104
Line 3</p>
98105
<p>With 2 trailing spaces:</p>
99-
<p>Line 4
100-
Line 5
106+
<p>Line 4<br>
107+
Line 5<br>
101108
Line 6</p>
102109
<h1>Paragraphs</h1>
103110
<p>Paragraph 1</p>
@@ -111,7 +118,12 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
111118
<h2>Heading 2</h2>
112119
<h3>Heading 3</h3>
113120
<h4>Heading 4</h4>
121+
<h5>Heading 5</h5>
122+
<h6>Heading 6</h6>
123+
<p>####### Heading 7</p>
124+
<p>## Indented Heading</p>
114125
<p>#Heading no space</p>
126+
<h1>Hashes at the end of the line get trimmed</h1>
115127
<h2>Heading directly above a paragraph</h2>
116128
<p>Aenean congue venenatis rutrum. Suspendisse vehicula finibus volutpat. Nunc lacinia rhoncus nibh.</p>
117129
<h1>Bold and italics</h1>
@@ -161,7 +173,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
161173
<h1>Image</h1>
162174
<p><img src="https://assets.nhs.uk/images/nhs-logo.png" alt="NHS Logo"></p>
163175
<h1>Links</h1>
164-
<p><a href="https://en.wikipedia.org/wiki/Markdown">Link text</a></p>
176+
<p><a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="noopener noreferrer">Link text</a></p>
165177
<p>www.nhs.uk</p>
166178
<p>nhs.uk</p>
167179
<p>https://www.nhs.uk</p>
@@ -185,23 +197,25 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
185197
</ul>
186198
<p>Horizontal line using 3 underscores</p>
187199
<hr>
200+
<p>Horizontal line with less than 3 doesn't render</p>
201+
<p>__</p>
188202
"
189203
`;
190204
191205
exports[`renderSMSMarkdown should render markdown matching GOVUK Notify SMS rules 1`] = `
192206
"<p># Linebreaks</p>
193207
<p>Without 2 trailing spaces:</p>
194-
<p>Line 1
195-
Line 2
208+
<p>Line 1<br>
209+
Line 2<br>
196210
Line 3</p>
197211
<p>With 2 trailing spaces:</p>
198-
<p>Line 4
199-
Line 5
212+
<p>Line 4<br>
213+
Line 5<br>
200214
Line 6</p>
201215
<p># Paragraphs</p>
202216
<p>Paragraph 1</p>
203217
<p>Paragraph 2</p>
204-
<p>Paragraph 3
218+
<p>Paragraph 3<br>
205219
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam vitae finibus.</p>
206220
<p>Paragraph above two blank lines</p>
207221
<p>Paragraph below two blank lines</p>
@@ -210,8 +224,13 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam
210224
<p>## Heading 2</p>
211225
<p>### Heading 3</p>
212226
<p>#### Heading 4</p>
227+
<p>##### Heading 5</p>
228+
<p>###### Heading 6</p>
229+
<p>####### Heading 7</p>
230+
<p>## Indented Heading</p>
213231
<p>#Heading no space</p>
214-
<p>## Heading directly above a paragraph
232+
<p># Hashes at the end of the line get trimmed ###</p>
233+
<p>## Heading directly above a paragraph<br>
215234
Aenean congue venenatis rutrum. Suspendisse vehicula finibus volutpat. Nunc lacinia rhoncus nibh.</p>
216235
<p># Bold and italics</p>
217236
<p>**Some bold text using asterisks**</p>
@@ -220,41 +239,43 @@ Aenean congue venenatis rutrum. Suspendisse vehicula finibus volutpat. Nunc laci
220239
<p>_Some italic text using underscores_</p>
221240
<p># Lists</p>
222241
<p>Bullets with asterisks:</p>
223-
<p>* Duis finibus tellus augue, ut dapibus orci vehicula id.
224-
* Proin in condimentum tellus, ac elementum ligula.
242+
<p>* Duis finibus tellus augue, ut dapibus orci vehicula id.<br>
243+
* Proin in condimentum tellus, ac elementum ligula.<br>
225244
* Nulla libero nisl, hendrerit vel est quis, efficitur dignissim est.</p>
226245
<p>Bullets with dashes:</p>
227-
<p>- Duis finibus tellus augue, ut dapibus orci vehicula id.
228-
- Proin in condimentum tellus, ac elementum ligula.
246+
<p>- Duis finibus tellus augue, ut dapibus orci vehicula id.<br>
247+
- Proin in condimentum tellus, ac elementum ligula.<br>
229248
- Nulla libero nisl, hendrerit vel est quis, efficitur dignissim est.</p>
230249
<p>Bullets without required spaces:</p>
231-
<p>*bullet 1 no space
232-
*bullet 2 no space
250+
<p>*bullet 1 no space<br>
251+
*bullet 2 no space<br>
233252
*bullet 3 no space</p>
234253
<p>Ordered list:</p>
235-
<p>1. Praesent rutrum ex vel velit aliquam.
236-
2. Et viverra turpis vestibulum.
254+
<p>1. Praesent rutrum ex vel velit aliquam.<br>
255+
2. Et viverra turpis vestibulum.<br>
237256
3. Pellentesque quis nisi accumsan.</p>
238257
<p>Ordered list without required spaces:</p>
239-
<p>1.Step 1 no space
240-
2.Step 2 no space
258+
<p>1.Step 1 no space<br>
259+
2.Step 2 no space<br>
241260
3.Step 3 no space</p>
242261
<p># Image</p>
243-
<p>![NHS Logo](<a href="https://assets.nhs.uk/images/nhs-logo.png">https://assets.nhs.uk/images/nhs-logo.png</a>)</p>
262+
<p>![NHS Logo](<a href="https://assets.nhs.uk/images/nhs-logo.png" target="_blank" rel="noopener noreferrer">https://assets.nhs.uk/images/nhs-logo.png</a>)</p>
244263
<p># Links</p>
245-
<p>[Link text](<a href="https://en.wikipedia.org/wiki/Markdown">https://en.wikipedia.org/wiki/Markdown</a>)</p>
246-
<p><a href="http://www.nhs.uk">www.nhs.uk</a></p>
247-
<p><a href="http://nhs.uk">nhs.uk</a></p>
248-
<p><a href="https://www.nhs.uk">https://www.nhs.uk</a></p>
249-
<p><a href="http://nhs.uk">http://nhs.uk</a></p>
264+
<p>[Link text](<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="noopener noreferrer">https://en.wikipedia.org/wiki/Markdown</a>)</p>
265+
<p><a href="http://www.nhs.uk" target="_blank" rel="noopener noreferrer">www.nhs.uk</a></p>
266+
<p><a href="http://nhs.uk" target="_blank" rel="noopener noreferrer">nhs.uk</a></p>
267+
<p><a href="https://www.nhs.uk" target="_blank" rel="noopener noreferrer">https://www.nhs.uk</a></p>
268+
<p><a href="http://nhs.uk" target="_blank" rel="noopener noreferrer">http://nhs.uk</a></p>
250269
<p>user@domain.com</p>
251270
<p>Links with &lt; &gt; symbols:</p>
252-
<p>&lt;<a href="http://www.google.com">www.google.com</a>&gt;</p>
271+
<p>&lt;<a href="http://www.google.com" target="_blank" rel="noopener noreferrer">www.google.com</a>&gt;</p>
253272
<p>&lt;user@domain.com&gt;</p>
254273
<p># Lines</p>
255274
<p>Horizontal line using 3 asterisks</p>
256275
<p>***</p>
257276
<p>Horizontal line using 3 underscores</p>
258277
<p>___</p>
278+
<p>Horizontal line with less than 3 doesn't render</p>
279+
<p>__</p>
259280
"
260281
`;

frontend/src/__tests__/components/forms/fixtures.ts renamed to frontend/src/__tests__/utils/markdownit/fixtures/index.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* All supported markdown features
3+
* Be careful not to auto-format this file
34
*/
45
export const markdown = `
56
# Linebreaks
@@ -12,9 +13,9 @@ Line 3
1213
1314
With 2 trailing spaces:
1415
15-
Line 4
16-
Line 5
17-
Line 6
16+
Line 4
17+
Line 5
18+
Line 6
1819
1920
# Paragraphs
2021
@@ -23,7 +24,7 @@ Paragraph 1
2324
Paragraph 2
2425
2526
Paragraph 3
26-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam vitae finibus.
27+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor vel quam vitae finibus.
2728
2829
Paragraph above two blank lines
2930
@@ -40,8 +41,18 @@ Paragraph below two blank lines
4041
4142
#### Heading 4
4243
44+
##### Heading 5
45+
46+
###### Heading 6
47+
48+
####### Heading 7
49+
50+
## Indented Heading
51+
4352
#Heading no space
4453
54+
# Hashes at the end of the line get trimmed ###
55+
4556
## Heading directly above a paragraph
4657
Aenean congue venenatis rutrum. Suspendisse vehicula finibus volutpat. Nunc lacinia rhoncus nibh.
4758
@@ -120,4 +131,8 @@ Horizontal line using 3 asterisks
120131
Horizontal line using 3 underscores
121132
122133
___
134+
135+
Horizontal line with less than 3 doesn't render
136+
137+
__
123138
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
renderNHSAppMarkdown,
44
renderSMSMarkdown,
55
} from '@utils/markdownit';
6-
import { markdown } from '../../components/forms/fixtures';
6+
import { markdown } from './fixtures';
77

88
describe('renderEmailMarkdown', () => {
99
it('should render markdown matching GOVUK Notify email rules', () => {

frontend/src/utils/markdownit/block-rules/heading.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function headingNoSpaces(
4242
return false;
4343
}
4444

45+
/* istanbul ignore next */
4546
if (silent) {
4647
return true;
4748
}

frontend/src/utils/markdownit/block-rules/hr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function hrUnderscoreOnly(
5252
return false;
5353
}
5454

55+
/* istanbul ignore next */
5556
if (silent) {
5657
return true;
5758
}

frontend/src/utils/markdownit/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function renderEmailMarkdown(value: string) {
3737
markdown.block.ruler.at('heading', headingNoSpaces); // Support headings with no spaces after the hash (#Heading)
3838

3939
markdown.renderer.rules.heading_open = headingMaxDepth; // Only support headings up to <h2> - otherwise render <p>
40+
markdown.renderer.rules.heading_close = headingMaxDepth; // Only support headings up to <h2> - otherwise render <p>
4041

4142
return markdown.render(value);
4243
}
@@ -46,6 +47,8 @@ export function renderNHSAppMarkdown(value: string) {
4647

4748
markdown.enable(['heading', 'emphasis', 'list', 'image', 'link', 'hr']); // Enable out of the box rules
4849

50+
markdown.renderer.rules.link_open = linkOpenNewTab; // Open links in a new tab
51+
4952
markdown.inline.ruler.enable(['newline']); // Enable newline support with double-space line endings
5053

5154
markdown.block.ruler.at('hr', hrUnderscoreOnly); // Only support <hr> via underscores (not * or -)
@@ -59,6 +62,10 @@ export function renderSMSMarkdown(value: string) {
5962
markdown.set({ linkify: true }); // Add linkify instance
6063
markdown.core.ruler.enable(['linkify']); // Enable linkify rules
6164
markdown.linkify.set({ fuzzyIP: false, fuzzyEmail: false, fuzzyLink: true }); // Support fuzzy matching for links
65+
markdown.renderer.rules.link_open = linkOpenNewTab; // Open links in a new tab
66+
67+
markdown.set({ breaks: true }); // add \n to <br>
68+
markdown.inline.ruler.enable(['newline']); // Enable newline support with double-space line endings
6269

6370
return markdown.render(value);
6471
}

scripts/config/pre-commit.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ repos:
33
rev: v4.6.0 # Use the ref you want to point at
44
hooks:
55
- id: trailing-whitespace
6-
exclude: .+\.snap
6+
exclude: |
7+
(?x)^(
8+
frontend/src/__tests__/utils/markdownit/fixtures/index\.ts|
9+
.+\.snap
10+
)$
711
- id: detect-aws-credentials
812
args: [--allow-missing-credentials]
913
- id: check-added-large-files
@@ -36,7 +40,7 @@ repos:
3640
hooks:
3741
- id: check-file-format
3842
name: Check file format
39-
entry: /usr/bin/env check=branch ./scripts/githooks/check-file-format.sh
43+
entry: /usr/bin/env check=branch exclude=frontend/src/__tests__/utils/markdownit/fixtures/index.ts ./scripts/githooks/check-file-format.sh
4044
language: script
4145
pass_filenames: false
4246
- repo: local

0 commit comments

Comments
 (0)