<commit_before>import { regexes } from './smileys';

/**
 * Processes links and smileys in "body"
 */
export function processReplacements(body) {
    // make links clickable + add smileys
    return smilify(linkify(body));
}

/**
 * Finds and replaces all links in the links in "body"
 * with their <a href=""></a>
 */
export function linkify(inputText) {
    let replacedText;

    /* eslint-disable no-useless-escape, max-len */

    // URLs starting with http://, https://, or ftp://
    const replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;

    replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>');

    // URLs starting with "www." (without // before it, or it'd re-link the ones done above).
    const replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;

    replacedText = replacedText.replace(replacePattern2, '$1<a href="https://$2" target="_blank" rel="noopener noreferrer">$2</a>');

    // Change email addresses to mailto: links.
    const replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;

    replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

    /* eslint-enable no-useless-escape */

    return replacedText;
}

/**
 * Replaces common smiley strings with images
 */
function smilify(body) {
    if (!body) {
        return body;
    }

    let formattedBody = body;

    for (const smiley in regexes) {
        if (regexes.hasOwnProperty(smiley)) {
            formattedBody = formattedBody.replace(regexes[smiley],
                `<img class="smiley" src="images/smileys/${smiley}.svg">`);
        }
    }

    return body;
}<commit_msg>fix(chat): return formatted body to show smileys<commit_after>import { regexes } from './smileys';

/**
 * Processes links and smileys in "body"
 */
export function processReplacements(body) {
    // make links clickable + add smileys
    return smilify(linkify(body));
}

/**
 * Finds and replaces all links in the links in "body"
 * with their <a href=""></a>
 */
export function linkify(inputText) {
    let replacedText;

    /* eslint-disable no-useless-escape, max-len */

    // URLs starting with http://, https://, or ftp://
    const replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;

    replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>');

    // URLs starting with "www." (without // before it, or it'd re-link the ones done above).
    const replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;

    replacedText = replacedText.replace(replacePattern2, '$1<a href="https://$2" target="_blank" rel="noopener noreferrer">$2</a>');

    // Change email addresses to mailto: links.
    const replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;

    replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

    /* eslint-enable no-useless-escape */

    return replacedText;
}

/**
 * Replaces common smiley strings with images
 */
function smilify(body) {
    if (!body) {
        return body;
    }

    let formattedBody = body;

    for (const smiley in regexes) {
        if (regexes.hasOwnProperty(smiley)) {
            formattedBody = formattedBody.replace(regexes[smiley],
                `<img class="smiley" src="images/smileys/${smiley}.svg">`);
        }
    }

    return formattedBody;
}
{'fraction_non_alphanumeric': 0.19639794168096056, 'fraction_numerical': 0.012006861063464836, 'mean_word_length': 3.0923976608187136, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5515838', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1210, 'n_words': 264}