<commit_before>package org.xcolab.util.html;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Entities;
import org.jsoup.safety.Cleaner;
import org.jsoup.safety.Whitelist;
import org.nibor.autolink.LinkExtractor;
import org.nibor.autolink.LinkSpan;
import org.nibor.autolink.LinkType;

import java.util.EnumSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Utility class to sanitize and format HTML inputs.
 */
public final class HtmlUtil {

    private static final String EXISTING_LINKS_REGEX = "(<a[^>]*>[^<]*</a>|<img[^>]*>|<a[^>]*>)";
    private static final Pattern existingLinksPattern = Pattern.compile(EXISTING_LINKS_REGEX);

    private HtmlUtil() { }

    /**
     * Removes all html form the input string
     * @param text unsafe input
     * @return input string without any html tags
     */
    public static String cleanAll(String text) {
        return clean(text, Whitelist.none(), "");
    }

    /**
     * Removes unsafe and structural html from the input string
     * @param text unsafe input
     * @return input string without dangerous and structural html tags
     */<commit_msg>[COLAB-2088] fixed regex to work with nested tags<commit_after>package org.xcolab.util.html;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Entities;
import org.jsoup.safety.Cleaner;
import org.jsoup.safety.Whitelist;
import org.nibor.autolink.LinkExtractor;
import org.nibor.autolink.LinkSpan;
import org.nibor.autolink.LinkType;

import java.util.EnumSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Utility class to sanitize and format HTML inputs.
 */
public final class HtmlUtil {

    private static final String EXISTING_LINKS_REGEX = "(<a[^>]*>.*?</a>|<img[^>]*>|<a[^>]*>)";
    private static final Pattern existingLinksPattern = Pattern.compile(EXISTING_LINKS_REGEX);

    private HtmlUtil() { }

    /**
     * Removes all html form the input string
     * @param text unsafe input
     * @return input string without any html tags
     */
    public static String cleanAll(String text) {
        return clean(text, Whitelist.none(), "");
    }

    /**
     * Removes unsafe and structural html from the input string
     * @param text unsafe input
     * @return input string without dangerous and structural html tags
     */
{'fraction_non_alphanumeric': 0.11547256097560976, 'fraction_numerical': 0.0022865853658536584, 'mean_word_length': 3.861111111111111, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, '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': '4233512', 'n_tokens_mistral': 842, 'n_tokens_neox': 811, 'n_words': 215}