Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output = output.replace(//g, '>');
output = output.replace(/'/g, ''');
output = output.replace(/"/g, '"');
return output;
}
// Copied from our fork of commonmark.js
var emailAlphaNumericChars = '\\p{L}\\p{Nd}';
var emailSpecialCharacters = '!#$%&\'*+\\-\\/=?^_`{|}~';
var emailRestrictedSpecialCharacters = '\\s(),:;<>@\\[\\]';
var emailValidCharacters = emailAlphaNumericChars + emailSpecialCharacters;
var emailValidRestrictedCharacters = emailValidCharacters + emailRestrictedSpecialCharacters;
var emailStartPattern = '(?:[' + emailValidCharacters + '](?:[' + emailValidCharacters + ']|\\.(?!\\.|@))*|\\"[' + emailValidRestrictedCharacters + '.]+\\")@';
var reEmail = XRegExp.cache('(^|[^\\pL\\d])(' + emailStartPattern + '[\\pL\\d.\\-]+[.]\\pL{2,4}(?=$|[^\\p{L}]))', 'g');
// Convert emails into tokens
function autolinkEmails(text, tokens) {
function replaceEmailWithToken(fullMatch, prefix, email) {
const index = tokens.size;
const alias = `$MM_EMAIL${index}$`;
tokens.set(alias, {
value: `<a href="mailto:${email}" class="theme">${email}</a>`,
originalText: email,
});
return prefix + alias;
}
let output = text;
if (originalText.length < minimumHashtagLength + 1) {
// too short to be a hashtag
return fullMatch;
}
tokens.set(alias, {
value: `<a data-hashtag="${originalText}" href="#" class="mention-link">${originalText}</a>`,
originalText,
hashtag: originalText.substring(1),
});
return prefix + alias;
}
return output.replace(XRegExp.cache('(^|\\W)(#\\pL[\\pL\\d\\-_.]*[\\pL\\d])', 'g'), replaceHashtagWithToken);
}
handlePretextChanged(pretext, resultCallback) {
const captured = XRegExp.cache('(?:^|\\W)@([\\pL\\d\\-_.]*)$', 'i').exec(pretext.toLowerCase());
if (!captured) {
return false;
}
const prefix = captured[1];
this.startNewRequest(prefix);
this.updateMatches(resultCallback, this.users());
// If we haven't gotten server-side results in 500 ms, add the loading indicator.
let showLoadingIndicator = setTimeout(() => {
if (this.shouldCancelDispatch(prefix)) {
return;
}
this.updateMatches(resultCallback, this.users().concat([{
}
tokens.set(alias, {
value: `<a data-hashtag="${originalText}" href="#" class="mention-link">${originalText}</a>`,
originalText,
hashtag: originalText.substring(1),
});
return prefix + alias;
}
return output.replace(XRegExp.cache('(^|\\W)(#\\pL[\\pL\\d\\-_.]*[\\pL\\d])', 'g'), replaceHashtagWithToken);
}
const puncStart = XRegExp.cache('^[^\\pL\\d\\s#]+');
const puncEnd = XRegExp.cache('[^\\pL\\d\\s]+$');
function parseSearchTerms(searchTerm) {
let terms = [];
let termString = searchTerm;
while (termString) {
let captured;
// check for a quoted string
captured = (/^"([^"]*)"/).exec(termString);
if (captured) {
termString = termString.substring(captured[0].length);
if (captured[1].length > 0) {
terms.push(captured[1]);
return fullMatch;
}
tokens.set(alias, {
value: `<a data-hashtag="${originalText}" href="#" class="mention-link">${originalText}</a>`,
originalText,
hashtag: originalText.substring(1),
});
return prefix + alias;
}
return output.replace(XRegExp.cache('(^|\\W)(#\\pL[\\pL\\d\\-_.]*[\\pL\\d])', 'g'), replaceHashtagWithToken);
}
const puncStart = XRegExp.cache('^[^\\pL\\d\\s#]+');
const puncEnd = XRegExp.cache('[^\\pL\\d\\s]+$');
function parseSearchTerms(searchTerm) {
let terms = [];
let termString = searchTerm;
while (termString) {
let captured;
// check for a quoted string
captured = (/^"([^"]*)"/).exec(termString);
if (captured) {
termString = termString.substring(captured[0].length);
if (captured[1].length > 0) {
let $
try {
$ = cheerio.load(body)
} catch (e) {
throw new Error('Error loading DOM', e)
}
const idRegex = 'station=(\\d*)'
const titleRegex = '^(([\\p{L}0-9-]*[\\s-]?)*)\\s-'
const stations = []
const hrefs = $('.listtable td a:contains(\'A\')')
for (let i = 0; i < hrefs.length; i++) {
const elem = $(hrefs[i])
// get the station title and id
const titleMatch = xregexp.cache(titleRegex).exec(elem.attr('title'))
const idMatch = xregexp.cache(idRegex).exec(elem.attr('href'))
if (!idMatch || !titleMatch) {
throw new Error('Parsing error -- Source is changed')
}
stations.push({
name: titleMatch[1],
id: idMatch[1],
})
}
return res.cache(86400).json({ results: stations })
})
})
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import XRegExp from 'xregexp';
import {getEmojiImageUrl} from 'mattermost-redux/utils/emoji_utils';
import emojiRegex from 'emoji-regex';
import {formatWithRenderer} from 'utils/markdown';
import {getEmojiMap} from 'selectors/emojis';
import store from 'stores/redux_store.jsx';
import * as Emoticons from './emoticons.jsx';
import * as Markdown from './markdown';
const punctuation = XRegExp.cache('[^\\pL\\d]');
const AT_MENTION_PATTERN = /\B@([a-z0-9.\-_]*)/gi;
const UNICODE_EMOJI_REGEX = emojiRegex();
const htmlEmojiPattern = /^<p>\s*(?:<img class="emoticon">]*>|<span>]*>[^<]*<\/span>\s*|<span class="emoticon emoticon--unicode">[^<]*<\/span>\s*)+<\/p>$/;
// pattern to detect the existence of a Chinese, Japanese, or Korean character in a string
// http://stackoverflow.com/questions/15033196/using-javascript-to-check-whether-a-string-contains-japanese-characters-includi
const cjkPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf\uac00-\ud7a3]/;
// Performs formatting of user posts including highlighting mentions and search terms and converting urls, hashtags,
// @mentions and ~channels to links by taking a user's message and returning a string of formatted html. Also takes
// a number of options as part of the second parameter:
// - searchTerm - If specified, this word is highlighted in the resulting html. Defaults to nothing.
// - searchMatches - If specified, an array of words that will be highlighted. Defaults to nothing. If both
// this and searchTerm are specified, this takes precedence.
// - mentionHighlight - Specifies whether or not to highlight mentions of the current user. Defaults to true.</span></span></p>
let $
try {
$ = cheerio.load(body)
} catch (e) {
throw new Error('Error loading DOM', e)
}
const idRegex = 'station=(\\d*)'
const titleRegex = '^(([\\p{L}0-9-]*[\\s-]?)*)\\s-'
const stations = []
const hrefs = $('.listtable td a:contains(\'A\')')
for (let i = 0; i < hrefs.length; i++) {
const elem = $(hrefs[i])
// get the station title and id
const titleMatch = xregexp.cache(titleRegex).exec(elem.attr('title'))
const idMatch = xregexp.cache(idRegex).exec(elem.attr('href'))
if (!idMatch || !titleMatch) {
throw new Error('Parsing error -- Source is changed')
}
stations.push({
name: titleMatch[1],
id: idMatch[1],
})
}
return res.cache(86400).json({ results: stations })
})
})