mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
37 lines
952 B
React
37 lines
952 B
React
|
|
// 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;
|
||
|
|
}
|