Esempio n. 1
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, DfmXrefInlineToken token, MarkdownInlineContext context)
 {
     var href = token.Href == null ? string.Empty : $" href=\"{StringHelper.HtmlEncode(token.Href)}\"";
     var name = token.Name == null ? null : StringHelper.HtmlEncode(token.Name);
     var title = token.Title == null ? null : $" title=\"{StringHelper.HtmlEncode(token.Title)}\"";
     return $"<xref{href}{title}>{name}</xref>";
 }
Esempio n. 2
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownListBlockToken token, MarkdownBlockContext context)
        {
            const string ListStartString = "* ";
            var content = StringBuffer.Empty;

            if (token.Ordered)
            {
                foreach (var t in token.Tokens)
                {
                    var listItemToken = t as MarkdownListItemBlockToken;
                    if (listItemToken == null)
                    {
                        throw new Exception($"token {t.GetType()} is not MarkdownListItemBlockToken in MarkdownListBlockToken. Token raw:{t.RawMarkdown}");
                    }
                    content += ListStartString;
                    content += render.Render(t);
                }
            }
            else
            {
                for (int i = 1; i < token.Tokens.Length; ++i)
                {
                    var listItemToken = token.Tokens[i] as MarkdownListItemBlockToken;

                    if (listItemToken == null)
                    {
                        throw new Exception($"token {token.Tokens[i].GetType()} is not MarkdownListItemBlockToken in MarkdownListBlockToken. Token raw:{token.Tokens[i].RawMarkdown}");
                    }

                    content += i.ToString();
                    content += ". ";
                }
            }
            return content;
        }
Esempio n. 3
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmYamlHeaderBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = "---\n";
     content += token.Content;
     content += "\n---\n";
     return content;
 }
Esempio n. 4
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeInlineToken token, MarkdownInlineContext context)
 {
     lock (_inlineInclusionHelper)
     {
         return _inlineInclusionHelper.Load(renderer, token.Src, token.Raw, token.SourceInfo, context, (DfmEngine)renderer.Engine);
     }
 }
Esempio n. 5
0
 public static string GenerateReferenceNotFoundErrorMessage(IMarkdownRenderer renderer, DfmFencesToken token)
 {
     var errorMessageInMarkdown = $"Can not find reference {token.Path}";
     var errorMessage = $"Unable to resolve {token.SourceInfo.Markdown}. {errorMessageInMarkdown}. at line {token.SourceInfo.LineNumber}.";
     Logger.LogError(errorMessage);
     return GetRenderedFencesBlockString(token, renderer.Options, errorMessageInMarkdown);
 }
Esempio n. 6
0
        public virtual StringBuffer Render(IMarkdownRenderer render, AzureVideoBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            object path;
            if (!context.Variables.TryGetValue("path", out path))
            {
                path = string.Empty;
                content += token.SourceInfo.Markdown;
                return content += "\n\n";
            }

            if (!context.Variables.ContainsKey("azureVideoInfoMapping"))
            {
                Logger.LogWarning($"Can't fild azure video info mapping. Raw: {token.SourceInfo.Markdown}");
                content = token.SourceInfo.Markdown;
                return content + "\n\n";
            }

            var azureVideoInfoMapping = (IReadOnlyDictionary<string, AzureVideoInfo>)context.Variables["azureVideoInfoMapping"];
            if (azureVideoInfoMapping == null || !azureVideoInfoMapping.ContainsKey(token.VideoId))
            {
                Logger.LogWarning($"Can't fild azure video info mapping for file {path}. Raw: {token.SourceInfo.Markdown}");
                content = token.SourceInfo.Markdown;
                return content + "\n\n";
            }

            var azureVideoInfo = azureVideoInfoMapping[token.VideoId];
            content += $@"<iframe width=""{azureVideoInfo.Width}"" height=""{azureVideoInfo.Height}"" src=""{azureVideoInfo.Link}"" frameborder=""0"" allowfullscreen=""true""></iframe>";
            return content + "\n\n";
        }
