Exemplo n.º 1
0
        /// <summary>
        /// Converts an IDocument to a RichText and applies the provided highlighter.
        /// </summary>
        public static RichText ConvertTextDocumentToRichText(IDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            var texts = new List <RichText>();

            for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++)
            {
                var line = document.GetLineByNumber(lineNumber);
                if (lineNumber > 1)
                {
                    texts.Add(line.PreviousLine.DelimiterLength == 2 ? "\r\n" : "\n");
                }
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    texts.Add(highlightedLine.ToRichText());
                }
                else
                {
                    texts.Add(document.GetText(line));
                }
            }
            return(RichText.Concat(texts.ToArray()));
        }