/// <summary> /// Parses source code. /// </summary> /// <param name="source">The source code which will be parsed.</param> /// <param name="scannerResult">The result returned by the scanners after scanning the source code.</param> /// <returns>The highlighted source code.</returns> public override string Parse(string source, IList <Occurrence> scannerResult) { StringWriter htmlStringWriter = new StringWriter(); XhtmlTextWriter htmlWriter = new XhtmlTextWriter(htmlStringWriter); int lastIndex = 0; for (int i = 0; i < scannerResult.Count; i++) { if ((scannerResult[i].Start - lastIndex) >= 0) { if (scannerResult[i].Start > 0) { // Encode non-highlighted text first. htmlWriter.WriteEncodedText(source.Substring(lastIndex, scannerResult[i].Start - lastIndex)); } htmlWriter.Write(this.ParseToken(source.Substring(scannerResult[i].Start, scannerResult[i].Length), scannerResult[i].Node)); } lastIndex = scannerResult[i].Start + scannerResult[i].Length; } // Encode the last bit of nonhighlighted text. if (lastIndex < source.Length) { htmlWriter.WriteEncodedText(source.Substring(lastIndex)); } string result = htmlStringWriter.ToString(); htmlWriter.Close(); htmlStringWriter.Close(); return(result); }