Пример #1
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";
        }
Пример #2
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;
 }
Пример #3
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmYamlHeaderBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = "---\n";
     content += token.Content;
     content += "\n---\n";
     return content;
 }
Пример #4
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmIncludeBlockToken token, MarkdownBlockContext context)
 {
     lock (_blockInclusionHelper)
     {
         return _blockInclusionHelper.Load(renderer, token.Src, token.Raw, token.SourceInfo, context, (DfmEngine)renderer.Engine);
     }
 }
Пример #5
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";
        }
Пример #6
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;
        }
Пример #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;
        }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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";
 }
Пример #11
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";
 }
Пример #12
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>";
 }
Пример #13
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";
 }
Пример #14
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
 {
     string level = token.Depth.ToString();
     var result = (StringBuffer)"<h"
         + level
         + " id=\""
         + engine.Options.HeaderPrefix
         + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
         + "\">";
     var c = engine.SwitchContext(context.InlineContext);
     result += engine.Mark(token.Content);
     engine.SwitchContext(c);
     result += "</h";
     result += level;
     result += ">\n";
     return result;
 }
Пример #15
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;
 }
Пример #16
0
 public override StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer content = string.Empty;
     var splitTokens = DfmRendererHelper.SplitBlockquoteTokens(token.Tokens);
     foreach (var splitToken in splitTokens)
     {
         if (splitToken.Token is DfmSectionBlockToken)
         {
             content += "<div";
             content += ((DfmSectionBlockToken)splitToken.Token).Attributes;
             content += ">";
             foreach (var item in splitToken.InnerTokens)
             {
                 content += renderer.Render(item);
             }
             content += "</div>\n";
         }
         else if (splitToken.Token is DfmNoteBlockToken)
         {
             var noteToken = (DfmNoteBlockToken)splitToken.Token;
             content += "<div class=\"";
             content += noteToken.NoteType;
             content += "\"><h5>";
             content += noteToken.NoteType;
             content += "</h5>";
             foreach (var item in splitToken.InnerTokens)
             {
                 content += renderer.Render(item);
             }
             content += "</div>\n";
         }
         else
         {
             content += "<blockquote>";
             foreach (var item in splitToken.InnerTokens)
             {
                 content += renderer.Render(item);
             }
             content += "</blockquote>\n";
         }
     }
     return content;
 }
Пример #17
0
        public override StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = StringBuffer.Empty;
            var splitTokens = DfmBlockquoteHelper.SplitBlockquoteTokens(token.Tokens);
            foreach (var splitToken in splitTokens)
            {
                var sectionToken = splitToken.Token as DfmSectionBlockToken;
                if (sectionToken != null)
                {
                    content += Insert(sectionToken, ExposeTokenNameInDfm(sectionToken));
                    foreach (var item in splitToken.InnerTokens)
                    {
                        content += renderer.Render(item);
                    }
                    continue;
                }

                var noteToken = splitToken.Token as DfmNoteBlockToken;
                if (noteToken != null)
                {
                    var type = noteToken.NoteType.ToUpper();
                    content += Insert(noteToken, type);
                    foreach (var item in splitToken.InnerTokens)
                    {
                        content += renderer.Render(item);
                    }
                    continue;
                }

                var videoToken = splitToken.Token as DfmVideoBlockToken;
                if (videoToken != null)
                {
                    content += Insert(videoToken, $"{ExposeTokenNameInDfm(videoToken)}>{videoToken.Link}");
                    continue;
                }

                foreach (var item in splitToken.InnerTokens)
                {
                    content += renderer.Render(item);
                }
            }
            return Insert(token, ExposeTokenNameInDfm(token), content);
        }
Пример #18
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmYamlHeaderBlockToken token, MarkdownBlockContext context)
        {
            if (string.IsNullOrEmpty(token.Content))
            {
                return StringBuffer.Empty;
            }
            var startLine = token.SourceInfo.LineNumber;
            var endLine = startLine + token.Content.Count(ch => ch == '\n') + 2;
            var sourceFile = token.SourceInfo.File;

            StringBuffer result = $"<yamlheader start=\"{startLine}\" end=\"{endLine}\"";
            if (!string.IsNullOrEmpty(sourceFile))
            {
                sourceFile = StringHelper.HtmlEncode(sourceFile);
                result += $" sourceFile=\"{sourceFile}\"";
            }
            result += ">";
            result += StringHelper.HtmlEncode(token.Content);
            return result + "</yamlheader>";
        }
