Rewrite() public method

public Rewrite ( ImmutableArray tokens ) : ImmutableArray
tokens ImmutableArray
return ImmutableArray
Ejemplo n.º 1
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.º 2
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.º 3
0
        private static ImmutableArray<IMarkdownToken> Tokenize(string markdown, string file)
        {
            var gfm = new GfmEngineBuilder(new Options()).CreateEngine(new HtmlRenderer());
            var sourceInfo = SourceInfo.Create(markdown.Replace("\r\n", "\n"), file);

            var tokens = gfm.Parser.Tokenize(sourceInfo);

            tokens = TokenHelper.CreateParagraghs(
                gfm.Parser,
                MarkdownParagraphBlockRule.Instance,
                tokens,
                true,
                sourceInfo);

            var rewriter =
                new MarkdownRewriteEngine(
                    gfm,
                    MarkdownTokenRewriterFactory.FromLambda<IMarkdownRewriteEngine, TwoPhaseBlockToken>(
                        (e, t) => t.Extract(gfm.Parser)));
            tokens = rewriter.Rewrite(tokens);
            return tokens;
        }
Ejemplo n.º 4
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;
 }