Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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));

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

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