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); }
public override bool ValidateAndPrepare(string[] lines, DfmFencesToken token) { foreach (var pair in LinePairs) { if (!CheckLineRange(lines.Length, pair.Item1, pair.Item2)) { return false; } } return true; }
public static string GetRenderedFencesBlockString(DfmFencesToken token, Options options, string errorMessage, string[] codeLines = null) { string renderedErrorMessage = string.Empty; string renderedCodeLines = string.Empty; if (!string.IsNullOrEmpty(errorMessage)) { renderedErrorMessage = $"<!-- {StringHelper.HtmlEncode(errorMessage)} -->\n"; } if (codeLines != null) { var lang = string.IsNullOrEmpty(token.Lang) ? null : $" class=\"{options.LangPrefix}{token.Lang}\""; var name = string.IsNullOrEmpty(token.Name) ? null : $" name=\"{StringHelper.HtmlEncode(token.Name)}\""; var title = string.IsNullOrEmpty(token.Title) ? null : $" title=\"{StringHelper.HtmlEncode(token.Title)}\""; var highlight = string.IsNullOrEmpty(token.PathQueryOption?.HighlightLines) ? null : $" highlight-lines=\"{StringHelper.HtmlEncode(token.PathQueryOption.HighlightLines)}\""; renderedCodeLines = $"<pre><code{lang}{name}{title}{highlight}>{StringHelper.HtmlEncode(string.Join("\n", codeLines))}\n</code></pre>"; } return $"{renderedErrorMessage}{renderedCodeLines}"; }
public virtual StringBuffer RenderCloseCodeTag(StringBuffer result, DfmFencesToken token, Options options) { return(result + "</code>"); }
public virtual StringBuffer RenderOpenPreTag(StringBuffer result, DfmFencesToken token, Options options) { result += "<pre"; result = HtmlRenderer.AppendSourceInfo(result, options, token); return(result + ">"); }
public virtual DfmExtractCodeResult ExtractCode(DfmFencesToken token, string[] fencesCode) { return(_dfmCodeExtractor.ExtractFencesCode(token, fencesCode)); }
public virtual string FindFile(DfmFencesToken token, IMarkdownContext context) { return(DfmFallbackHelper.GetFilePathWithFallback(token.Path, context).Item1); }
public static string GenerateErrorMessage(DfmFencesToken token, string message) { return($"{message} when resolving \"{token.SourceInfo.Markdown.Trim()}\""); }
public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmFencesToken token, IMarkdownContext context) { if (!TypeForwardedToPathUtility.IsRelativePath(token.Path)) { string errorMessage = $"Code absolute path: {token.Path} is not supported in file {context.GetFilePathStack().Peek()}"; Logger.LogError(errorMessage); return DfmFencesBlockHelper.GetRenderedFencesBlockString(token, renderer.Options, errorMessage); } try { // Always report original dependency context.ReportDependency(token.Path); var filePathWithStatus = DfmFallbackHelper.GetFilePathWithFallback(token.Path, context); var extractResult = _dfmCodeExtractor.ExtractFencesCode(token, filePathWithStatus.Item1); var result = DfmFencesBlockHelper.GetRenderedFencesBlockString(token, renderer.Options, extractResult.ErrorMessage, extractResult.FencesCodeLines); return result; } catch (DirectoryNotFoundException) { return DfmFencesBlockHelper.GenerateReferenceNotFoundErrorMessage(renderer, token); } catch (FileNotFoundException) { return DfmFencesBlockHelper.GenerateReferenceNotFoundErrorMessage(renderer, token); } }
private static string GetCodeLanguageOrExtension(DfmFencesToken token) { return(!string.IsNullOrEmpty(token.Lang) ? token.Lang : Path.GetExtension(token.Path)); }
public bool ValidateAndPrepare(string[] lines, DfmFencesToken token) { throw new NotSupportedException(); }
public abstract IEnumerable <string> GetQueryLines(string[] lines, DfmFencesToken token);
public override bool ValidateAndPrepare(string[] lines, DfmFencesToken token) { return true; }
private static string GenerateErrorMessage(DfmFencesToken token) { return($"{token.PathQueryOption.ErrorMessage} when resolving \"{token.SourceInfo.Markdown.Trim()}\""); }
public DfmExtractCodeResult ExtractFencesCode(DfmFencesToken token, string fencesPath) => ExtractFencesCode(token, fencesPath, null);
public abstract bool ValidateAndPrepare(string[] lines, DfmFencesToken token);
public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmFencesToken token, IMarkdownContext context) { return(_codeRenderer.Render(renderer, token, context)); }
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}."; Logger.LogError(errorMessage, line: token.SourceInfo.LineNumber.ToString()); return(GetRenderedFencesBlockString(token, renderer.Options, errorMessageInMarkdown)); }
public static string GenerateErrorMessage(DfmFencesToken token, IDfmFencesBlockPathQueryOption option) { return(GenerateErrorMessage(token, option.ErrorMessage)); }