Пример #19
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, DfmFencesBlockToken token, MarkdownBlockContext context)
        {
            if (!PathUtility.IsRelativePath(token.Path))
            {
                string errorMessage = $"Code absolute path: {token.Path} is not supported in file {context.GetFilePathStack().Peek()}";
                Logger.LogError(errorMessage);
                return DfmRendererHelper.GetRenderedFencesBlockString(token, engine.Options, errorMessage);
            }

            try
            {
                // TODO: Valid REST and REST-i script.
                var fencesPath = ((RelativePath)token.Path).BasedOn((RelativePath)context.GetFilePathStack().Peek());
                var extractResult = _dfmCodeExtractor.ExtractFencesCode(token, fencesPath);
                return DfmRendererHelper.GetRenderedFencesBlockString(token, engine.Options, extractResult.ErrorMessage, extractResult.FencesCodeLines);
            }
            catch (FileNotFoundException)
            {
                string errorMessage = $"Can not find reference {token.Path}";
                Logger.LogError(errorMessage);
                return DfmRendererHelper.GetRenderedFencesBlockString(token, engine.Options, errorMessage);
            }
        }
Пример #20
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return engine.Options.XHtml ? "<hr/>\n" : "<hr>\n";
 }
Пример #21
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.Content.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.Content.Tokens)
                    {
                        content += render.Render(t);
                    }
                    content += " |";
                }
                content += "\n";
            }

            return(content += "\n");
        }
Пример #22
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<table>\n<thead>\n";
     // header
     result += "<tr>\n";
     var cell = StringBuffer.Empty;
     for (int i = 0; i < token.Header.Length; i++)
     {
         if (i < token.Align.Length && token.Align[i] != Align.NotSpec)
         {
             result += "<th style=\"text-align:";
             result += token.Align[i].ToString().ToLower();
             result += "\">";
         }
         else
         {
             result += "<th>";
         }
         foreach (var item in token.Header[i].Tokens)
         {
             result += engine.Render(item);
         }
         result += "</th>\n";
     }
     result += "</tr>\n";
     result += "</thead>\n";
     result += "<tbody>\n";
     // body
     for (int i = 0; i < token.Cells.Length; i++)
     {
         var row = token.Cells[i];
         result += "<tr>\n";
         for (int j = 0; j < row.Length; j++)
         {
             if (j < token.Align.Length && token.Align[j] != Align.NotSpec)
             {
                 result += "<td style=\"text-align:";
                 result += token.Align[j].ToString().ToLower();
                 result += "\">";
             }
             else
             {
                 result += "<td>";
             }
             foreach (var item in row[j].Tokens)
             {
                 result += engine.Render(item);
             }
             result += "</td>\n";
         }
         result += "</tr>\n";
     }
     return result + "</tbody>\n" + "</table>\n";
 }
Пример #23
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownNonParagraphBlockToken token, MarkdownBlockContext context)
 {
     var result = StringBuffer.Empty;
     foreach (var item in token.Content.Tokens)
     {
         result += renderer.Render(item);
     }
     return result;
 }
Пример #24
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     if (!token.Pre && !engine.Options.Pedantic)
     {
         var c      = engine.SwitchContext(context.InlineContext);
         var result = engine.Mark(token.Content);
         engine.SwitchContext(c);
         return(result);
     }
     else
     {
         return(token.Content);
     }
 }
Пример #25
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<p>";
     foreach (var item in token.InlineTokens.Tokens)
     {
         result += engine.Render(item);
     }
     result += "</p>\n";
     return result;
 }
Пример #26
0
        public virtual StringBuffer Render(MarkdownEngine 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, context);
            }
            return(content + "</" + type + ">\n");
        }
Пример #27
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTextToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<p>";

            result += token.Content;
            result += "</p>\n";
            return(result);
        }
Пример #28
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return(engine.Options.XHtml ? "<hr/>\n" : "<hr>\n");
 }
Пример #29
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = "<blockquote>\n";

            content += RenderTokens(engine, token.Tokens, context, true, token.Rule);
            return(content + "</blockquote>\n");
        }
