mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Removed textToJsx!
This commit is contained in:
@@ -434,205 +434,6 @@ export function searchForTerm(term) {
|
||||
});
|
||||
}
|
||||
|
||||
var puncStartRegex = /^((?![@#])\W)+/g;
|
||||
var puncEndRegex = /(\W)+$/g;
|
||||
|
||||
export function textToJsx(textin, options) {
|
||||
var text = textin;
|
||||
if (options && options.singleline) {
|
||||
var repRegex = new RegExp('\n', 'g'); //eslint-disable-line no-control-regex
|
||||
text = text.replace(repRegex, ' ');
|
||||
}
|
||||
|
||||
var searchTerm = '';
|
||||
if (options && options.searchTerm) {
|
||||
searchTerm = options.searchTerm.toLowerCase();
|
||||
}
|
||||
|
||||
var mentionClass = 'mention-highlight';
|
||||
if (options && options.noMentionHighlight) {
|
||||
mentionClass = '';
|
||||
}
|
||||
|
||||
var inner = [];
|
||||
|
||||
// Function specific regex
|
||||
var hashRegex = /^href="#[^']+"|(^#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$/g;
|
||||
|
||||
var implicitKeywords = UserStore.getCurrentMentionKeys();
|
||||
|
||||
var lines = text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
var words = line.split(' ');
|
||||
var highlightSearchClass = '';
|
||||
for (let z = 0; z < words.length; z++) {
|
||||
var word = words[z];
|
||||
var trimWord = word.replace(puncStartRegex, '').replace(puncEndRegex, '').trim();
|
||||
var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
|
||||
var explicitMention = mentionRegex.exec(trimWord);
|
||||
|
||||
if (searchTerm !== '') {
|
||||
let searchWords = searchTerm.split(' ');
|
||||
for (let idx in searchWords) {
|
||||
if ({}.hasOwnProperty.call(searchWords, idx)) {
|
||||
let searchWord = searchWords[idx];
|
||||
if (searchWord === word.toLowerCase() || searchWord === trimWord.toLowerCase()) {
|
||||
highlightSearchClass = ' search-highlight';
|
||||
break;
|
||||
} else if (searchWord.charAt(searchWord.length - 1) === '*') {
|
||||
let searchWordPrefix = searchWord.slice(0, -1);
|
||||
if (trimWord.toLowerCase().indexOf(searchWordPrefix) > -1 || word.toLowerCase().indexOf(searchWordPrefix) > -1) {
|
||||
highlightSearchClass = ' search-highlight';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitMention &&
|
||||
(UserStore.getProfileByUsername(explicitMention[1]) ||
|
||||
Constants.SPECIAL_MENTIONS.indexOf(explicitMention[1]) !== -1)) {
|
||||
let name = explicitMention[1];
|
||||
|
||||
// do both a non-case sensitive and case senstive check
|
||||
let mClass = '';
|
||||
if (implicitKeywords.indexOf('@' + name.toLowerCase()) !== -1 || implicitKeywords.indexOf('@' + name) !== -1) {
|
||||
mClass = mentionClass;
|
||||
}
|
||||
|
||||
let suffix = word.match(puncEndRegex);
|
||||
let prefix = word.match(puncStartRegex);
|
||||
|
||||
if (searchTerm === name) {
|
||||
highlightSearchClass = ' search-highlight';
|
||||
}
|
||||
|
||||
inner.push(
|
||||
<span key={name + i + z + '_span'}>
|
||||
{prefix}
|
||||
<a
|
||||
className={mClass + highlightSearchClass + ' mention-link'}
|
||||
key={name + i + z + '_link'}
|
||||
href='#'
|
||||
onClick={() => searchForTerm(name)} //eslint-disable-line no-loop-func
|
||||
>
|
||||
@{name}
|
||||
</a>
|
||||
{suffix}
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
} else if (testUrlMatch(word).length) {
|
||||
let match = testUrlMatch(word)[0];
|
||||
let link = match.link;
|
||||
|
||||
let prefix = word.substring(0, word.indexOf(match.text));
|
||||
let suffix = word.substring(word.indexOf(match.text) + match.text.length);
|
||||
|
||||
inner.push(
|
||||
<span key={word + i + z + '_span'}>
|
||||
{prefix}
|
||||
<a
|
||||
key={word + i + z + '_link'}
|
||||
className={'theme' + highlightSearchClass}
|
||||
target='_blank'
|
||||
href={link}
|
||||
>
|
||||
{match.text}
|
||||
</a>
|
||||
{suffix}
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
} else if (trimWord.match(hashRegex)) {
|
||||
let suffix = word.match(puncEndRegex);
|
||||
let prefix = word.match(puncStartRegex);
|
||||
let mClass = '';
|
||||
if (implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1) {
|
||||
mClass = mentionClass;
|
||||
}
|
||||
|
||||
if (searchTerm === trimWord.substring(1).toLowerCase() || searchTerm === trimWord.toLowerCase()) {
|
||||
highlightSearchClass = ' search-highlight';
|
||||
}
|
||||
|
||||
inner.push(
|
||||
<span key={word + i + z + '_span'}>
|
||||
{prefix}
|
||||
<a
|
||||
key={word + i + z + '_hash'}
|
||||
className={'theme ' + mClass + highlightSearchClass}
|
||||
href='#'
|
||||
onClick={searchForTerm.bind(this, trimWord)} //eslint-disable-line no-loop-func
|
||||
>
|
||||
{trimWord}
|
||||
</a>
|
||||
{suffix}
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
} else if (implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1) {
|
||||
let suffix = word.match(puncEndRegex);
|
||||
let prefix = word.match(puncStartRegex);
|
||||
|
||||
if (trimWord.charAt(0) === '@') {
|
||||
if (searchTerm === trimWord.substring(1).toLowerCase()) {
|
||||
highlightSearchClass = ' search-highlight';
|
||||
}
|
||||
inner.push(
|
||||
<span key={word + i + z + '_span'}>
|
||||
{prefix}
|
||||
<a
|
||||
className={mentionClass + highlightSearchClass}
|
||||
key={name + i + z + '_link'}
|
||||
href='#'
|
||||
>
|
||||
{trimWord}
|
||||
</a>
|
||||
{suffix}
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
inner.push(
|
||||
<span key={word + i + z + '_span'}>
|
||||
{prefix}
|
||||
<span className={mentionClass + highlightSearchClass}>
|
||||
{replaceHtmlEntities(trimWord)}
|
||||
</span>
|
||||
{suffix}
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
} else if (word === '') {
|
||||
|
||||
// if word is empty dont include a span
|
||||
|
||||
} else {
|
||||
inner.push(
|
||||
<span key={word + i + z + '_span'}>
|
||||
<span className={highlightSearchClass}>
|
||||
{replaceHtmlEntities(word)}
|
||||
</span>
|
||||
{' '}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
highlightSearchClass = '';
|
||||
}
|
||||
if (i !== lines.length - 1) {
|
||||
inner.push(
|
||||
<br key={'br_' + i}/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return inner;
|
||||
}
|
||||
|
||||
export function getFileType(extin) {
|
||||
var ext = extin.toLowerCase();
|
||||
if (Constants.IMAGE_TYPES.indexOf(ext) > -1) {
|
||||
|
||||
Reference in New Issue
Block a user