]> git.localhorst.tv Git - alttp.git/commitdiff
linebreaks in tech attribution
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 24 Aug 2023 05:39:17 +0000 (07:39 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 24 Aug 2023 05:39:17 +0000 (07:39 +0200)
resources/js/components/techniques/Detail.js
resources/js/helpers/nl2br.js [new file with mode: 0644]

index 8d5136dfc523c09e05efacfb99114b0912df2b07..376a391698d108addcae83a51bed98b7aac77488 100644 (file)
@@ -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) ?
                        <Alert variant="dark">
-                               <RawHTML html={getTranslation(technique, 'attribution', i18n.language)} />
+                               {nl2br(getTranslation(technique, 'attribution', i18n.language))}
                        </Alert>
                : null}
        </Container>;
diff --git a/resources/js/helpers/nl2br.js b/resources/js/helpers/nl2br.js
new file mode 100644 (file)
index 0000000..60d695a
--- /dev/null
@@ -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 <br key={index} />;
+               }
+               return line;
+       });
+};
+
+export default nl2br;