<commit_before>import Foundation

struct Plist2HTML {

	enum HTMLStyle: String {
		case light
		case dark
	}

	private let style: HTMLStyle

	init(with style: HTMLStyle) {
		self.style = style
	}

	private static let whiteHTMLColor = "white"
	private static let blackHTMLColor = "black"

	private static let blankLine = "<br>"
	private static let ackKey = "PreferenceSpecifiers"
	private static let titleKey = "Title"
	private static let licenseKey = "License"
	private static let footerKey = "FooterText"

	private var textColor: String {
		return (self.style == .light) ? Plist2HTML.blackHTMLColor : Plist2HTML.whiteHTMLColor
	}

	private var backgroundColor: String {
		return (self.style == .light) ? Plist2HTML.whiteHTMLColor : Plist2HTML.blackHTMLColor
	}

	/// Transforms the plist file containing the acknowledgments into an HTML
	/// - Parameter url: URL pointing to acknowledgments file
	func transformPlistFile(from url: URL) -> String {
		guard
			let plistDict = NSDictionary(contentsOfFile: url.path),
			let acknowledgmentsMultiList = plistDict[Plist2HTML.ackKey] as? NSArray else {
				return ""
		}

		var htmlString = ""

		acknowledgmentsMultiList.forEach { (acknowledgment: Any) in

			guard let ackDict = acknowledgment as? NSDictionary else {
				return
			}

			if let _title = ackDict[Plist2HTML.titleKey] as? String {
				htmlString += self.header(with: _title)
			}

			if let _license = ackDict[Plist2HTML.licenseKey] as? String {
				htmlString += self.subheader(with: _license)
			}

			if let _footerText = ackDict[Plist2HTML.footerKey] as? String {
				htmlString += self.paragraph(with: _footerText.replacingOccurrences(of: "\n", with: Plist2HTML.blankLine))
			}

			htmlString += Plist2HTML.blankLine
		}

		return self.body(with: htmlString)
	}

	// MARK: - Helpers

	private func body(with content: String) -> String {
		let fullBody = ("<body style=\"background-color:\(self.backgroundColor);\">" + content + "</body>")

		let style = """
		  <style> html, body { font-family: Calibri, "PT Sans", sans-serif; padding: 15px; }
			  ol {
				  padding-left: 15px;
			  }
			  li {
				  font-size: 16px;
			  }
		  </style>
		"""

		return (fullBody + style)
	}

	private func header(with title: String) -> String {
		return ("<h1 style=\"color:\(self.textColor);\">" + title + "</h1>")
	}

	private func subheader(with subtitle: String) -> String {
		return ("<h3 style=\"color:\(self.textColor);\">" + subtitle + "</h3>")
	}

	private func paragraph(with text: String) -> String {
		return ("<p style=\"color:\(self.textColor);\">" + text + "</p>")
	}
}
<commit_msg>Simplify `Plist2HTML` file by removing custom colors within the styles<commit_after>import Foundation

enum Plist2HTML {

	private static let blankLine = "<br>"
	private static let ackKey = "PreferenceSpecifiers"
	private static let titleKey = "Title"
	private static let licenseKey = "License"
	private static let footerKey = "FooterText"

	/// Transforms the plist file containing the acknowledgments into an HTML
	/// - Parameter url: URL pointing to acknowledgments file
	static func transformPlistFile(from url: URL) -> String {
		guard
			let plistDict = NSDictionary(contentsOfFile: url.path),
			let acknowledgmentsMultiList = plistDict[Plist2HTML.ackKey] as? NSArray else {
				return ""
		}

		var htmlString = ""

		acknowledgmentsMultiList.forEach { (acknowledgment: Any) in

			guard let ackDict = acknowledgment as? NSDictionary else {
				return
			}

			if let _title = ackDict[Plist2HTML.titleKey] as? String {
				htmlString += Plist2HTML.header(with: _title)
			}

			if let _license = ackDict[Plist2HTML.licenseKey] as? String {
				htmlString += Plist2HTML.subheader(with: _license)
			}

			if let _footerText = ackDict[Plist2HTML.footerKey] as? String {
				htmlString += Plist2HTML.paragraph(with: _footerText.replacingOccurrences(of: "\n", with: Plist2HTML.blankLine))
			}

			htmlString += Plist2HTML.blankLine
		}

		return Plist2HTML.body(with: htmlString)
	}

	// MARK: - Helpers

	private static func body(with content: String) -> String {
		let fullBody = ("<body>" + content + "</body>")

		let style = """
		<style> html, body { font-family: Calibri, "PT Sans", sans-serif; padding: 15px; }
			ol {
				padding-left: 15px;
			}
			li {
				font-size: 16px;
			}
			@media (prefers-color-scheme: dark) {
				body {
					background: #333;
					color: #fff;
				}
				a {
					color:#999;
				}
			}
		</style>
		"""
		return (fullBody + style)
	}

	private static func header(with title: String) -> String {
		return ("<h1>" + title + "</h1>")
	}

	private static func subheader(with subtitle: String) -> String {
		return ("<h3>" + subtitle + "</h3>")
	}

	private static func paragraph(with text: String) -> String {
		return ("<p>" + text + "</p>")
	}
}

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.010225375626043406, 'mean_word_length': 3.5517568850902186, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, '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': '6401555', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1537, 'n_words': 426}