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); }
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 Insert(token, ExposeTokenName(token), childContent); }
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(Insert(token, ExposeTokenName(token), childContent)); }
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) { content += renderer.Render(splitToken); } return(content); }
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) { 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.ToUpper(); 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 { content += "<blockquote>"; foreach (var item in splitToken.InnerTokens) { content += renderer.Render(item); } content += "</blockquote>\n"; } } return(content); }
public override StringBuffer Render(MarkdownEngine engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context) { if (token.Tokens.Length > 0) { var ft = token.Tokens[0] as DfmNoteBlockToken; if (ft != null) { return($"<blockquote class=\"{ft.NoteType}\">" + RenderTokens(engine, token.Tokens.RemoveAt(0), context, true, token.Rule) + "</blockquote>"); } } return(base.Render(engine, token, context)); }
public override StringBuffer Render(MarkdownEngine engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context) { if (token.Tokens.Length > 0) { var ft = token.Tokens[0] as DfmNoteBlockToken; if (ft != null) { return $"<blockquote class=\"{ft.NoteType}\">" + RenderTokens(engine, token.Tokens.RemoveAt(0), context, true, token.Rule) + "</blockquote>"; } } return base.Render(engine, token, context); }
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)); }
public override StringBuffer Render(IMarkdownRenderer render, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context) { const string BlockQuoteStartString = "> "; const string BlockQuoteJoinString = "\n" + BlockQuoteStartString; var source = token.SourceInfo.Markdown; var content = StringBuffer.Empty; for (var index = 0; index < token.Tokens.Length; index++) { var t = token.Tokens[index]; if (index == token.Tokens.Length - 1 && t is DfmVideoBlockToken videoToken) { content += render.Render(t).ToString().TrimEnd(); } else { 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; } } var newlinesCount = Helper.CountEndNewLine(source); return(content + new string('\n', newlinesCount)); }
public override StringBuffer Render(IMarkdownRenderer render, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context) { const string BlockQuoteStartString = "> "; const string BlockQuoteJoinString = "\n" + BlockQuoteStartString; var content = StringBuffer.Empty; var tokens = (from t in token.Tokens where !(t is MarkdownNewLineBlockToken) select t).ToList(); for (var index = 0; index < tokens.Count; index++) { var t = tokens[index]; if (index == tokens.Count - 1 && t is DfmVideoBlockToken videoToken) { content += render.Render(t).ToString().TrimEnd(); } else { 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 + "\n\n"); }
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); }