Inheritance: IMarkdownToken
示例#1
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);
 }
        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;
        }
示例#3
0
        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}";
        }
示例#4
0
 public virtual StringBuffer RenderCloseCodeTag(StringBuffer result, DfmFencesToken token, Options options)
 {
     return(result + "</code>");
 }
示例#5
0
 public virtual StringBuffer RenderOpenPreTag(StringBuffer result, DfmFencesToken token, Options options)
 {
     result += "<pre";
     result  = HtmlRenderer.AppendSourceInfo(result, options, token);
     return(result + ">");
 }
示例#6
0
 public virtual DfmExtractCodeResult ExtractCode(DfmFencesToken token, string[] fencesCode)
 {
     return(_dfmCodeExtractor.ExtractFencesCode(token, fencesCode));
 }
示例#7
0
 public virtual string FindFile(DfmFencesToken token, IMarkdownContext context)
 {
     return(DfmFallbackHelper.GetFilePathWithFallback(token.Path, context).Item1);
 }
示例#8
0
 public static string GenerateErrorMessage(DfmFencesToken token, string message)
 {
     return($"{message} when resolving \"{token.SourceInfo.Markdown.Trim()}\"");
 }
示例#9
0
        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);
            }
        }
示例#10
0
 private static string GetCodeLanguageOrExtension(DfmFencesToken token)
 {
     return(!string.IsNullOrEmpty(token.Lang) ? token.Lang : Path.GetExtension(token.Path));
 }
示例#11
0
 public bool ValidateAndPrepare(string[] lines, DfmFencesToken token)
 {
     throw new NotSupportedException();
 }
示例#12
0
 public abstract IEnumerable <string> GetQueryLines(string[] lines, DfmFencesToken token);
 public override bool ValidateAndPrepare(string[] lines, DfmFencesToken token)
 {
     return true;
 }
示例#14
0
 private static string GenerateErrorMessage(DfmFencesToken token)
 {
     return($"{token.PathQueryOption.ErrorMessage} when resolving \"{token.SourceInfo.Markdown.Trim()}\"");
 }
示例#15
0
 public DfmExtractCodeResult ExtractFencesCode(DfmFencesToken token, string fencesPath)
 => ExtractFencesCode(token, fencesPath, null);
 public abstract bool ValidateAndPrepare(string[] lines, DfmFencesToken token);
示例#17
0
 public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmFencesToken token, IMarkdownContext context)
 {
     return(_codeRenderer.Render(renderer, token, context));
 }
示例#18
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}.";

            Logger.LogError(errorMessage, line: token.SourceInfo.LineNumber.ToString());
            return(GetRenderedFencesBlockString(token, renderer.Options, errorMessageInMarkdown));
        }
示例#19
0
 public static string GenerateErrorMessage(DfmFencesToken token, IDfmFencesBlockPathQueryOption option)
 {
     return(GenerateErrorMessage(token, option.ErrorMessage));
 }