Skip to content

Commit 2794938

Browse files
[ASL-4380] Markdown fixes to display nested lists (#323)
* [ASL-4380] Markdown fixes to display nested lists - Remove trimming of whitespace at the start of lines - Use remarkBreaks rather than styling it using pre * [ASL-4380] Markdown fixes to display nested lists - Remove trimming of whitespace at the start of lines - Use remarkBreaks rather than styling it using pre * [ASL-4380] Fix test whitespace
1 parent 240d99e commit 2794938

File tree

5 files changed

+65
-73
lines changed

5 files changed

+65
-73
lines changed

package-lock.json

Lines changed: 48 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ukhomeoffice/asl-components",
3-
"version": "12.1.0",
3+
"version": "13.0.0",
44
"description": "React components for ASL layouts and elements",
55
"main": "src/index.jsx",
66
"styles": "styles/index.scss",
@@ -39,6 +39,7 @@
3939
"qs": "^6.6.1",
4040
"react": "^16.9.0",
4141
"react-markdown": "^6.0.2",
42+
"remark-breaks": "^2.0.2",
4243
"react-redux": "^7.1.0",
4344
"redux": "^4.0.1",
4445
"shasum": "^1.0.2",

src/conditions/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Conditions({
6868
{
6969
conditions &&
7070
<Fragment>
71-
<Inset className="condition"><Markdown>{ tempCondition }</Markdown></Inset>
71+
<Inset className="condition"><Markdown significantLineBreaks>{ tempCondition }</Markdown></Inset>
7272
<ConditionReminders reminders={ tempReminders } />
7373
</Fragment>
7474
}

src/markdown/index.jsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react/display-name */
22
import React, { Fragment } from 'react';
33
import ReactMarkdown from 'react-markdown';
4+
import remarkBreaks from 'remark-breaks';
45

56
function RenderLink({ href, children }) {
67
return <Fragment>[{ children }]({ href })</Fragment>;
@@ -14,13 +15,6 @@ const components = {
1415
linkReference: RenderLinkReference
1516
};
1617

17-
const trim = str => {
18-
if (typeof str === 'string') {
19-
return str.split('\n').map(s => s.trim()).join('\n').trim();
20-
}
21-
return str;
22-
};
23-
2418
// eslint-disable-next-line no-unused-vars
2519
const wrapInSpanIfOnlyChild = enabled => ({ node, siblingCount, index, ...props }) => {
2620
if (enabled && siblingCount === 1) {
@@ -29,16 +23,23 @@ const wrapInSpanIfOnlyChild = enabled => ({ node, siblingCount, index, ...props
2923
return <p {...props} />;
3024
};
3125

32-
export default function Markdown({ children, links = false, unwrapSingleLine = false, source, ...props }) {
33-
26+
export default function Markdown({
27+
children,
28+
links = false,
29+
unwrapSingleLine = false,
30+
significantLineBreaks = false,
31+
source,
32+
...props
33+
}) {
3434
return <ReactMarkdown
3535
includeElementIndex={true}
3636
components={{
3737
...(!links && components),
3838
p: wrapInSpanIfOnlyChild(unwrapSingleLine)
3939
}}
40+
remarkPlugins={significantLineBreaks ? [remarkBreaks] : []}
4041
{...props}
4142
>
42-
{ trim(source || children) }
43+
{ source || children }
4344
</ReactMarkdown>;
4445
}

src/snippet/index.spec.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ describe('<Snippet />', () => {
1616
const content = {
1717
string: 'one line',
1818
list: `* one
19-
* two
20-
* three`,
19+
* two
20+
* three`,
2121
paragraphs: `one
2222
23-
two`
23+
two`
2424
};
2525

2626
test('does not include a wrapping element on single line input', () => {

0 commit comments

Comments
 (0)