From 8c8219f8c3d6beb4bab030f9b50caeb0eeffc32a Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 24 Aug 2023 07:39:17 +0200 Subject: [PATCH] linebreaks in tech attribution --- resources/js/components/techniques/Detail.js | 3 ++- resources/js/helpers/nl2br.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 resources/js/helpers/nl2br.js diff --git a/resources/js/components/techniques/Detail.js b/resources/js/components/techniques/Detail.js index 8d5136d..376a391 100644 --- a/resources/js/components/techniques/Detail.js +++ b/resources/js/components/techniques/Detail.js @@ -9,6 +9,7 @@ import Requirements from './Requirements'; import Rulesets from './Rulesets'; import Icon from '../common/Icon'; import RawHTML from '../common/RawHTML'; +import nl2br from '../../helpers/nl2br'; import { getRelations, getTranslation, @@ -72,7 +73,7 @@ const Detail = ({ actions, technique }) => { : null} {getTranslation(technique, 'attribution', i18n.language) ? - + {nl2br(getTranslation(technique, 'attribution', i18n.language))} : null} ; diff --git a/resources/js/helpers/nl2br.js b/resources/js/helpers/nl2br.js new file mode 100644 index 0000000..60d695a --- /dev/null +++ b/resources/js/helpers/nl2br.js @@ -0,0 +1,16 @@ +import React from 'react'; + +const nl2br = str => { + if (typeof str !== 'string') { + return str; + } + const nl = /(\r\n|\r|\n)/g; + return str.split(nl).map((line, index) => { + if (line.match(nl)) { + return
; + } + return line; + }); +}; + +export default nl2br; -- 2.39.2