Esempio n. 7
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            const string BlockQuoteStartString = "> ";
            const string BlockQuoteJoinString = "\n" + BlockQuoteStartString;

            var content = StringBuffer.Empty;
            foreach (var t in token.Tokens)
            {
                content += render.Render(t);
            }
            var contents = content.ToString().Split('\n');
            content = StringBuffer.Empty;
            foreach (var item in contents)
            {
                if (content == StringBuffer.Empty)
                {
                    content += BlockQuoteStartString;
                    content += item;
                }
                else
                {
                    content += BlockQuoteJoinString;
                    content += item;
                }
            }
            return content;
        }
Esempio n. 8
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownCodeBlockToken token, MarkdownBlockContext context)
        {
            bool escaped = false;
            string code = token.Code;
            if (engine.Options.Highlight != null)
            {
                var highlightCode = engine.Options.Highlight(code, token.Lang);
                if (highlightCode != null && highlightCode != code)
                {
                    escaped = true;
                    code = highlightCode;
                }
            }

            if (string.IsNullOrEmpty(token.Lang))
            {
                return (StringBuffer)"<pre><code>" + (escaped ? code : StringHelper.Escape(code, true)) + "\n</code></pre>";
            }

            return "<pre><code class=\""
                + engine.Options.LangPrefix
                + StringHelper.Escape(token.Lang, true)
                + "\">"
                + (escaped ? code : StringHelper.Escape(code, true))
                + "\n</code></pre>\n";
        }
Esempio n. 9
0
 public override StringBuffer Render(IMarkdownRenderer engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = string.Empty;
     var splitTokens = DfmRendererHelper.SplitBlockquoteTokens(token.Tokens);
     foreach (var splitToken in splitTokens)
     {
         if (splitToken.Token is DfmSectionBlockToken)
         {
             var sectionToken = splitToken.Token as DfmSectionBlockToken;
             content += $"<div{sectionToken.Attributes}>";
             content += RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule);
             content += "</div>\n";
         }
         else if (splitToken.Token is DfmNoteBlockToken)
         {
             var noteToken = splitToken.Token as DfmNoteBlockToken;
             content += $"<div class=\"{noteToken.NoteType}\"><h5>{noteToken.NoteType}</h5>" + RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule) + "</div>\n";
         }
         else
         {
             content += "<blockquote>";
             content += RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule);
             content += "</blockquote>\n";
         }
     }
     return content;
 }
Esempio n. 10
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeBlockToken token, MarkdownBlockContext context)
 {
     var href = token.Src == null ? null : $"src=\"{StringHelper.HtmlEncode(token.Src)}\"";
     var name = token.Name == null ? null : StringHelper.HtmlEncode(token.Name);
     var title = token.Title == null ? null : $"title=\"{StringHelper.HtmlEncode(token.Title)}\"";
     var resolved = _blockInclusionHelper.Load(renderer, token.Src, token.Raw, context, ((DfmEngine)renderer.Engine).InternalMarkup);
     return resolved;
 }
Esempio n. 11
0
 protected virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownListItemBlockToken token)
 {
     var childContent = StringBuffer.Empty;
     foreach (var item in token.Tokens)
     {
         childContent += renderer.Render(item);
     }
     return Insert(token, ExposeTokenName(token), childContent);
 }
Esempio n. 12
0
 private StringBuffer RenderAzureIncludeToken(IMarkdownRenderer render, AzureIncludeBasicToken token, IMarkdownContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     foreach(var t in token.Tokens)
     {
         content += render.Render(t);
     }
     return content;
 }
Esempio n. 13
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
 {
     var childContent = StringBuffer.Empty;
     foreach (var item in token.InlineTokens.Tokens)
     {
         childContent += renderer.Render(item);
     }
     return Insert(token, ExposeTokenName(token), childContent);
 }
Esempio n. 14
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = "<blockquote>\n";
     foreach (var item in token.Tokens)
     {
         content += renderer.Render(item);
     }
     return content + "</blockquote>\n";
 }