Пример #30
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
        {
            string level  = token.Depth.ToString();
            var    result = (StringBuffer)"<h"
                            + level
                            + " id=\""
                            + engine.Options.HeaderPrefix
                            + Regex.Replace(token.Content.ToLower(), @"[^\w]+", "-")
                            + "\">";
            var c = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</h";
            result += level;
            result += ">\n";
            return(result);
        }
Пример #31
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownTableBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<table>\n<thead>\n";

            // header
            result += "<tr>\n";
            var cell = StringBuffer.Empty;
            var c    = engine.SwitchContext(context.InlineContext);

            for (int i = 0; i < token.Header.Length; i++)
            {
                if (i < token.Align.Length && token.Align[i] != Align.NotSpec)
                {
                    result += "<th style=\"text-align:";
                    result += token.Align[i].ToString().ToLower();
                    result += "\">";
                }
                else
                {
                    result += "<th>";
                }
                result += engine.Mark(token.Header[i]);
                result += "</th>\n";
            }
            result += "</tr>\n";
            result += "</thead>\n";
            result += "<tbody>\n";
            // body
            for (int i = 0; i < token.Cells.Length; i++)
            {
                var row = token.Cells[i];
                result += "<tr>\n";
                for (int j = 0; j < row.Length; j++)
                {
                    if (j < token.Align.Length && token.Align[j] != Align.NotSpec)
                    {
                        result += "<td style=\"text-align:";
                        result += token.Align[j].ToString().ToLower();
                        result += "\">";
                    }
                    else
                    {
                        result += "<td>";
                    }
                    result += engine.Mark(row[j]);
                    result += "</td>\n";
                }
                result += "</tr>\n";
            }
            engine.SwitchContext(c);
            return(result + "</tbody>\n" + "</table>\n");
        }
Пример #32
0
        public virtual StringBuffer Render(MarkdownEngine 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");
        }
Пример #33
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmBlockquoteBlockToken token, MarkdownBlockContext context)
 {
     return Render(render, (MarkdownBlockquoteBlockToken)token, context);
 }
Пример #34
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownListItemBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = "<li>";

            content += RenderTokens(engine, token.Tokens, context, token.Loose, token.Rule);
            return(content + "</li>\n");
        }
Пример #35
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, DfmNoteBlockToken token, MarkdownBlockContext context)
 {
     return token.Content;
 }
Пример #36
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownCodeBlockToken token, MarkdownBlockContext context)
 {
     return(this.Insert("Code(" + token.Lang + ")", this.GetSize(), Type.Leaf));
 }
Пример #37
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));
        }
Пример #38
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);
        }
Пример #39
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownHtmlBlockToken token, MarkdownBlockContext context)
 {
     var result = StringBuffer.Empty;
     foreach (var item in token.Content.Tokens)
     {
         result += engine.Render(item);
     }
     return result;
 }
Пример #40
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));
        }
Пример #41
0
 public virtual StringBuffer Render(IMarkdownRenderer engine, MarkdownTextToken token, MarkdownBlockContext context)
 {
     StringBuffer result = "<p>";
     result += token.Content;
     result += "</p>\n";
     return result;
 }
Пример #42
0
        public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            var childContent = StringBuffer.Empty;

            foreach (var item in token.Tokens)
            {
                childContent += renderer.Render(item);
            }
            return(this.Insert("Blockquote", childContent, Type.NonLeaf));
        }
Пример #43
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));
        }
Пример #44
0
        protected StringBuffer RenderTokens(MarkdownEngine engine, ImmutableArray <IMarkdownToken> tokens, MarkdownBlockContext context, bool wrapParagraph = false, IMarkdownRule rule = null)
        {
            var content     = StringBuffer.Empty;
            var textContent = StringBuffer.Empty;

            foreach (var t in tokens)
            {
                var text = t as MarkdownTextToken;
                if (text != null)
                {
                    if (textContent != StringBuffer.Empty)
                    {
                        textContent += "\n";
                    }
                    textContent += text.Content;
                    continue;
                }
                if (!wrapParagraph && t is MarkdownNewLineBlockToken)
                {
                    continue;
                }
                if (textContent != StringBuffer.Empty)
                {
                    content    += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
                    textContent = StringBuffer.Empty;
                }
                content += engine.Render(t, context);
            }
            if (textContent != StringBuffer.Empty)
            {
                content += RenderTextInTokens(engine, context, wrapParagraph, rule, textContent);
            }
            return(content);
        }
