示例#1
0
        public override StringBuffer Render(IMarkdownRenderer engine, MarkdownBlockquoteBlockToken token, MarkdownBlockContext context)
        {
            StringBuffer content     = string.Empty;
            var          splitTokens = DfmRendererHelper.SplitBlockquoteTokens(token.Tokens);

            foreach (var splitToken in splitTokens)
            {
                if (splitToken.Token is DfmSectionBlockToken)
                {
                    var sectionToken = splitToken.Token as DfmSectionBlockToken;
                    content += $"<div{sectionToken.Attributes}>";
                    content += RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule);
                    content += "</div>\n";
                }
                else if (splitToken.Token is DfmNoteBlockToken)
                {
                    var noteToken = splitToken.Token as DfmNoteBlockToken;
                    content += $"<div class=\"{noteToken.NoteType}\"><h5>{noteToken.NoteType}</h5>" + RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule) + "</div>\n";
                }
                else
                {
                    content += "<blockquote>";
                    content += RenderTokens(engine, splitToken.InnerTokens.ToImmutableArray(), context, true, token.Rule);
                    content += "</blockquote>\n";
                }
            }
            return(content);
        }
示例#2
0
        public virtual StringBuffer Render(IMarkdownRenderer engine, 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, engine.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, engine.Options, extractResult.ErrorMessage, extractResult.FencesCodeLines));
            }
            catch (FileNotFoundException)
            {
                string errorMessage = $"Can not find reference {token.Path}";
                Logger.LogError(errorMessage);
                return(DfmRendererHelper.GetRenderedFencesBlockString(token, engine.Options, errorMessage));
            }
        }