Esempio n. 15
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
 {
     var content = StringBuffer.Empty;
     foreach (var t in token.InlineTokens.Tokens)
     {
         content += render.Render(t);
     }
     return content + "\n\n";
 }
Esempio n. 16
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
 {
     var childContent = StringBuffer.Empty;
     foreach (var item in token.Content)
     {
         childContent += renderer.Render(item);
     }
     return Insert(token, $"{ExposeTokenNameInDfm(token)}>{Escape(token.Href)}", childContent);
 }
Esempio n. 17
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     foreach(var t in token.Content.Tokens)
     {
         content += render.Render(t);
     }
     return content;
 }
Esempio n. 18
0
        private string LoadCore(IMarkdownRenderer adapter, string currentPath, string raw, SourceInfo sourceInfo, IMarkdownContext context, DfmEngine engine)
        {
            try
            {
                if (!PathUtility.IsRelativePath(currentPath))
                {
                    return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Absolute path \"{currentPath}\" is not supported.", raw, sourceInfo);
                }

                // Always report original include file dependency
                var originalRelativePath = currentPath;
                context.ReportDependency(currentPath);

                var parents = context.GetFilePathStack();
                string parent = string.Empty;
                if (parents == null) parents = ImmutableStack<string>.Empty;

                // Update currentPath to be referencing to sourcePath
                else if (!parents.IsEmpty)
                {
                    parent = parents.Peek();
                    currentPath = ((RelativePath)currentPath).BasedOn((RelativePath)parent);
                }

                if (parents.Contains(currentPath, FilePathComparer.OSPlatformSensitiveComparer))
                {
                    return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}: Circular dependency found in \"{parent}\"", raw, sourceInfo);
                }

                // Add current file path to chain when entering recursion
                parents = parents.Push(currentPath);
                string result;
                HashSet<string> dependency;
                if (!_dependencyCache.TryGetValue(currentPath, out dependency) ||
                    !_cache.TryGet(currentPath, out result))
                {
                    var filePathWithStatus = DfmFallbackHelper.GetFilePathWithFallback(originalRelativePath, context);
                    var src = File.ReadAllText(filePathWithStatus.Item1);
                    dependency = new HashSet<string>();
                    src = engine.InternalMarkup(src, context.SetFilePathStack(parents).SetDependency(dependency).SetIsInclude());

                    result = UpdateToHrefFromWorkingFolder(src, currentPath);
                    result = GenerateNodeWithCommentWrapper("INCLUDE", $"Include content from \"{currentPath}\"", result);
                    _cache.Add(currentPath, result);
                    _dependencyCache[currentPath] = dependency;
                }
                context.ReportDependency(
                    from d in dependency
                    select (string)((RelativePath)currentPath + (RelativePath)d - (RelativePath)parent));
                return result;
            }
            catch (Exception e)
            {
                return GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}:{e.Message}", raw, sourceInfo);
            }
        }
Esempio n. 19
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
 {
     string level = token.Depth.ToString();
     var childContent = StringBuffer.Empty;
     foreach (var item in token.Content.Tokens)
     {
         childContent += renderer.Render(item);
     }
     return Insert(token, $"{ExposeTokenName(token)}{level}", childContent);
 }
Esempio n. 20
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownListBlockToken token, MarkdownBlockContext context)
 {
     var type = token.Ordered ? "ol" : "ul";
     var childContent = StringBuffer.Empty;
     foreach (var item in token.Tokens)
     {
         childContent += Render(renderer, (MarkdownListItemBlockToken) item);
     }
     return Insert(token, type, childContent);
 }
Esempio n. 21
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmYamlHeaderBlockToken token, MarkdownBlockContext context)
 {
     if (string.IsNullOrEmpty(token.Content))
     {
         return StringBuffer.Empty;
     }
     StringBuffer result = "<yamlheader>";
     result += StringHelper.HtmlEncode(token.Content);
     return result + "</yamlheader>";
 }
