<commit_before>from __future__ import unicode_literals
import frappe
import json, re
import bleach, bleach_whitelist.bleach_whitelist as bleach_whitelist
from six import string_types
from bs4 import BeautifulSoup

def clean_html(html):
	if not isinstance(html, string_types):
		return html

	return bleach.clean(clean_script_and_style(html),
		tags=['div', 'p', 'br', 'ul', 'ol', 'li', 'strong', 'b', 'em', 'i', 'u',
			'table', 'thead', 'tbody', 'td', 'tr'],
		attributes=[],
		styles=['color', 'border', 'border-color'],
		strip=True, strip_comments=True)

def clean_email_html(html):
	if not isinstance(html, string_types):
		return html

	return bleach.clean(clean_script_and_style(html),
		tags=['div', 'p', 'br', 'ul', 'ol', 'li', 'strong', 'b', 'em', 'i', 'u', 'a',
			'table', 'thead', 'tbody', 'td', 'tr', 'th', 'pre', 'code',
			'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'button', 'img'],
		attributes=['border', 'colspan', 'rowspan',
			'src', 'href', 'style', 'id'],
		styles=['color', 'border-color', 'width', 'height', 'max-width',
			'background-color', 'border-collapse', 'border-radius',
			'border', 'border-top', 'border-bottom', 'border-left', 'border-right',
			'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right',
			'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
			'font-size', 'font-weight', 'font-family', 'text-decoration',
			'line-height', 'text-align', 'vertical-align'
		],
		protocols=['cid', 'http', 'https', 'mailto', 'data'],
		strip=True, strip_comments=True)

def clean_script_and_style(html):
	# remove script and style
	soup = BeautifulSoup(html, 'html5lib')
	for s in soup(['script', 'style']):
		s.decompose()<commit_msg>fix: display style removed from emails (bp #11963) (#11964)<commit_after>from __future__ import unicode_literals
import frappe
import json, re
import bleach, bleach_whitelist.bleach_whitelist as bleach_whitelist
from six import string_types
from bs4 import BeautifulSoup

def clean_html(html):
	if not isinstance(html, string_types):
		return html

	return bleach.clean(clean_script_and_style(html),
		tags=['div', 'p', 'br', 'ul', 'ol', 'li', 'strong', 'b', 'em', 'i', 'u',
			'table', 'thead', 'tbody', 'td', 'tr'],
		attributes=[],
		styles=['color', 'border', 'border-color'],
		strip=True, strip_comments=True)

def clean_email_html(html):
	if not isinstance(html, string_types):
		return html

	return bleach.clean(clean_script_and_style(html),
		tags=['div', 'p', 'br', 'ul', 'ol', 'li', 'strong', 'b', 'em', 'i', 'u', 'a',
			'table', 'thead', 'tbody', 'td', 'tr', 'th', 'pre', 'code',
			'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'button', 'img'],
		attributes=['border', 'colspan', 'rowspan',
			'src', 'href', 'style', 'id'],
		styles=['color', 'border-color', 'width', 'height', 'max-width',
			'background-color', 'border-collapse', 'border-radius',
			'border', 'border-top', 'border-bottom', 'border-left', 'border-right',
			'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right',
			'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
			'font-size', 'font-weight', 'font-family', 'text-decoration',
			'line-height', 'text-align', 'vertical-align', 'display'
		],
		protocols=['cid', 'http', 'https', 'mailto', 'data'],
		strip=True, strip_comments=True)

def clean_script_and_style(html):
	# remove script and style
	soup = BeautifulSoup(html, 'html5lib')
	for s in soup(['script', 'style']):
		s.decompose()
{'fraction_non_alphanumeric': 0.21920969137582924, 'fraction_numerical': 0.0074992789154888955, 'mean_word_length': 5.8, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3277626', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1250, 'n_words': 310}