Наследование: 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);
Пример #13
0
 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);
Пример #16
0
 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));
 }