Esempio n. 22
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownStrongInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "**";
     foreach (var t in token.Content)
     {
         content += render.Render(t);
     }
     content += "**";
     return content;
 }
Esempio n. 23
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownCodeBlockToken token, MarkdownBlockContext context)
 {
     if (!string.IsNullOrEmpty(token.Lang))
     {
         return Insert(token, $"{ExposeTokenName(token)}({token.Lang})>{Escape(token.Code)}");
     }
     else
     {
         return Insert(token, $"{ExposeTokenName(token)}>{Escape(token.Code)}");
     }
 }
Esempio n. 24
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownListBlockToken token, MarkdownBlockContext context)
 {
     var type = token.Ordered ? "ol" : "ul";
     StringBuffer content = "<";
     content += type;
     content += ">\n";
     foreach (var t in token.Tokens)
     {
         content += engine.Render(t);
     }
     return content + "</" + type + ">\n";
 }
Esempio n. 25
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
 {
     switch(token.LinkType)
     {
         case MarkdownLinkType.NormalLink:
             return RenderImageNormalLink(render, token, context);
         case MarkdownLinkType.NumberLink:
             return RenderNumberLink(render, token, context);
         case MarkdownLinkType.RefLink:
             return RenderRefLink(render, token, context);
         default:
             throw new NotSupportedException($"Link type: {token.LinkType} doesn't support in Image Link Render");
     }
 }
Esempio n. 26
0
 private StringBuffer RenderImageNormalLink(IMarkdownRenderer render, MarkdownImageInlineToken token, MarkdownInlineContext context)
 {
     StringBuffer content = StringBuffer.Empty;
     content += "![";
     content += token.Text;
     content += "](";
     content += Regexes.Helper.MarkdownUnescape.Replace(token.Href, m => "\\" + m.Value);
     if (!string.IsNullOrEmpty(token.Title))
     {
         content += " \"";
         content += Regexes.Helper.MarkdownUnescape.Replace(token.Title, m => "\\" + m.Value);
         content += "\"";
     }
     content += ")";
     return content;
 }
Esempio n. 27
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer result = "<xref";
            result = AppendAttribute(result, "href", token.Href);
            result = AppendAttribute(result, "title", token.Title);
            result = AppendAttribute(result, "data-throw-if-not-resolved", token.ThrowIfNotResolved.ToString());
            result = AppendAttribute(result, "data-raw", token.RawMarkdown);
            
            result += ">";
            if (token.Name != null)
            {
                result += StringHelper.HtmlEncode(token.Name);
            }

            result += "</xref>";
            return result;
        }
Esempio n. 28
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
 {
     string level = token.Depth.ToString();
     var result = (StringBuffer)"<h"
         + level
         + " id=\""
         + engine.Options.HeaderPrefix
         + token.Id
         + "\">";
     foreach (var item in token.Content.Tokens)
     {
         result += engine.Render(item);
     }
     result += "</h";
     result += level;
     result += ">\n";
     return result;
 }
Esempio n. 29
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmXrefInlineToken token, MarkdownInlineContext context)
        {
            StringBuffer result = "<xref";
            result = AppendAttribute(result, "href", token.Href);
            result = AppendAttribute(result, "title", token.Title);
            result = AppendAttribute(result, "data-throw-if-not-resolved", token.ThrowIfNotResolved.ToString());
            result = AppendAttribute(result, "data-raw-source", token.SourceInfo.Markdown);
            result = AppendSourceInfo(result, renderer, token);
            result += ">";

            foreach (var item in token.Content)
            {
                result += renderer.Render(item);
            }

            result += "</xref>";
            return result;
        }
        public void Setup(IMarkdownRenderer renderer) {
            if (renderer == null) {
                throw new ArgumentNullException(nameof(renderer));
            }

            var htmlRenderer = renderer as TextRendererBase<HtmlRenderer>;
            if (htmlRenderer == null) {
                return;
            }

            var originalCodeBlockRenderer = htmlRenderer.ObjectRenderers.FindExact<CodeBlockRenderer>();
            if (originalCodeBlockRenderer != null) {
                htmlRenderer.ObjectRenderers.Remove(originalCodeBlockRenderer);
            }

            htmlRenderer.ObjectRenderers.AddIfNotAlready(
                new SyntaxHighlightingCodeBlockRenderer(originalCodeBlockRenderer));
        }
