Example #1
0
        protected override void ColorizeLine(DocumentLine line)
        {
            var ast = _abstractSyntaxTree;

            if (ast is null)
            {
                return;
            }

            var theme = _theme;

            if (theme is null)
            {
                return;
            }

            var start         = line.Offset;
            var end           = line.EndOffset;
            var leadingSpaces = CurrentContext.GetText(start, end - start).Text.TakeWhile(char.IsWhiteSpace).Count();

            foreach (var block in EnumerateSpanningBlocks(ast, start, end))
            {
                if (BlockHighlighter.TryGetValue(block.Tag, out Func <Theme, Highlight> highlighter))
                {
                    var magnify = double.NaN;
                    //if (block.Heading.Level == 1) magnify = theme.Header1Height;
                    //if (block.Heading.Level == 2) magnify = theme.Header2Height;

                    var length = block.Tag == BlockTag.ListItem
                        ? Math.Min(block.SourceLength, block.ListData.Padding)
                        : block.SourceLength;

                    if (block.Tag == BlockTag.HtmlBlock &&
                        block.HtmlBlockType == HtmlBlockType.Comment)
                    {
                        highlighter = t => t.HighlightComment;
                    }


                    ApplyLinePart(highlighter(theme), block.SourcePosition, length, start, end, leadingSpaces, magnify);
                }

                foreach (var inline in EnumerateInlines(block.InlineContent)
                         .TakeWhile(il => il.SourcePosition < end)
                         .Where(il => InlineHighlighter.TryGetValue(il.Tag, out highlighter)))
                {
                    var position = inline.SourcePosition;
                    var length   = inline.SourceLength;

                    //if ((inline.Tag == InlineTag.Link || inline.Tag == InlineTag.Image)
                    //    && inline.FirstChild?.LiteralContent != null
                    //    && inline.FirstChild.LiteralContent != inline.TargetUrl)
                    //{
                    //    var literal = inline.FirstChild.LastSibling;
                    //    var urlPosition = literal.SourcePosition + literal.SourceLength + 1;
                    //    var urlLength = inline.SourcePosition + inline.SourceLength - urlPosition;
                    //    if (urlLength > 0) // check for <*****@*****.**> style links
                    //    {
                    //        position = urlPosition;
                    //        length = urlLength;
                    //    }
                    //}

                    // inlines don't magnify
                    ApplyLinePart(highlighter(theme), position, length, start, end, leadingSpaces, double.NaN);
                }
            }
        }