Exemplo n.º 1
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            var childBuilder = new RenderTreeBuilder();

            ChildContent(childBuilder);

            var frames = childBuilder.GetFrames().Array;
            var sb     = new StringBuilder();

            for (int n = 0; n < frames.Length; n++)
            {
                if (frames[n] is RenderTreeFrame renderFrame)
                {
                    switch (renderFrame.FrameType)
                    {
                    case RenderTreeFrameType.Text:
                        sb.Append(renderFrame.TextContent);
                        break;

                    case RenderTreeFrameType.Markup:
                        sb.Append(renderFrame.MarkupContent);
                        break;
                    }
                }
            }

            // Remove whitespaces at the beginning of each new line
            for (int n = 0, i = 0, step = Environment.NewLine.Length; n + step < sb.Length; n++, i++)
            {
                if (sb[n] != Environment.NewLine[i])
                {
                    i = 0;
                    continue;
                }

                if (i + 1 == step)
                {
                    var pos = n;
                    while (sb[pos + 1] == ' ')
                    {
                        pos++;
                    }

                    i = 0;
                    sb.Remove(n + 1, pos - n);
                }
            }

            var pipeline = new MarkdownPipelineBuilder()
                           .UseAdvancedExtensions()
                           .Configure(Extensions)
                           .Build();

            MarkdownParser.Convert(sb.ToString(), new BlazorRenderer(builder, 0), pipeline);
        }
Exemplo n.º 2
0
        public static string ToHtml(string markdown)
        {
            var markdownPipelineBuilder = new MarkdownPipelineBuilder()
                                          .DisableHtml()
                                          .UseAutoLinks();

            markdownPipelineBuilder
            .Extensions
            .AddIfNotAlready <UnescapedFencedCodeBlockExtension>();

            var pipeline = markdownPipelineBuilder.Build();

            return(MarkdownHelper.ToHtml(markdown ?? string.Empty, pipeline));
        }
Exemplo n.º 3
0
 public string Render(string source)
 {
     return(Markdown.ToHtml(source, Pipeline));
 }
Exemplo n.º 4
0
 public MarkdownDocument Parse(string text)
 {
     return(Markdigger.Parse(text, pipeline));
 }
Exemplo n.º 5
0
 public string ToPlainText(string text)
 {
     return(Markdigger.ToPlainText(text, pipeline));
 }
Exemplo n.º 6
0
 public string ToHtml(string text)
 {
     return(Markdigger.ToHtml(text, pipeline));
 }
Exemplo n.º 7
0
 public string Normalise(string text)
 {
     return(Markdigger.Normalize(text, null, pipeline));
 }