function codeView(aSourceLines, aHits, aLocations, iLinesOfContext, bShowHits) {
		var iHighlightLevel = 0,
			iLastHighlightedLine = -Infinity,
			aPositions = aLocations.reduce(locate, []).sort(comparator),
			iSkippedLines = 0;

		// comparator for two locations
		function comparator(a, b) {
			return a.line - b.line || a.column - b.column;
		}

		// returns HTML for skipped lines, if any; updates iSkippedLines
		function getSkippedHtml() {
			var sHtml = "";

			if (iSkippedLines > 0) {
				sHtml = "<div class='ellipsis'><span>...</span>";
				if (bShowHits) {
					sHtml += "<span class='hits'>&nbsp;</span>";
				}
				sHtml += "<span class='skipped'>" + iSkippedLines + " lines skipped</span></div>";
				iSkippedLines = 0;
			}
			return sHtml;
		}

		// highlight given source code according to current level; updates iLastHighlightedLine
		function highlight(iLine, sSourceCode) {
			sSourceCode = encodeXML(sSourceCode);
			if (sSourceCode && iHighlightLevel) {
				iLastHighlightedLine = iLine;
				sSourceCode = "<span class='highlight'>" + sSourceCode + "</span>";
			}
			return sSourceCode;
		}

		// highlight given line according to current highlight level and positions;
		// updates iHighlightLevel
		function highlightLine(iLine, sSourceLine) {
			var iColumn = 0,
				sResult = "";

			while (aPositions.length && iLine === aPositions[0].line) {
				sResult += highlight(iLine, sSourceLine.slice(iColumn, aPositions[0].column));
				iColumn = aPositions[0].column;
				iHighlightLevel += aPositions.shift().delta;
			}

			sResult += highlight(iLine, sSourceLine.slice(iColumn));
			return sResult;
		}

		// add start/end position of given location
		function locate(aPositions, oLocation) {
			oLocation.start.delta = +1;
			aPositions.push(oLocation.start);
			oLocation.end.delta = -1;
			aPositions.push(oLocation.end);
			return aPositions;
		}

		if (iLinesOfContext === undefined) {
			iLinesOfContext = Infinity;
		}
		return aSourceLines.reduce(function (sHtml, sSourceLine, iLine) {
			var i,
				iNextHighlightedLine = aPositions.length && aPositions[0].line || Infinity,
				iNextHitsLine;

			function show() {
				sHtml += "<div";
				if (aHits[iLine] === 0) {
					sHtml += " class='miss'";
					iLastHighlightedLine = iLine;
				} else if (bShowHits && aHits[iLine] > 0) {
					sHtml += " class='hit'";
				}
				sHtml += "><span>" + iLine + "</span>";
				if (bShowHits) {
					sHtml += "<span class='hits'>"
						+ (aHits[iLine] >= 0 ? aHits[iLine] + "x" : "&nbsp;")
						+ "</span>";
				}
				sHtml += highlightLine(iLine, sSourceLine)
					+ "</div>";
			}

			if (bShowHits) {
				for (i = iLine; i < aHits.length; i += 1) {
					if (aHits[i] !== undefined) {
						iNextHitsLine = i;
						break;
					}
				}
			} else {
				iNextHitsLine = aHits.indexOf(0, iLine);
			}

			if (iNextHitsLine >= 0 && iNextHitsLine < iNextHighlightedLine) {
				iNextHighlightedLine = iNextHitsLine; // treat hit/missed lines as highlighted
			}
			// show iLinesOfContext before and after highlighting, do not skip a single line
			if (iLine >= iNextHighlightedLine - iLinesOfContext
				|| iLine <= iLastHighlightedLine + iLinesOfContext
				|| iNextHighlightedLine - iLastHighlightedLine === 2 * (iLinesOfContext + 1)) {
				sHtml += getSkippedHtml();
				show();
			} else {
				iSkippedLines += 1;
			}
			return sHtml;
		}, "") + getSkippedHtml();
	}