Esempio n. 31
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmSectionBlockToken token, MarkdownBlockContext context)
 {
     return(string.IsNullOrEmpty(token.Attributes)
             ? "[!div]\n"
             : $"[!div {token.Attributes}]\n");
 }
Esempio n. 32
0
        public async Task <IActionResult> Stats(
            [FromServices] IMarkdownRenderer renderer,
            [FromServices] IGit git,
            [FromQuery] string q,
            [FromQuery] string since,
            [FromQuery] string until,
            [FromQuery] string author
            )
        {
            var logArgs = Utils.SplitArguments(q).Concat(new[]
            {
                Param(nameof(since), since),
                Param(nameof(until), until),
                Param(nameof(author), author)
            }.WhereValue()).ToArray();

            var c = git.GetChanges(logArgs);

            var byName = c.GroupBy(_ => _.Commit.author.Email)
                         .Select(_ => new
            {
                User         = _.Key,
                AddedLines   = _.Sum(_c => _c.Stats.AddedLines),
                RemovedLines = _.Sum(_c => _c.Stats.RemovedLines)
            })
                         .OrderByDescending(_ => _.AddedLines + _.RemovedLines)
                         .ToList();

            var byPath = c
                         .SelectMany(_ => ContentPath.FromUrlPath(_.Stats.Path).Lineage
                                     .Select(dir => new { Path = dir, Change = _ }))
                         .GroupBy(_ => _.Path)
                         .Select(_ => new
            {
                Path         = _.Key,
                AddedLines   = _.Sum(_c => _c.Change.Stats.AddedLines),
                RemovedLines = _.Sum(_c => _c.Change.Stats.RemovedLines)
            })
                         .OrderByDescending(_ => _.AddedLines)
                         .Take(100)
                         .ToList();

            var markdown = $@"
<form action=""/stats"" method=""get"" >
<input name=""since"" placeholder=""since yyyy-mm-dd"" value={Attribute(since)} />
<input name=""until"" placeholder=""until yyyy-mm-dd"" value={Attribute(until)} />
<input name=""author"" placeholder=""author"" value={Attribute(author)} />
<input type=""submit"" />
</form>

## By User

{byName.MarkdownTable()
    .With("User", _ => $"[{_.User}](/stats?author={_.User})")
    .With("Added Lines", _ => _.AddedLines)
    .With("Removed Lines", _ => _.RemovedLines)
}

## By Path

{byPath.MarkdownTable()
    .With("Path", _ => $"[{_.Path}](/{_.Path})")
    .With("Added Lines", _ => _.AddedLines)
    .With("Removed Lines", _ => _.RemovedLines)
}

";

            return(await MarkdownView(renderer, new ContentPath(), markdown));
        }
Esempio n. 33
0
 public virtual string Load(IMarkdownRenderer adapter, string currentPath, SourceInfo sourceInfo, IMarkdownContext context, DfmEngine engine)
 {
     return(LoadCore(adapter, currentPath, sourceInfo, context, engine));
 }
Esempio n. 34
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 35
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownEscapeInlineToken token, MarkdownInlineContext context)
 {
     return(Insert(token, $"{ExposeTokenName(token)}>{Escape(token.Content)}"));
 }
Esempio n. 36
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmNoteBlockToken token, MarkdownBlockContext context)
 {
     return(token.Content);
 }
