<commit_before>import React from 'react';
import truncatise from 'truncatise';
import { Utils } from 'meteor/vulcan:core';

const highlightMaxChars = 2400;
export const excerptMaxChars = 700;
export const postExcerptMaxChars = 600;

export const highlightFromMarkdown = (body, mdi) => {
  const html = mdi.render(body);
  return highlightFromHTML(html);
}

export const highlightFromHTML = (html) => {
  return Utils.sanitize(truncatise(html, {
    TruncateLength: highlightMaxChars,
    TruncateBy: "characters",
    Suffix: "...",
  }));
};

export const truncate = (html, truncateLength) => {
  return Utils.sanitize(truncatise(html, {
    TruncateLength: Math.floor(truncateLength - (truncateLength/4)) || truncateLength,
    TruncateBy: "characters",
    Suffix: "...",
  }));
}

export const postExcerptFromHTML = (html, truncationCharCount) => {
  if(!html) return ""
  const styles = html.match(/<style[\s\S]*?<\/style>/g) || ""
  const htmlRemovedStyles = html.replace(/<style[\s\S]*?<\/style>/g, '');

  return Utils.sanitize(truncatise(htmlRemovedStyles, {
    TruncateLength: truncationCharCount || postExcerptMaxChars,
    TruncateBy: "characters",
    Suffix: `... <a class="read-more-default">(Read more)</a>${styles}`,
  }));
};

export const commentExcerptFromHTML = (html, truncationCharCount) => {
  if(!html) return ""
  const styles = html.match(/<style[\s\S]*?<\/style>/g) || ""
  const htmlRemovedStyles = html.replace(/<style[\s\S]*?<\/style>/g, '');

  return Utils.sanitize(truncatise(htmlRemovedStyles, {
    // We want the amount comments get truncated to to be less than the threshold at which they are truncated, so that users don't have the experience of expanding a comment only to see a couple more words (which just feels silly).

    // This varies by the size of the comment or truncation amount, and reducing it by 1/4th seems about right.
    TruncateLength: Math.floor(truncationCharCount - (truncationCharCount/4)) || excerptMaxChars,
    TruncateBy: "characters",
    Suffix: `... <span class="read-more"><a class="read-more-default">(Read more)</a><a class="read-more-tooltip">(Click to expand thread)</a><span class="read-more-f-tooltip">Cmd/Ctrl F to expand all comments on this post</span></span>${styles}`,
  }));
};

export const excerptFromMarkdown = (body, mdi) => {
  const html = mdi.render(body);
  return commentExcerptFromHTML(html);<commit_msg>Remove all the useless sanitization in ellipsize.jsx<commit_after>import React from 'react';
import truncatise from 'truncatise';
import { Utils } from 'meteor/vulcan:core';

const highlightMaxChars = 2400;
export const excerptMaxChars = 700;
export const postExcerptMaxChars = 600;

export const highlightFromMarkdown = (body, mdi) => {
  const html = mdi.render(body);
  return highlightFromHTML(html);
}

export const highlightFromHTML = (html) => {
  return truncatise(html, {
    TruncateLength: highlightMaxChars,
    TruncateBy: "characters",
    Suffix: "...",
  });
};

export const truncate = (html, truncateLength) => {
  return truncatise(html, {
    TruncateLength: Math.floor(truncateLength - (truncateLength/4)) || truncateLength,
    TruncateBy: "characters",
    Suffix: "...",
  });
}

export const postExcerptFromHTML = (html, truncationCharCount) => {
  if(!html) return ""
  const styles = html.match(/<style[\s\S]*?<\/style>/g) || ""
  const htmlRemovedStyles = html.replace(/<style[\s\S]*?<\/style>/g, '');

  return truncatise(htmlRemovedStyles, {
    TruncateLength: truncationCharCount || postExcerptMaxChars,
    TruncateBy: "characters",
    Suffix: `... <a class="read-more-default">(Read more)</a>${styles}`,
  });
};

export const commentExcerptFromHTML = (html, truncationCharCount) => {
  if(!html) return ""
  const styles = html.match(/<style[\s\S]*?<\/style>/g) || ""
  const htmlRemovedStyles = html.replace(/<style[\s\S]*?<\/style>/g, '');

  return truncatise(htmlRemovedStyles, {
    // We want the amount comments get truncated to to be less than the threshold at which they are truncated, so that users don't have the experience of expanding a comment only to see a couple more words (which just feels silly).

    // This varies by the size of the comment or truncation amount, and reducing it by 1/4th seems about right.
    TruncateLength: Math.floor(truncationCharCount - (truncationCharCount/4)) || excerptMaxChars,
    TruncateBy: "characters",
    Suffix: `... <span class="read-more"><a class="read-more-default">(Read more)</a><a class="read-more-tooltip">(Click to expand thread)</a><span class="read-more-f-tooltip">Cmd/Ctrl F to expand all comments on this post</span></span>${styles}`,
  });
};

export const excerptFromMarkdown = (body, mdi) => {
  const html = mdi.render(body);
  return commentExcerptFromHTML(html);
{'fraction_non_alphanumeric': 0.15021998742928974, 'fraction_numerical': 0.005866331447726796, 'mean_word_length': 4.538283062645012, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7238804', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1514, 'n_words': 387}