public virtual StringBuffer RenderFencesCode(DfmFencesToken token, Options options, string errorMessage, string[] codeLines = null, IDfmFencesBlockPathQueryOption pathQueryOption = null) { StringBuffer result; string renderedErrorMessage = string.Empty; string renderedCodeLines = string.Empty; if (!string.IsNullOrEmpty(errorMessage)) { result = RenderCodeErrorString(errorMessage); } else { result = StringBuffer.Empty; } if (codeLines != null) { result = RenderOpenPreTag(result, token, options); result = RenderOpenCodeTag(result, token, options, pathQueryOption); foreach (var line in codeLines) { result += StringHelper.HtmlEncode(line); result += "\n"; } result = RenderCloseCodeTag(result, token, options); result = RenderClosePreTag(result, token, options); } return(result); }
public DfmFencesToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang, string title, IDfmFencesBlockPathQueryOption pathQueryOption) { Rule = rule; Context = context; Path = path; Lang = lang; Name = name; Title = title; PathQueryOption = pathQueryOption; SourceInfo = sourceInfo; }
public DfmFencesBlockToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, string rawMarkdown, string lang = null, string title = null, IDfmFencesBlockPathQueryOption pathQueryOption = null) { Rule = rule; Context = context; Path = path; Lang = lang; Name = name; Title = title; PathQueryOption = pathQueryOption; RawMarkdown = rawMarkdown; }
public DfmExtractCodeResult ExtractFencesCode(DfmFencesToken token, string[] fencesCode, IDfmFencesBlockPathQueryOption pathQueryOption) { if (token == null) { throw new ArgumentNullException(nameof(token)); } if (fencesCode == null) { throw new ArgumentNullException(nameof(fencesCode)); } using (new LoggerPhaseScope("Extract Dfm Code")) { if (pathQueryOption == null) { // Add the full file when no query option is given return(new DfmExtractCodeResult { IsSuccessful = true, CodeLines = Dedent(fencesCode), }); } if (!pathQueryOption.ValidateAndPrepare(fencesCode, token)) { Logger.LogWarning(GenerateErrorMessage(token, pathQueryOption), line: token.SourceInfo.LineNumber.ToString(), code: WarningCodes.Markdown.InvalidCodeSnippet); return(new DfmExtractCodeResult { IsSuccessful = false, ErrorMessage = pathQueryOption.ErrorMessage, CodeLines = fencesCode }); } if (!string.IsNullOrEmpty(pathQueryOption.ErrorMessage)) { Logger.LogWarning(GenerateErrorMessage(token, pathQueryOption), line: token.SourceInfo.LineNumber.ToString()); } var includedLines = pathQueryOption.GetQueryLines(fencesCode).ToList(); if (!pathQueryOption.ValidateHighlightLinesAndDedentLength(includedLines.Count)) { Logger.LogWarning(GenerateErrorMessage(token, pathQueryOption), line: token.SourceInfo.LineNumber.ToString()); } return(new DfmExtractCodeResult { IsSuccessful = true, ErrorMessage = pathQueryOption.ErrorMessage, CodeLines = Dedent(includedLines, pathQueryOption.DedentLength) }); } }
public DfmExtractCodeResult ExtractFencesCode(DfmFencesToken token, string fencesPath, IDfmFencesBlockPathQueryOption pathQueryOption) { if (token == null) { throw new ArgumentNullException(nameof(token)); } if (string.IsNullOrEmpty(fencesPath)) { throw new ArgumentNullException(nameof(fencesPath)); } using (new LoggerPhaseScope("Extract Dfm Code From Path")) { var fencesCode = EnvironmentContext.FileAbstractLayer.ReadAllLines(fencesPath); return(ExtractFencesCode(token, fencesCode, pathQueryOption)); } }
private static string GenerateErrorMessage(DfmFencesToken token, IDfmFencesBlockPathQueryOption option) { return($"{option.ErrorMessage} when resolving \"{token.SourceInfo.Markdown.Trim()}\""); }
public DfmFencesToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang, string title, IDfmFencesBlockPathQueryOption pathQueryOption) : this(rule, context, name, path, sourceInfo, lang, title, pathQueryOption, null) { }
public DfmFencesInlineToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang = null, string title = null, IDfmFencesBlockPathQueryOption pathQueryOption = null, string queryStringAndFragment = null) : base(rule, context, name, path, sourceInfo, lang, title, pathQueryOption, queryStringAndFragment) { }
public virtual StringBuffer RenderOpenCodeTag(StringBuffer result, DfmFencesToken token, Options options, IDfmFencesBlockPathQueryOption pathQueryOption) { result += "<code"; if (!string.IsNullOrEmpty(token.Lang)) { result = result + " class=\"" + options.LangPrefix + token.Lang + "\""; } if (!string.IsNullOrEmpty(token.Name)) { result = result + " name=\"" + StringHelper.HtmlEncode(token.Name) + "\""; } if (!string.IsNullOrEmpty(token.Title)) { result = result + " title=\"" + StringHelper.HtmlEncode(token.Title) + "\""; } if (!string.IsNullOrEmpty(pathQueryOption?.HighlightLines)) { result = result + " highlight-lines=\"" + StringHelper.HtmlEncode(pathQueryOption.HighlightLines) + "\""; } result += ">"; return(result); }
public virtual DfmExtractCodeResult ExtractCode(DfmFencesToken token, string[] fencesCode, IDfmFencesBlockPathQueryOption option) { return(_dfmCodeExtractor.ExtractFencesCode(token, fencesCode, option)); }
public DfmFencesInlineToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang = null, string title = null, IDfmFencesBlockPathQueryOption pathQueryOption = null) : base(rule, context, name, path, sourceInfo, lang, title, pathQueryOption) { }
public override StringBuffer RenderOpenCodeTag(StringBuffer result, DfmFencesToken token, Options options, IDfmFencesBlockPathQueryOption pathQueryOption) { var lang = GetLang(token, out bool isInteractive); var gitUrl = GetGitUrl(token); result += "<code"; if (!string.IsNullOrEmpty(lang)) { result = result + " class=\"" + options.LangPrefix + lang + "\""; if (isInteractive) { result += " data-interactive=\""; result += StringHelper.HtmlEncode(lang); result += "\""; } } if (gitUrl != null && gitUrl.StartsWith("https://github.com/")) { result += " data-src=\""; result += StringHelper.HtmlEncode(gitUrl); result += "\""; } if (!string.IsNullOrEmpty(token.Name)) { result = result + " name=\"" + StringHelper.HtmlEncode(token.Name) + "\""; } if (!string.IsNullOrEmpty(token.Title)) { result = result + " title=\"" + StringHelper.HtmlEncode(token.Title) + "\""; } if (!string.IsNullOrEmpty(pathQueryOption?.HighlightLines)) { result = result + " highlight-lines=\"" + StringHelper.HtmlEncode(pathQueryOption.HighlightLines) + "\""; } result += ">"; return(result); }
public DfmFencesToken(IMarkdownRule rule, IMarkdownContext context, string name, string path, SourceInfo sourceInfo, string lang, string title, IDfmFencesBlockPathQueryOption pathQueryOption, string queryStringAndFragment) : this(rule, context, name, path, sourceInfo, lang, title, queryStringAndFragment) { PathQueryOption = pathQueryOption; }
public DfmExtractCodeResult ExtractFencesCode(DfmFencesToken token, string[] fencesCode, IDfmFencesBlockPathQueryOption pathQueryOption) { if (token == null) { throw new ArgumentNullException(nameof(token)); } if (fencesCode == null) { throw new ArgumentNullException(nameof(fencesCode)); } using (new LoggerPhaseScope("Extract Dfm Code")) { if (pathQueryOption == null) { // Add the full file when no query option is given return(new DfmExtractCodeResult { IsSuccessful = true, CodeLines = Dedent(fencesCode), }); } string[] includedLines; try { includedLines = pathQueryOption.GetQueryLines(fencesCode, token).ToArray(); } catch (Exception e) { Logger.LogWarning( GenerateErrorMessage(token, e.Message), line: token.SourceInfo.LineNumber.ToString(), code: WarningCodes.Markdown.InvalidCodeSnippet); return(new DfmExtractCodeResult { IsSuccessful = false, ErrorMessage = e.Message, CodeLines = fencesCode }); } return(new DfmExtractCodeResult { IsSuccessful = true, ErrorMessage = pathQueryOption.ErrorMessage, CodeLines = includedLines, }); } }
public static string GenerateErrorMessage(DfmFencesToken token, IDfmFencesBlockPathQueryOption option) { return(GenerateErrorMessage(token, option.ErrorMessage)); }