private static StringBuffer GenerateReferenceNotFoundErrorMessage(IMarkdownRenderer renderer, DfmFencesBlockToken token) { string errorMessage = $"Can not find reference {token.Path}"; Logger.LogError(errorMessage); return(DfmRendererHelper.GetRenderedFencesBlockString(token, renderer.Options, errorMessage)); }
public virtual StringBuffer Render(IMarkdownRenderer renderer, DfmFencesBlockToken token, MarkdownBlockContext context) { if (!PathUtility.IsRelativePath(token.Path)) { string errorMessage = $"Code absolute path: {token.Path} is not supported in file {context.GetFilePathStack().Peek()}"; Logger.LogError(errorMessage); return(DfmRendererHelper.GetRenderedFencesBlockString(token, renderer.Options, errorMessage)); } try { // TODO: Valid REST and REST-i script. var fencesPath = ((RelativePath)token.Path).BasedOn((RelativePath)context.GetFilePathStack().Peek()); var extractResult = _dfmCodeExtractor.ExtractFencesCode(token, fencesPath); return(DfmRendererHelper.GetRenderedFencesBlockString(token, renderer.Options, extractResult.ErrorMessage, extractResult.FencesCodeLines)); } catch (DirectoryNotFoundException) { return(GenerateReferenceNotFoundErrorMessage(renderer, token)); } catch (FileNotFoundException) { return(GenerateReferenceNotFoundErrorMessage(renderer, token)); } }
public override StringBuffer Render(IMarkdownRenderer renderer, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context) { StringBuffer content = string.Empty; var splitTokens = DfmRendererHelper.SplitBlockquoteTokens(token.Tokens); foreach (var splitToken in splitTokens) { if (splitToken.Token is DfmSectionBlockToken) { content += "<div"; content += ((DfmSectionBlockToken)splitToken.Token).Attributes; content += ">"; foreach (var item in splitToken.InnerTokens) { content += renderer.Render(item); } content += "</div>\n"; } else if (splitToken.Token is DfmNoteBlockToken) { var noteToken = (DfmNoteBlockToken)splitToken.Token; content += "<div class=\""; content += noteToken.NoteType.ToUpper(); content += "\"><h5>"; content += noteToken.NoteType.ToUpper(); content += "</h5>"; foreach (var item in splitToken.InnerTokens) { content += renderer.Render(item); } content += "</div>\n"; } else { content += "<blockquote>"; foreach (var item in splitToken.InnerTokens) { content += renderer.Render(item); } content += "</blockquote>\n"; } } return(content); }