Esempio n. 37
0
        public override StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content     = string.Empty;
            var          splitTokens = DfmBlockquoteHelper.SplitBlockquoteTokens(token.Tokens);

            foreach (var splitToken in splitTokens)
            {
                if (splitToken.Token is DfmSectionBlockToken)
                {
                    if (!splitToken.Token.SourceInfo.Markdown.EndsWith("\n"))
                    {
                        Logger.LogWarning("The content part of [!div] syntax is suggested to start in a new line.", file: splitToken.Token.SourceInfo.File, line: splitToken.Token.SourceInfo.LineNumber.ToString());
                    }
                    content += "<div";
                    content += ((DfmSectionBlockToken)splitToken.Token).Attributes;
                    content  = AppendSourceInfo(content, renderer, splitToken.Token);
                    content += ">";
                    foreach (var item in splitToken.InnerTokens)
                    {
                        content += renderer.Render(item);
                    }
                    content += "</div>\n";
                }
                else if (splitToken.Token is DfmNoteBlockToken)
                {
                    if (!splitToken.Token.SourceInfo.Markdown.EndsWith("\n"))
                    {
                        Logger.LogWarning("The content part of NOTE/WARNING/CAUTION/IMPORTANT syntax is suggested to start in a new line.", file: splitToken.Token.SourceInfo.File, line: splitToken.Token.SourceInfo.LineNumber.ToString());
                    }
                    var noteToken = (DfmNoteBlockToken)splitToken.Token;
                    content += "<div class=\"";
                    content += noteToken.NoteType.ToUpper();
                    content += "\"";
                    content  = AppendSourceInfo(content, renderer, splitToken.Token);
                    content += ">";
                    string heading;
                    if (Tokens != null && Tokens.TryGetValue(noteToken.NoteType.ToLower(), out heading))
                    {
                        content += heading;
                    }
                    else
                    {
                        content += "<h5>";
                        content += noteToken.NoteType.ToUpper();
                        content += "</h5>";
                    }
                    foreach (var item in splitToken.InnerTokens)
                    {
                        content += renderer.Render(item);
                    }
                    content += "</div>\n";
                }
                else if (splitToken.Token is DfmVideoBlockToken)
                {
                    var videoToken = splitToken.Token as DfmVideoBlockToken;
                    content += "<div class=\"embeddedvideo\"><iframe src=\"";
                    content += videoToken.Link;
                    content += "\" frameborder=\"0\" allowfullscreen=\"true\"";
                    content  = AppendSourceInfo(content, renderer, splitToken.Token);
                    content += "></iframe></div>\n";
                    continue;
                }
                else
                {
                    content += "<blockquote";
                    content  = AppendSourceInfo(content, renderer, splitToken.Token);
                    content += ">";
                    foreach (var item in splitToken.InnerTokens)
                    {
                        content += renderer.Render(item);
                    }
                    content += "</blockquote>\n";
                }
            }
            return(content);
        }
 public void Setup(IMarkdownRenderer renderer)
 {
 }
Esempio n. 39
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
     renderer.ObjectRenderers.InsertBefore <ListRenderer>(new TableOfContentsHtmlRenderer());
 }
Esempio n. 40
0
 public virtual StringBuffer Render(IMarkdownRenderer render, AzureIncludeBlockToken token, MarkdownBlockContext context)
 {
     // Don't add \n\n here because if we render AzureIncludeBlockToken, it will always be wrappered by paragraph. Which already append \n\n
     return(RenderAzureIncludeToken(render, token, context));
 }
Esempio n. 41
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
     ReceivedSetup = true;
 }
Esempio n. 42
0
 public virtual StringBuffer Render(IMarkdownRenderer render, AzureIncludeInlineToken token, MarkdownInlineContext context)
 {
     return(RenderAzureIncludeToken(render, token, context));
 }