/**
	 * Compute HTML "code view" with line and intra-line highlighting.
	 *
	 * @param {string[]} aSourceLines
	 *   Lines of source code
	 * @param {number[]} aHits
	 *   Array of hit counts per line
	 * @param {object[]} aLocations
	 *   Intra-line locations to highlight (given as Blanket.js <code>SourceLocation</code> objects)
	 * @param {number} [iLinesOfContext=Infinity]
	 *   Lines of context to show, default is unlimited
	 * @param {boolean} [bShowHits=false]
	 *   Whether to show hit counts per line and highlight hit lines (not just missed ones)
	 * @returns {string}
	 *   HTML
	 */
Compute HTML "code view" with line and intra-line highlighting.
Compute HTML " code view " with line and intra - line highlighting .
function codeView(aSourceLines, aHits, aLocations, iLinesOfContext, bShowHits) {
		var iHighlightLevel = 0,
			iLastHighlightedLine = -Infinity,
			aPositions = aLocations.reduce(locate, []).sort(comparator),
			iSkippedLines = 0;
		function comparator(a, b) {
			return a.line - b.line || a.column - b.column;
		}
		function getSkippedHtml() {
			var sHtml = "";
			if (iSkippedLines > 0) {
				sHtml = "<div class='ellipsis'><span>...</span>";
				if (bShowHits) {
					sHtml += "<span class='hits'>&nbsp;</span>";
				}
				sHtml += "<span class='skipped'>" + iSkippedLines + " lines skipped</span></div>";
				iSkippedLines = 0;
			}
			return sHtml;
		}
		function highlight(iLine, sSourceCode) {
			sSourceCode = encodeXML(sSourceCode);
			if (sSourceCode && iHighlightLevel) {
				iLastHighlightedLine = iLine;
				sSourceCode = "<span class='highlight'>" + sSourceCode + "</span>";
			}
			return sSourceCode;
		}
		function highlightLine(iLine, sSourceLine) {
			var iColumn = 0,
				sResult = "";
			while (aPositions.length && iLine === aPositions[0].line) {
				sResult += highlight(iLine, sSourceLine.slice(iColumn, aPositions[0].column));
				iColumn = aPositions[0].column;
				iHighlightLevel += aPositions.shift().delta;
			}
			sResult += highlight(iLine, sSourceLine.slice(iColumn));
			return sResult;
		}
		function locate(aPositions, oLocation) {
			oLocation.start.delta = +1;
			aPositions.push(oLocation.start);
			oLocation.end.delta = -1;
			aPositions.push(oLocation.end);
			return aPositions;
		}
		if (iLinesOfContext === undefined) {
			iLinesOfContext = Infinity;
		}
		return aSourceLines.reduce(function (sHtml, sSourceLine, iLine) {
			var i,
				iNextHighlightedLine = aPositions.length && aPositions[0].line || Infinity,
				iNextHitsLine;
			function show() {
				sHtml += "<div";
				if (aHits[iLine] === 0) {
					sHtml += " class='miss'";
					iLastHighlightedLine = iLine;
				} else if (bShowHits && aHits[iLine] > 0) {
					sHtml += " class='hit'";
				}
				sHtml += "><span>" + iLine + "</span>";
				if (bShowHits) {
					sHtml += "<span class='hits'>"
						+ (aHits[iLine] >= 0 ? aHits[iLine] + "x" : "&nbsp;")
						+ "</span>";
				}
				sHtml += highlightLine(iLine, sSourceLine)
					+ "</div>";
			}
			if (bShowHits) {
				for (i = iLine; i < aHits.length; i += 1) {
					if (aHits[i] !== undefined) {
						iNextHitsLine = i;
						break;
					}
				}
			} else {
				iNextHitsLine = aHits.indexOf(0, iLine);
			}
			if (iNextHitsLine >= 0 && iNextHitsLine < iNextHighlightedLine) {
				iNextHighlightedLine = iNextHitsLine; 
			}
			if (iLine >= iNextHighlightedLine - iLinesOfContext
				|| iLine <= iLastHighlightedLine + iLinesOfContext
				|| iNextHighlightedLine - iLastHighlightedLine === 2 * (iLinesOfContext + 1)) {
				sHtml += getSkippedHtml();
				show();
			} else {
				iSkippedLines += 1;
			}
			return sHtml;
		}, "") + getSkippedHtml();
	}
