<commit_before>"use strict";

define(
		[	'src/options',
			'src/exampleData',
			'src/diff',
			'src/cslStyles',
			'src/xmlUtility',
			'src/debug'
		],
		function (
			CSLEDIT_options,
			CSLEDIT_exampleData,
			CSLEDIT_diff,
			CSLEDIT_cslStyles,
			CSLEDIT_xmlUtility,
			debug
		) {	
	var outputNode;

	var closenessString = function (stringA, stringB) {
		var matchQuality = CSLEDIT_diff.matchQuality(stringA, stringB),
			closeness;

		if (matchQuality === 100) {
			closeness = "Perfect match!";
		} else {
			closeness = matchQuality + "% match";
		}

		return '<td class="closeness match">' + closeness + '</td>';
	};

	var displaySearchResults = function (styles, _outputNode, exampleIndex /* optional */) {
		var index,
			outputList = [],
			masterStyleSuffix = "",
			style,
			citation,
			bibliography,
			citationCloseness = "",
			bibliographyCloseness = "",
			citationDiff,
			bibliographyDiff,
			featuredStyleClass,
			featuredStyleText,
			resultsLimit = 30;

		outputNode = outputNode || _outputNode;
		
		outputNode.html("");

		exampleIndex = exampleIndex || 0;

		for (index = 0; index < Math.min(styles.length, resultsLimit); index++)
		{
			style = styles[index];
			if (style.masterId !== style.styleId)
			{
				masterStyleSuffix = ' (same as <a href="' + style.masterId + '">' +
					CSLEDIT_cslStyles.styles().styleTitleFromId[style.masterId] + '</a>)';
			} else {
				masterStyleSuffix = '';
			}

			citation = CSLEDIT_cslStyles
				.exampleCitations()
				.exampleCitationsFromMasterId[style.masterId][exampleIndex]
				.formattedCitations[0];
			bibliography = CSLEDIT_cslStyles
				.exampleCitations()
				.exampleCitationsFromMasterId[style.masterId][exampleIndex]
				.formattedBibliography;
			
			if (typeof style.userCitation !== "undefined" &&
					style.userCitation !== "" &&
					citation !== "") {
				citationDiff = CSLEDIT_diff.prettyHtmlDiff(style.userCitation, citation);
				citationCloseness = closenessString(style.userCitation, citation);
			}

			if (typeof style.userBibliography !== "undefined" &&
					style.userBibliography !== "" &&
					bibliography !== "") {
				bibliographyDiff =
					CSLEDIT_diff.prettyHtmlDiff(style.userBibliography, CSLEDIT_xmlUtility.cleanInput(bibliography));
				bibliographyCloseness = closenessString(
						style.userBibliography, CSLEDIT_xmlUtility.cleanInput(bibliography));
			}

			featuredStyleClass = '';
			featuredStyleText = '';
			if (CSLEDIT_exampleData.topStyles.indexOf(style.styleId) !== -1) {
				featuredStyleClass = ' class="featuredStyle" ';
				featuredStyleText = '<span class="featuredStyle">Popular</span>';
			}

			outputList.push(
				'<table' + featuredStyleClass + '>' +
				'<tr><td colspan=3>' + featuredStyleText + '<a class="style-title" href="' + style.styleId + '">' +
				CSLEDIT_cslStyles.styles().styleTitleFromId[style.styleId] + "</a>" +
				masterStyleSuffix + '</td></tr>' +
				'<tr><td nowrap="nowrap"><span class="faint">Inline citation</span></td>' +
				'<td class=match>' +
				citation + '</td>' + citationCloseness + '</tr>' +
				'<tr><td nowrap="nowrap"><span class="faint">Bibliography</span></td>' +
				'<td class=match>' +
				bibliography + '</td>' + bibliographyCloseness + "</tr>" +
				'<tr><td><button class="installStyle" data-styleId="' + style.styleId + '">Install</button></td><td>' +
				'<button class="editStyle" data-styleId="' + style.styleId + '">Edit</button>' +
				'<button class="viewCode" data-styleId="' + style.styleId + '">View code</button></td></tr>' +
				'</table>');
		}
		
		if (outputList.length === 0) {
			outputNode.append('<p>No results found</p>');
		} else {
			if (outputList.length === 0 && searchQuery.length === 0) {
				outputNode.append('<p>Popular styles:</p>');
			} else {
				outputNode.append('<p>Displaying ' + outputList.length + ' results:</p>');
			}
			
			$.each(outputList, function (i, entry) {
				outputNode.append(entry + "<p/>");<commit_msg>Change the link from Zotero to the locally hosted version.<commit_after>"use strict";

define(
		[	'src/options',
			'src/exampleData',
			'src/diff',
			'src/cslStyles',
			'src/xmlUtility',
			'src/debug'
		],
		function (
			CSLEDIT_options,
			CSLEDIT_exampleData,
			CSLEDIT_diff,
			CSLEDIT_cslStyles,
			CSLEDIT_xmlUtility,
			debug
		) {	
	var outputNode;

	var closenessString = function (stringA, stringB) {
		var matchQuality = CSLEDIT_diff.matchQuality(stringA, stringB),
			closeness;

		if (matchQuality === 100) {
			closeness = "Perfect match!";
		} else {
			closeness = matchQuality + "% match";
		}

		return '<td class="closeness match">' + closeness + '</td>';
	};

	var displaySearchResults = function (styles, _outputNode, exampleIndex /* optional */) {
		var index,
			outputList = [],
			masterStyleSuffix = "",
			style,
			citation,
			bibliography,
			citationCloseness = "",
			bibliographyCloseness = "",
			citationDiff,
			bibliographyDiff,
			featuredStyleClass,
			featuredStyleText,
			resultsLimit = 30;

		outputNode = outputNode || _outputNode;
		
		outputNode.html("");

		exampleIndex = exampleIndex || 0;

		for (index = 0; index < Math.min(styles.length, resultsLimit); index++)
		{
			style = styles[index];
			if (style.masterId !== style.styleId)
			{
				masterStyleSuffix = ' (same as <a href="' + style.masterId + '">' +
					CSLEDIT_cslStyles.styles().styleTitleFromId[style.masterId] + '</a>)';
			} else {
				masterStyleSuffix = '';
			}

			citation = CSLEDIT_cslStyles
				.exampleCitations()
				.exampleCitationsFromMasterId[style.masterId][exampleIndex]
				.formattedCitations[0];
			bibliography = CSLEDIT_cslStyles
				.exampleCitations()
				.exampleCitationsFromMasterId[style.masterId][exampleIndex]
				.formattedBibliography;
			
			if (typeof style.userCitation !== "undefined" &&
					style.userCitation !== "" &&
					citation !== "") {
				citationDiff = CSLEDIT_diff.prettyHtmlDiff(style.userCitation, citation);
				citationCloseness = closenessString(style.userCitation, citation);
			}

			if (typeof style.userBibliography !== "undefined" &&
					style.userBibliography !== "" &&
					bibliography !== "") {
				bibliographyDiff =
					CSLEDIT_diff.prettyHtmlDiff(style.userBibliography, CSLEDIT_xmlUtility.cleanInput(bibliography));
				bibliographyCloseness = closenessString(
						style.userBibliography, CSLEDIT_xmlUtility.cleanInput(bibliography));
			}

			featuredStyleClass = '';
			featuredStyleText = '';
			if (CSLEDIT_exampleData.topStyles.indexOf(style.styleId) !== -1) {
				featuredStyleClass = ' class="featuredStyle" ';
				featuredStyleText = '<span class="featuredStyle">Popular</span>';
			}

			outputList.push(
				'<table' + featuredStyleClass + '>' +
				'<tr><td colspan=3>' + featuredStyleText + '<a class="style-title" href="' + 
					CSLEDIT_cslStyles.localURLFromZoteroId(style.styleId) + '">' +
				CSLEDIT_cslStyles.styles().styleTitleFromId[style.styleId] + "</a>" +
				masterStyleSuffix + '</td></tr>' +
				'<tr><td nowrap="nowrap"><span class="faint">Inline citation</span></td>' +
				'<td class=match>' +
				citation + '</td>' + citationCloseness + '</tr>' +
				'<tr><td nowrap="nowrap"><span class="faint">Bibliography</span></td>' +
				'<td class=match>' +
				bibliography + '</td>' + bibliographyCloseness + "</tr>" +
				'<tr><td><button class="installStyle" data-styleId="' + style.styleId + '">Install</button></td><td>' +
				'<button class="editStyle" data-styleId="' + style.styleId + '">Edit</button>' +
				'<button class="viewCode" data-styleId="' + style.styleId + '">View code</button></td></tr>' +
				'</table>');
		}
		
		if (outputList.length === 0) {
			outputNode.append('<p>No results found</p>');
		} else {
			if (outputList.length === 0 && searchQuery.length === 0) {
				outputNode.append('<p>Popular styles:</p>');
			} else {
				outputNode.append('<p>Displaying ' + outputList.length + ' results:</p>');
			}
			
			$.each(outputList, function (i, entry) {
				outputNode.append(entry + "<p/>");
{'fraction_non_alphanumeric': 0.1659782200525723, 'fraction_numerical': 0.0032544749029916136, 'mean_word_length': 3.8660170523751525, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '6397484', 'n_tokens_mistral': 3218, 'n_tokens_neox': 2584, 'n_words': 436}