From bedf9e4583bcac246c0dfabee8ef2b93bdf810d3 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 27 Nov 2018 20:33:41 +1100 Subject: [PATCH] Added Hyperlink support to Content. --- public/objects/content/Content.jsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/public/objects/content/Content.jsx b/public/objects/content/Content.jsx index dc40f7b..d4de545 100644 --- a/public/objects/content/Content.jsx +++ b/public/objects/content/Content.jsx @@ -26,11 +26,24 @@ import { Paragraph } from './../typography/Typography'; const DoLine = content => { //TODO: Support things like hyperlinks etc. - return { content } + let parts = []; + let currentBuffer = ``; + let bits = content.split(' '); + for(let i = 0; i < bits.length; i++) { + let s = bits[i]; + if(s.startsWith('https://') || s.startsWith('http://')) { + parts.push({ s }); + } else { + parts.push(s); + } + if(i < (bits.length-1)) parts.push(' '); + } + return { parts } }; -const DoNewline = content => { DoLine(content) }
; -const DoParagraph = content => DoNewline(e)) } />; +const DoParagraph = content => { + return { DoLine(e) }
+})} />; export default props => { let { content, children } = props; @@ -38,7 +51,9 @@ export default props => { return ( - { content.split('\n\n').map(e => DoParagraph(e)) } + { content.split('\n\n').map(e => { + return { DoParagraph(e) } + }) } ); };