本文整理汇总了C#中IMarkdownRenderer类的典型用法代码示例。如果您正苦于以下问题:C# IMarkdownRenderer类的具体用法?C# IMarkdownRenderer怎么用?C# IMarkdownRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMarkdownRenderer类属于命名空间,在下文中一共展示了IMarkdownRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public virtual StringBuffer Render(IMarkdownRenderer render, DfmYamlHeaderBlockToken token, MarkdownBlockContext context)
{
StringBuffer content = "---\n";
content += token.Content;
content += "\n---\n";
return content;
}
示例2: Render
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;
}
示例3: GenerateReferenceNotFoundErrorMessage
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);
}
示例4: Render
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 += [email protected]"<iframe width=""{azureVideoInfo.Width}"" height=""{azureVideoInfo.Height}"" src=""{azureVideoInfo.Link}"" frameborder=""0"" allowfullscreen=""true""></iframe>";
return content + "\n\n";
}
示例5: Render
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);
}
}
示例6: Render
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;
}
示例7: Render
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";
}
示例8: Render
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: Render
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);
}
示例10: RenderAzureIncludeToken
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;
}
示例11: Render
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;
}
示例12: Render
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);
}
示例13: LoadCore
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);
}
}
示例14: Render
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");
}
}
示例15: RenderImageNormalLink
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;
}