diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-09-09 14:59:10 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-09-14 09:19:26 -0400 |
commit | 2d2939576cce38b3f4517d243d51dd6998eda42f (patch) | |
tree | bba5b1aad240201b37783a5e4210fa1b09fb23f4 /web/react/utils | |
parent | c3742aef71801544172cf77a46d52835594096a4 (diff) | |
download | chat-2d2939576cce38b3f4517d243d51dd6998eda42f.tar.gz chat-2d2939576cce38b3f4517d243d51dd6998eda42f.tar.bz2 chat-2d2939576cce38b3f4517d243d51dd6998eda42f.zip |
Added skeleton for new text formatting code which will replace textToJsx
Diffstat (limited to 'web/react/utils')
-rw-r--r-- | web/react/utils/text_formatting.jsx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx new file mode 100644 index 000000000..2e1416d1d --- /dev/null +++ b/web/react/utils/text_formatting.jsx @@ -0,0 +1,36 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +const Constants = require('../utils/constants.jsx'); +const UserStore = require('../stores/user_store.jsx'); + +export function formatText(text, options = {}) { + let output = sanitize(text); + + // TODO autolink @mentions + // TODO highlight mentions of self + // TODO autolink urls + // TODO highlight search terms + // TODO autolink hashtags + + // TODO leave space for markdown + + if (options.singleline) { + output = output.replace('\n', ' '); + } else { + output = output.replace('\n', '<br />'); + } + + return output; +} + +export function sanitize(text) { + let output = text; + + // normal string.replace only does a single occurrance so use a regex instead + output = output.replace(/&/g, '&'); + output = output.replace(/</g, '<'); + output = output.replace(/>/g, '>'); + + return output; +} |