Пример #45
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownListBlockToken token, MarkdownBlockContext context)
        {
            var content = StringBuffer.Empty;

            if (!token.Ordered)
            {
                const string ListStartString = "* ";
                foreach (var t in token.Tokens)
                {
                    var listItemToken = t as MarkdownListItemBlockToken;
                    if (listItemToken == null)
                    {
                        throw new Exception($"token {t.GetType()} is not unordered MarkdownListItemBlockToken in MarkdownListBlockToken. Token raw:{t.SourceInfo.Markdown}");
                    }
                    content += ListStartString;
                    content += Render(render, listItemToken, "  ");
                }
            }
            else
            {
                for (int i = 0; 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 ordered MarkdownListItemBlockToken in MarkdownListBlockToken. Token raw:{token.Tokens[i].SourceInfo.Markdown}");
                    }

                    content += $"{i + 1}. ";
                    string indent = new string(' ', (i + 1).ToString().Length + 2);
                    content += Render(render, listItemToken, indent);
                }
            }
            return(content + "\n");
        }
Пример #46
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownHeadingBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content = StringBuffer.Empty;

            for (int i = 0; i < token.Depth; ++i)
            {
                content += "#";
            }
            content += " ";

            foreach (var t in token.Content.Tokens)
            {
                content += render.Render(t);
            }
            content += "\n";
            return(content);
        }
Пример #47
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().TrimEnd('\n').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 + "\n\n");
        }
Пример #48
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);
        }
Пример #49
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmIncludeBlockToken token, MarkdownBlockContext context)
 {
     return string.IsNullOrEmpty(token.Title)
             ? $"[!INCLUDE [{token.Name}]({token.Src})]\n"
             : $"[!INCLUDE [{token.Name}]({token.Src} \"{token.Title}\")]\n";
 }
Пример #50
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");
        }
Пример #51
0
 public virtual StringBuffer Render(IMarkdownRenderer render, DfmNoteBlockToken token, MarkdownBlockContext context)
 {
     return $"[!{token.NoteType}]\n";
 }
Пример #52
0
        protected virtual StringBuffer ApplyInline(MarkdownEngine engine, StringBuffer content, MarkdownBlockContext context)
        {
            if (content == StringBuffer.Empty)
            {
                return(StringBuffer.Empty);
            }
            var c      = engine.SwitchContext(context.InlineContext);
            var result = engine.Mark(content.ToString());

            engine.SwitchContext(c);
            return(result);
        }
Пример #53
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return(Insert(token, ExposeTokenName(token)));
 }
Пример #54
0
        public virtual StringBuffer Render(MarkdownEngine engine, MarkdownParagraphBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer result = "<p>";
            var          c      = engine.SwitchContext(context.InlineContext);

            result += engine.Mark(token.Content);
            engine.SwitchContext(c);
            result += "</p>\n";
            return(result);
        }
Пример #55
0
        public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownListItemBlockToken token, MarkdownBlockContext context)
        {
            // TODO: Add corresponding white space before the result
            var content = StringBuffer.Empty;

            foreach (var t in token.Tokens)
            {
                content += render.Render(t);
            }
            return(content);
        }
Пример #56
0
 public virtual StringBuffer Render(MarkdownEngine engine, MarkdownNewLineBlockToken token, MarkdownBlockContext context)
 {
     // do nothing.
     return(StringBuffer.Empty);
 }
Пример #57
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(this.Insert("Heading" + level, childContent, Type.NonLeaf));
        }
Пример #58
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return("- - -\n");
 }
Пример #59
0
 public virtual StringBuffer Render(IMarkdownRenderer render, MarkdownListItemBlockToken token, MarkdownBlockContext context)
 {
     // TODO: Add corresponding white space before the result
     var content = StringBuffer.Empty;
     foreach (var t in token.Tokens)
     {
         content += render.Render(t);
     }
     return content;
 }
Пример #60
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, MarkdownHrBlockToken token, MarkdownBlockContext context)
 {
     return(this.Insert("Hr", this.GetSize(), Type.Leaf));
 }