Esempio n. 43
0
        private string LoadCore(IMarkdownRenderer adapter, string currentPath, string raw, IMarkdownContext context, Func <string, IMarkdownContext, string> resolver)
        {
            if (!PathUtility.IsRelativePath(currentPath))
            {
                if (!Path.IsPathRooted(currentPath))
                {
                    return(GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Absolute path \"{currentPath}\" is not supported.", raw));
                }
                else
                {
                    currentPath = PathUtility.MakeRelativePath(Environment.CurrentDirectory, currentPath);
                }
            }
            var    parents      = context.GetFilePathStack();
            var    originalPath = currentPath;
            string parent       = string.Empty;

            if (parents == null)
            {
                parents = ImmutableStack <string> .Empty;
            }

            // Update currentPath to be referencing to sourcePath
            else if (!parents.IsEmpty)
            {
                parent      = parents.Peek();
                currentPath = ((RelativePath)currentPath).BasedOn((RelativePath)parent);
            }

            if (parents.Contains(currentPath, FilePathComparer.OSPlatformSensitiveComparer))
            {
                return(GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}: Circular dependency found in \"{parent}\"", raw));
            }

            string result = string.Empty;

            // Add current file path to chain when entering recursion
            parents = parents.Push(currentPath);
            try
            {
                if (!_cache.TryGet(currentPath, out result))
                {
                    var src = File.ReadAllText(currentPath);

                    src = resolver(src, context.SetFilePathStack(parents));

                    HtmlDocument htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(src);
                    var node = htmlDoc.DocumentNode;

                    // If current content is not the root one, update href to root
                    if (parents.Count() > 1)
                    {
                        UpdateHref(node, originalPath);
                    }

                    result = node.WriteTo();
                    result = GenerateNodeWithCommentWrapper("INCLUDE", $"Include content from \"{currentPath}\"", result);
                }
            }
            catch (Exception e)
            {
                result = GenerateErrorNodeWithCommentWrapper("INCLUDE", $"Unable to resolve {raw}:{e.Message}", raw);
            }

            _cache.Add(currentPath, result);

            return(result);
        }
Esempio n. 44
0
 public string Load(IMarkdownRenderer adapter, string currentPath, string raw, IMarkdownContext context, Func <string, IMarkdownContext, string> resolver)
 {
     return(LoadCore(adapter, currentPath, raw, context, resolver));
 }
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) =>
 renderer.ObjectRenderers.Insert(0, Renderer);
Esempio n. 46
0
        public async Task <IActionResult> Commit([FromServices] IMarkdownRenderer renderer, [FromServices] IGit git, string commit)
        {
            var r = await git.Run(new[] { "show", commit });

            return(await MarkdownView(renderer, ContentPath.Root, AsCode(r.Output)));
        }
Esempio n. 47
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmFencesBlockToken token, MarkdownBlockContext context)
 {
     return(Render(renderer, token, (IMarkdownContext)context));
 }
Esempio n. 48
0
 public virtual StringBuffer Render(IMarkdownRenderer render, IMarkdownToken token, IMarkdownContext context)
 {
     return(token.RawMarkdown);
 }
Esempio n. 49
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmVideoBlockToken token, MarkdownBlockContext context)
 {
     return(token.SourceInfo.Markdown);
 }
Esempio n. 50
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return("- - -\n");
 }
Esempio n. 51
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
 }
Esempio n. 52
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            // Generate header line
            content += "|";
            foreach (var header in token.Header)
            {
                content += " ";
                foreach (var t in header.Tokens)
                {
                    content += render.Render(t);
                }
                content += " |";
            }
            content += "\n";

            // Generate align line
            content += "|";
            foreach (var align in token.Align)
            {
                switch (align)
                {
                case Align.NotSpec:
                    content += " --- ";
                    break;

                case Align.Left:
                    content += ":--- ";
                    break;

                case Align.Right:
                    content += " ---:";
                    break;

                case Align.Center:
                    content += ":---:";
                    break;

                default:
                    throw new NotSupportedException($"align:{align} doesn't support in GFM table");
                }
                content += "|";
            }
            content += "\n";

            // Generate content lines
            foreach (var row in token.Cells)
            {
                content += "| ";
                foreach (var column in row)
                {
                    foreach (var t in column.Tokens)
                    {
                        content += render.Render(t);
                    }
                    content += " |";
                }
                content += "\n";
            }

            return(content += "\n");
        }
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) => renderer.ObjectRenderers.AddIfNotAlready(new LinkerRenderAdapter(LinkRenderers));
Esempio n. 54
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmIncludeBlockToken token, MarkdownBlockContext context)
 {
     return(string.IsNullOrEmpty(token.Title)
             ? $"[!INCLUDE [{token.Name}]({token.Src})]\n\n"
             : $"[!INCLUDE [{token.Name}]({token.Src} \"{token.Title}\")]\n\n");
 }