function codeView ( aSourceLines , aHits , aLocations , iLinesOfContext , bShowHits ) { var iHighlightLevel = 0 , iLastHighlightedLine = - Infinity , aPositions = aLocations . reduce ( locate , [ ] ) . sort ( comparator ) , iSkippedLines = 0 ; function comparator ( a , b ) { return a . line - b . line || a . column - b . column ; } function getSkippedHtml ( ) { var sHtml = "" ; if ( iSkippedLines > 0 ) { sHtml = "<div class='ellipsis'><span>...</span>" ; if ( bShowHits ) { sHtml += "<span class='hits'>&nbsp;</span>" ; } sHtml += "<span class='skipped'>" + iSkippedLines + " lines skipped</span></div>" ; iSkippedLines = 0 ; } return sHtml ; } function highlight ( iLine , sSourceCode ) { sSourceCode = encodeXML ( sSourceCode ) ; if ( sSourceCode && iHighlightLevel ) { iLastHighlightedLine = iLine ; sSourceCode = "<span class='highlight'>" + sSourceCode + "</span>" ; } return sSourceCode ; } function highlightLine ( iLine , sSourceLine ) { var iColumn = 0 , sResult = "" ; while ( aPositions . length && iLine === aPositions [ 0 ] . line ) { sResult += highlight ( iLine , sSourceLine . slice ( iColumn , aPositions [ 0 ] . column ) ) ; iColumn = aPositions [ 0 ] . column ; iHighlightLevel += aPositions . shift ( ) . delta ; } sResult += highlight ( iLine , sSourceLine . slice ( iColumn ) ) ; return sResult ; } function locate ( aPositions , oLocation ) { oLocation . start . delta = + 1 ; aPositions . push ( oLocation . start ) ; oLocation . end . delta = - 1 ; aPositions . push ( oLocation . end ) ; return aPositions ; } if ( iLinesOfContext === undefined ) { iLinesOfContext = Infinity ; } return aSourceLines . reduce ( function ( sHtml , sSourceLine , iLine ) { var i , iNextHighlightedLine = aPositions . length && aPositions [ 0 ] . line || Infinity , iNextHitsLine ; function show ( ) { sHtml += "<div" ; if ( aHits [ iLine ] === 0 ) { sHtml += " class='miss'" ; iLastHighlightedLine = iLine ; } else if ( bShowHits && aHits [ iLine ] > 0 ) { sHtml += " class='hit'" ; } sHtml += "><span>" + iLine + "</span>" ; if ( bShowHits ) { sHtml += "<span class='hits'>" + ( aHits [ iLine ] >= 0 ? aHits [ iLine ] + "x" : "&nbsp;" ) + "</span>" ; } sHtml += highlightLine ( iLine , sSourceLine ) + "</div>" ; } if ( bShowHits ) { for ( i = iLine ; i < aHits . length ; i += 1 ) { if ( aHits [ i ] !== undefined ) { iNextHitsLine = i ; break ; } } } else { iNextHitsLine = aHits . indexOf ( 0 , iLine ) ; } if ( iNextHitsLine >= 0 && iNextHitsLine < iNextHighlightedLine ) { iNextHighlightedLine = iNextHitsLine ; } if ( iLine >= iNextHighlightedLine - iLinesOfContext || iLine <= iLastHighlightedLine + iLinesOfContext || iNextHighlightedLine - iLastHighlightedLine === 2 * ( iLinesOfContext + 1 ) ) { sHtml += getSkippedHtml ( ) ; show ( ) ; } else { iSkippedLines += 1 ; } return sHtml ; } , "" ) + getSkippedHtml ( ) ; }
Compute HTML "code view" with line and intra-line highlighting.
Compute HTML " code view " with line and intra - line highlighting .
// comparator for two locations // returns HTML for skipped lines, if any; updates iSkippedLines // highlight given source code according to current level; updates iLastHighlightedLine // highlight given line according to current highlight level and positions; // updates iHighlightLevel // add start/end position of given location // treat hit/missed lines as highlighted // show iLinesOfContext before and after highlighting, do not skip a single line