diff --git a/package-lock.json b/package-lock.json index be7be94e..0039a132 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "react-markdown": "^6.0.2", "react-redux": "^7.1.0", "redux": "^4.0.1", + "remark-breaks": "^2.0.2", "shasum": "^1.0.2", "url": "^0.11.0", "uuid": "^8.3.2" @@ -5760,6 +5761,28 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "engines": { + "node": ">=4" + } + }, "node_modules/is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -8818,6 +8841,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/remark-breaks": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/remark-breaks/-/remark-breaks-2.0.2.tgz", + "integrity": "sha512-LsQnPPQ7Fzp9RTjj4IwdEmjPOr9bxe9zYKWhs9ZQOg9hMg8rOfeeqQ410cvVdIK87Famqza1CKRxNkepp2EvUA==", + "dependencies": { + "unist-util-visit": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/remark-parse": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/remark-parse/-/remark-parse-9.0.0.tgz", @@ -9471,28 +9506,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/unified/node_modules/is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "engines": { - "node": ">=4" - } - }, "node_modules/unist-builder": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/unist-builder/-/unist-builder-2.0.3.tgz", @@ -9647,28 +9660,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/vfile/node_modules/is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "engines": { - "node": ">=4" - } - }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -14183,6 +14174,11 @@ "has-tostringtag": "^1.0.0" } }, + "is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" + }, "is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -16455,6 +16451,14 @@ "functions-have-names": "^1.2.2" } }, + "remark-breaks": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/remark-breaks/-/remark-breaks-2.0.2.tgz", + "integrity": "sha512-LsQnPPQ7Fzp9RTjj4IwdEmjPOr9bxe9zYKWhs9ZQOg9hMg8rOfeeqQ410cvVdIK87Famqza1CKRxNkepp2EvUA==", + "requires": { + "unist-util-visit": "^2.0.0" + } + }, "remark-parse": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/remark-parse/-/remark-parse-9.0.0.tgz", @@ -16937,13 +16941,6 @@ "is-plain-obj": "^2.0.0", "trough": "^1.0.0", "vfile": "^4.0.0" - }, - "dependencies": { - "is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" - } } }, "unist-builder": { @@ -17051,13 +17048,6 @@ "is-buffer": "^2.0.0", "unist-util-stringify-position": "^2.0.0", "vfile-message": "^2.0.0" - }, - "dependencies": { - "is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" - } } }, "vfile-message": { diff --git a/package.json b/package.json index 1d5c685e..efa28692 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ukhomeoffice/asl-components", - "version": "12.1.0", + "version": "13.0.0", "description": "React components for ASL layouts and elements", "main": "src/index.jsx", "styles": "styles/index.scss", @@ -39,6 +39,7 @@ "qs": "^6.6.1", "react": "^16.9.0", "react-markdown": "^6.0.2", + "remark-breaks": "^2.0.2", "react-redux": "^7.1.0", "redux": "^4.0.1", "shasum": "^1.0.2", diff --git a/src/conditions/index.jsx b/src/conditions/index.jsx index f1257bb1..1c8c9fcd 100644 --- a/src/conditions/index.jsx +++ b/src/conditions/index.jsx @@ -68,7 +68,7 @@ function Conditions({ { conditions && - { tempCondition } + { tempCondition } } diff --git a/src/markdown/index.jsx b/src/markdown/index.jsx index 15db4ffc..f512a336 100644 --- a/src/markdown/index.jsx +++ b/src/markdown/index.jsx @@ -1,6 +1,7 @@ /* eslint-disable react/display-name */ import React, { Fragment } from 'react'; import ReactMarkdown from 'react-markdown'; +import remarkBreaks from 'remark-breaks'; function RenderLink({ href, children }) { return [{ children }]({ href }); @@ -14,13 +15,6 @@ const components = { linkReference: RenderLinkReference }; -const trim = str => { - if (typeof str === 'string') { - return str.split('\n').map(s => s.trim()).join('\n').trim(); - } - return str; -}; - // eslint-disable-next-line no-unused-vars const wrapInSpanIfOnlyChild = enabled => ({ node, siblingCount, index, ...props }) => { if (enabled && siblingCount === 1) { @@ -29,16 +23,23 @@ const wrapInSpanIfOnlyChild = enabled => ({ node, siblingCount, index, ...props return

; }; -export default function Markdown({ children, links = false, unwrapSingleLine = false, source, ...props }) { - +export default function Markdown({ + children, + links = false, + unwrapSingleLine = false, + significantLineBreaks = false, + source, + ...props +}) { return - { trim(source || children) } + { source || children } ; } diff --git a/src/snippet/index.spec.jsx b/src/snippet/index.spec.jsx index e3159510..10fe9312 100644 --- a/src/snippet/index.spec.jsx +++ b/src/snippet/index.spec.jsx @@ -16,11 +16,11 @@ describe('', () => { const content = { string: 'one line', list: `* one - * two - * three`, +* two +* three`, paragraphs: `one - two` +two` }; test('does not include a wrapping element on single line input', () => {