<commit_before>// @flow
import htmlparser from 'htmlparser2'
import cssSelect from 'css-select'
export {cssSelect}

import {AllHtmlEntities} from 'html-entities'

export const entities = new AllHtmlEntities()

export function parseHtml(string: string): Object {
	return htmlparser.parseDOM(string, {
		withDomLvl1: true,
		normalizeWhitespace: false,
		xmlMode: false,
		decodeEntities: true,
	})
}

// from https://github.com/fb55/domutils/blob/master/lib/stringify.js
export function getText(elem: Object | Object[]): string {
	if (Array.isArray(elem)) return elem.map(getText).join('')
	if (elem.type === 'tag') return getText(elem.children)
	if (elem.type === 'text') return elem.data
	return ''
}

function getTextWithSpaces(elem: Object | Object[]): string {
	if (Array.isArray(elem)) return elem.map(getTextWithSpaces).join(' ')<commit_msg>html-lib: Update usage of htmlparser2<commit_after>// @flow
import htmlparser2 from 'htmlparser2'
import cssSelect from 'css-select'
export {cssSelect}

import {AllHtmlEntities} from 'html-entities'

export const entities = new AllHtmlEntities()

export function parseHtml(string: string): Object {
	return htmlparser2.parseDOM(string, {
		withDomLvl1: true,
		normalizeWhitespace: false,
		xmlMode: false,
		decodeEntities: true,
	})
}

// from https://github.com/fb55/domutils/blob/master/lib/stringify.js
export function getText(elem: Object | Object[]): string {
	if (Array.isArray(elem)) return elem.map(getText).join('')
	if (elem.type === 'tag') return getText(elem.children)
	if (elem.type === 'text') return elem.data
	return ''
}

function getTextWithSpaces(elem: Object | Object[]): string {
	if (Array.isArray(elem)) return elem.map(getTextWithSpaces).join(' ')
{'fraction_non_alphanumeric': 0.13953488372093023, 'fraction_numerical': 0.006395348837209302, 'mean_word_length': 5.518939393939394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '741001', 'n_tokens_mistral': 556, 'n_tokens_neox': 557, 'n_words': 140}