예제 #1
0
        private async Task <string> Publish(string html)
        {
            _codeFormatter = Substitute.For <ICodeFormatter>();
            _codeFormatter.FormatAsync(Arg.Any <string>(), Arg.Any <string>()).Returns(x => Task.FromResult((string)x[1]));

            _imageProcessor = Substitute.For <IImageProcessor>();
            _imageProcessor.Minimize(Arg.Any <string>()).Returns("minImage");

            _processor = new HtmlProcessor(_codeFormatter, _imageProcessor);
            var renderer = new ImageRenderer("the-post");
            var result   = renderer.Render(html);

            return(await _processor.ProcessAsync(result.Html));
        }
예제 #2
0
        private async Task <string> Code(HtmlNode node)
        {
            var plain            = node.InnerHtml.Trim();
            var highlightedLines = GetHighlightedLines(GetCode(plain));
            var formattedCode    = await _codeFormatter.FormatAsync(
                GetLanguage(plain),
                GetCode(plain).ReplaceWithPattern(@"\s*#hl", string.Empty));

            var lineNumbers = string.Empty;
            var lines       = formattedCode.SplitWithPattern(@"\r?\n");

            for (var i = 0; i < lines.Count(); i++)
            {
                var no = i + 1;
                if (highlightedLines.Contains(i))
                {
                    lines[i] = Emmet.El("span.highlight", lines[i]);
                    Increment(ref lineNumbers, Emmet.El("span.highlight", no));
                }
                else
                {
                    Increment(ref lineNumbers, no);
                }
            }

            formattedCode = lines.JoinLines();

            if (GetDefinitionLine(plain).Contains("no-line-number"))
            {
                return(Emmet.El("div.code>pre", formattedCode));
            }

            var table = $"<table><tr><td>{lineNumbers.Trim()}</td><td>{formattedCode}</td></tr></table>";

            return(Emmet.El("div.code>pre", table));
        }