public string ToHtml(string markdown)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return("");
            }

            var pipeline = new MarkdownPipelineBuilder();
            MarkdownPipeline markdownPipeline = pipeline.UseAdvancedExtensions().Build();

            MarkdownObject doc    = Markdown.Parse(markdown, markdownPipeline);
            var            walker = new MarkdigImageAndLinkWalker(
                (e) =>
            {
                ImageParsed?.Invoke(e);
            },
                (e) =>
            {
                LinkParsed?.Invoke(e);
            });

            walker.WalkAndBindParseEvents(doc);

            var builder    = new StringBuilder();
            var textwriter = new StringWriter(builder);

            var renderer = new HtmlRenderer(textwriter);

            renderer.Render(doc);

            return(builder.ToString());
        }
            static MarkdownPipeline Pipeline()
            {
                var builder = new MarkdownPipelineBuilder();

                builder.UseAdvancedExtensions();
                return(builder.Build());
            }
Exemple #3
0
        private Md2Html()
        {
            var pipelineBuilder = new MarkdownPipelineBuilder();

            pipeline = pipelineBuilder
                       .UseAdvancedExtensions()
                       .Build();
        }
Exemple #4
0
        public DocsMarkdownService(MarkdownPipelineBuilder builder)
        {
            builder.UseYamlFrontMatter();
            builder.UseAdvancedExtensions();
            builder.UseBootstrap();

            _pipeline = builder.Build();
        }
        public void PrepareParser()
        {
            var builder = new MarkdownPipelineBuilder();

            if (EnableExtensions)
            {
                builder.UseAdvancedExtensions();
            }

            _parser = builder.Build();
        }
Exemple #6
0
        public DocsMarkdownService(DocsMarkdownRenderingContext section)
        {
            var builder = new MarkdownPipelineBuilder();

            builder.UseYamlFrontMatter();
            builder.Use(new DisplayLinkExtension(section));
            builder.UseAdvancedExtensions();
            builder.UseBootstrap();

            _pipeline = builder.Build();
        }
Exemple #7
0
        private MarkdownPipeline GetPipeline()
        {
            var pipeline = new MarkdownPipelineBuilder();

            if (markdigOptions.Count == 0)
            {
                pipeline.UseAdvancedExtensions();
            }
            else
            {
                // TODO: handle Markdig options
            }
            return(pipeline.Build());
        }
        private static MarkdownPipeline CreateMarkdownPipeline(bool embedImages, bool usePrism, string sourceDirectory)
        {
            var builder = new MarkdownPipelineBuilder();

            builder.UseAdvancedExtensions();
            builder.DebugLog = Console.Out;

            if (embedImages)
            {
                builder.Use(new EmbedLocalImagesExtension(sourceDirectory));
            }

            if (usePrism)
            {
                builder.UsePrism();
            }

            return(builder.Build());
        }
Exemple #9
0
        public bool Parse(ref string source)
        {
            if (_pipeline == null)
            {
                _pipeline = _pipelineBuilder.UseAdvancedExtensions().Build();
            }

            using (var writer = new StringWriter())
            {
                var renderer = new HtmlRenderer(writer);
                _pipeline.Setup(renderer);

                var doc = Markdown.Parse(source, _pipeline);

                renderer.Render(doc);

                writer.Flush();

                source = writer.ToString();
            }

            return(true);
        }