From: Daniel Karbach Date: Thu, 24 Aug 2023 05:39:17 +0000 (+0200) Subject: linebreaks in tech attribution X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=8c8219f8c3d6beb4bab030f9b50caeb0eeffc32a;hp=19bdadf13c1632fc312f5539a2b2cee8282b5dcb;p=alttp.git linebreaks in tech attribution --- 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;