From c19ce094ec58dc93eb2236a9e83a1bbd6cf70370 Mon Sep 17 00:00:00 2001 From: Julian Steinwachs Date: Thu, 28 Jan 2016 20:08:52 +0100 Subject: [PATCH] wysiwyg markout, yey --- build/app-bundle.js | 21 ++++++++++++++++++++- css/main.css | 7 +++++++ jsx/common/PostComposer.js | 21 ++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/build/app-bundle.js b/build/app-bundle.js index 29f3a0a..d4e81a7 100644 --- a/build/app-bundle.js +++ b/build/app-bundle.js @@ -979,9 +979,28 @@ module.exports = PostComposer = React.createClass({displayName: "PostComposer", output+=(''+item.raw+''); break; default: - output+=(''+item.raw+''); + output+=(item.raw); } }); + + var rules = [ + {regex: /\[([^\[]+)\]\(([^\)]+)\)/g, + replacement: '[$1]($2)'}, // hyperlink + {regex: /(\s?)(\*)(.*?)(\*)(\s?)/g, + replacement: '$1*$3*$5'}, // emphasis + {regex: /(\s?)(\~)(.*?)(\~)(\s?)/g, + replacement: '$1~$3~$5'}, // emphasis + {regex: /(\s?)(\-)(.*?)(\-)(\s?)/g, + replacement: '$1-$3-$5'}, // emphasis + {regex: /(\s?)(\_)(.*?)(\_)(\s?)/g, + replacement: '$1_$3_$5'}, // emphasis + ] + + rules.forEach(function (rule) { + output = output.replace(rule.regex, rule.replacement); + }); + + console.log(text.slice(0, this.state.maxLength),output) // text overflow if (text.length > this.state.maxLength) { diff --git a/css/main.css b/css/main.css index 799319d..33f329f 100755 --- a/css/main.css +++ b/css/main.css @@ -100,4 +100,11 @@ body.modal-open { vertical-align: text-top; margin-left: 0.25em; margin-right: 0.125em; +} + +.ghost { + display: inline-block; + width: 0; + overflow: hidden; + height: 0; } \ No newline at end of file diff --git a/jsx/common/PostComposer.js b/jsx/common/PostComposer.js index 743a653..361a37d 100644 --- a/jsx/common/PostComposer.js +++ b/jsx/common/PostComposer.js @@ -162,9 +162,28 @@ module.exports = PostComposer = React.createClass({ output+=(''+item.raw+''); break; default: - output+=(''+item.raw+''); + output+=(item.raw); } }); + + var rules = [ + {regex: /\[([^\[]+)\]\(([^\)]+)\)/g, + replacement: '[$1]($2)'}, // hyperlink + {regex: /(\s?)(\*)(.*?)(\*)(\s?)/g, + replacement: '$1*$3*$5'}, // emphasis + {regex: /(\s?)(\~)(.*?)(\~)(\s?)/g, + replacement: '$1~$3~$5'}, // emphasis + {regex: /(\s?)(\-)(.*?)(\-)(\s?)/g, + replacement: '$1-$3-$5'}, // emphasis + {regex: /(\s?)(\_)(.*?)(\_)(\s?)/g, + replacement: '$1_$3_$5'}, // emphasis + ] + + rules.forEach(function (rule) { + output = output.replace(rule.regex, rule.replacement); + }); + + console.log(text.slice(0, this.state.maxLength),output) // text overflow if (text.length > this.state.maxLength) {