コード例 #1
0
        public StringBuffer Mark(string markdown, IMarkdownContext context)
        {
            var result = StringBuffer.Empty;
            var parser = Parser;

            if (context != null)
            {
                parser.SwitchContext(context);
            }
            var tokens = parser.Tokenize(Preprocess(markdown));
            var internalRewriteEngine =
                new MarkdownRewriteEngine(
                    this,
                    MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, TwoPhaseBlockToken>(
                        (e, t) => t.Extract(parser)));

            tokens = internalRewriteEngine.Rewrite(tokens);
            tokens = RewriteEngine.Rewrite(tokens);
            var renderer = Renderer;

            foreach (var token in tokens)
            {
                result += renderer.Render(token);
            }
            return(result);
        }
コード例 #2
0
ファイル: MarkdownEngine.cs プロジェクト: squillace/docfx
        public StringBuffer Mark(SourceInfo sourceInfo, IMarkdownContext context)
        {
            var result = StringBuffer.Empty;
            var parser = Parser;

            if (context != null)
            {
                parser.SwitchContext(context);
            }
            var tokens = parser.Tokenize(sourceInfo.Copy(Preprocess(sourceInfo.Markdown)));
            var internalRewriteEngine =
                new MarkdownRewriteEngine(
                    this,
                    MarkdownTokenRewriterFactory.Loop(
                        MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, TwoPhaseBlockToken>(
                            (e, t) => t.Extract(parser)),
                        MaxExtractCount + 1));

            tokens = internalRewriteEngine.Rewrite(tokens);
            var idTable         = new Dictionary <string, int>();
            var idRewriteEngine = new MarkdownRewriteEngine(
                this,
                MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, MarkdownHeadingBlockToken>(
                    (e, t) => t.RewriteId(idTable)));

            tokens = idRewriteEngine.Rewrite(tokens);
            tokens = RewriteEngine.Rewrite(tokens);
            var renderer = Renderer;

            foreach (var token in tokens)
            {
                result += renderer.Render(token);
            }
            return(result);
        }
コード例 #3
0
ファイル: MarkdownEngine.cs プロジェクト: z784916/docfx-1
        public StringBuffer Mark(SourceInfo sourceInfo, IMarkdownContext context)
        {
            var result = StringBuffer.Empty;
            var parser = Parser;

            if (context != null)
            {
                parser.SwitchContext(context);
            }
            var preprocessedSourceInfo = sourceInfo.Copy(Preprocess(sourceInfo.Markdown));

            var tokens = parser.Tokenize(preprocessedSourceInfo);

            if (parser.Context is MarkdownBlockContext)
            {
                tokens = TokenHelper.CreateParagraghs(
                    parser,
                    MarkdownParagraphBlockRule.Instance,
                    tokens,
                    true,
                    preprocessedSourceInfo);
            }

            // resolve two phase token
            tokens = RewriteTokens(
                tokens,
                sourceInfo.File,
                new MarkdownRewriteEngine(
                    this,
                    MarkdownTokenRewriterFactory.Loop(
                        MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, TwoPhaseBlockToken>(
                            (e, t) => t.Extract(parser)),
                        MaxExtractCount + 1)));

            // Aggregate tokens.
            foreach (var agg in TokenAggregators)
            {
                tokens = RewriteTokens(
                    tokens,
                    sourceInfo.File,
                    new MarkdownAggregateEngine(
                        this,
                        agg));
            }

            // customized rewriter.
            tokens = RewriteTokens(
                tokens,
                sourceInfo.File,
                RewriteEngine);

            if (Options.ShouldFixId)
            {
                // fix id.
                var idTable = new Dictionary <string, int>();
                tokens = RewriteTokens(
                    tokens,
                    sourceInfo.File,
                    new MarkdownRewriteEngine(
                        this,
                        MarkdownTokenRewriterFactory.FromLambda <IMarkdownRewriteEngine, MarkdownHeadingBlockToken>(
                            (e, t) => t.RewriteId(idTable))));
            }

            if (TokenTreeValidator != null)
            {
                TokenTreeValidator.Validate(tokens);
            }

            var renderer = Renderer;

            foreach (var token in tokens)
            {
                result += renderer.Render(token);
            }
            return(result);
        }