Esempio n. 55
0
        // GET: /<controller>/
        public async Task <IActionResult> Index(
            [FromServices] IContentProvider contentProvider,
            [FromServices] IMarkdownRenderer renderer,
            [FromServices] IHistory history,
            [FromServices] IGit git,
            [FromQuery] string log,
            [FromQuery] string q,
            string path)
        {
            var contentPath = ContentPath.FromUrlPath(path);

            if (this.HttpContext.WebSockets.IsWebSocketRequest)
            {
                await NotifyContentChanged(this.HttpContext.WebSockets, contentProvider, contentPath);

                return(Ok());
            }

            if (log != null)
            {
                var r = await git.Run(new[] { "log" }.Concat(Utils.SplitArguments(log)).Concat(new[] { "--", git.GetPath(contentPath) }));

                return(await MarkdownView(renderer, contentPath, AsCode(r.Output)));
            }

            if (q != null)
            {
                var pretty  = $"--pretty=format:* [%ar: %s]({git.GetPath(contentPath)}?log=--stat+-p+-1+-U+%H), by %an";
                var grepLog = await git.Run(new[] { "log", pretty, "-100", "-S", q, git.GetPath(contentPath) });

                var grepText = git.GrepOutputToMarkdown((await git.Run(new[] { "grep", "-I", "-n", q })).Output);
                return(await MarkdownView(renderer, contentPath, grepLog.Output + hr + grepText));
            }

            var children = contentProvider.GetChildren(contentPath);

            if (children.Any())
            {
                if (!this.HttpContext.Request.Path.Value.EndsWith("/"))
                {
                    var url        = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedUrl(this.HttpContext.Request);
                    var redirectTo = url + "/";
                    return(this.Redirect(redirectTo));
                }
                return(await MarkdownView(renderer, contentPath, GetDirectoryMarkdown(contentProvider, history, contentPath, children)));
            }

            if (contentPath.IsExtension(new[] { ".md" }))
            {
                return(await MarkdownView(renderer, contentPath, GetMarkdown(contentProvider, history, contentPath)));
            }

            var mdFile = contentPath.CatName(".md");

            if (mdFile.HasValue && contentProvider.Exists(mdFile.Value))
            {
                return(await MarkdownView(renderer, contentPath, GetText(contentProvider, mdFile.Value)));
            }

            if (IsText(contentProvider, contentPath))
            {
                return(await MarkdownView(renderer, contentPath, GetSourceAsMarkdown(contentProvider, history, contentPath)));
            }

            contentProvider.Pull();

            // raw file
            return(await Raw(contentProvider, path));
        }
Esempio n. 56
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmNoteBlockToken token, MarkdownBlockContext context)
 {
     return($"[!{token.NoteType}]\n");
 }
Esempio n. 57
0
        public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
        {
            var index = renderer.ObjectRenderers.FindIndex(r => r.GetType() == typeof(LinkInlineRenderer));

            renderer.ObjectRenderers[index] = new EmbeddedImageLinkInlineRenderer(this.BaseDirectory);
        }
Esempio n. 58
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
     PipelineHelpers.SetupSyntaxRender(renderer);
 }
Esempio n. 59
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
     // Nothing to setup, JiraLinks used a normal LinkInlineRenderer
 }
Esempio n. 60
0
        async Task <IActionResult> MarkdownView(IMarkdownRenderer renderer, ContentPath path, Option <string> markdown)
        {
            var result = await renderer.Render(markdown.ValueOr("empty"));

            return(View("Index", new ContentModel(path, result.Title.ValueOr(path.GetDisplayName("Home")), result.Body)));
        }