Example #1
0
        /// <summary>
        /// Normalizes the specified markdown to a normalized markdown text.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="writer">The destination <see cref="TextWriter"/> that will receive the result of the conversion.</param>
        /// <param name="options">The normalize options</param>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>A normalized markdown text.</returns>
        public static MarkdownDocument Normalize(string markdown, TextWriter writer, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();
            pipeline = CheckForSelfPipeline(pipeline, markdown);

            // We override the renderer with our own writer
            var renderer = new NormalizeRenderer(writer, options);

            pipeline.Setup(renderer);

            var document = Parse(markdown, pipeline, context);

            renderer.Render(document);
            writer.Flush();

            return(document);
        }
Example #2
0
        /// <summary>
        /// Normalizes the specified markdown to a normalized markdown text.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="options">The normalize options</param>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>A normalized markdown text.</returns>
        public static string Normalize(string markdown, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            var writer = new StringWriter();

            Normalize(markdown, writer, options, pipeline, context);
            return(writer.ToString());
        }
Example #3
0
        /// <summary>
        /// Converts a Markdown string to HTML.
        /// </summary>
        /// <param name="markdown">A Markdown text.</param>
        /// <param name="pipeline">The pipeline used for the conversion.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>The result of the conversion</returns>
        /// <exception cref="System.ArgumentNullException">if markdown variable is null</exception>
        public static string ToPlainText(string markdown, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            var writer = new StringWriter();

            ToPlainText(markdown, writer, pipeline, context);
            return(writer.ToString());
        }
Example #4
0
        /// <summary>
        /// Converts a Markdown string to Plain text and output to the specified writer.
        /// </summary>
        /// <param name="markdown">A Markdown text.</param>
        /// <param name="writer">The destination <see cref="TextWriter"/> that will receive the result of the conversion.</param>
        /// <param name="pipeline">The pipeline used for the conversion.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>The Markdown document that has been parsed</returns>
        /// <exception cref="System.ArgumentNullException">if reader or writer variable are null</exception>
        public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();
            pipeline = CheckForSelfPipeline(pipeline, markdown);

            // We override the renderer with our own writer
            var renderer = new HtmlRenderer(writer)
            {
                EnableHtmlForBlock  = false,
                EnableHtmlForInline = false,
                EnableHtmlEscape    = false,
            };

            pipeline.Setup(renderer);

            var document = Parse(markdown, pipeline, context);

            renderer.Render(document);
            writer.Flush();

            return(document);
        }
Example #5
0
        /// <summary>
        /// Parses the specified markdown into an AST <see cref="MarkdownDocument"/>
        /// </summary>
        /// <param name="markdown">The markdown text.</param>
        /// <param name="pipeline">The pipeline used for the parsing.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>An AST Markdown document</returns>
        /// <exception cref="System.ArgumentNullException">if markdown variable is null</exception>
        public static MarkdownDocument Parse(string markdown, MarkdownPipeline pipeline, MarkdownParserContext context = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();

            pipeline = CheckForSelfPipeline(pipeline, markdown);
            return(MarkdownParser.Parse(markdown, pipeline, context));
        }
Example #6
0
        /// <summary>
        /// Converts a Markdown string using a custom <see cref="IMarkdownRenderer"/>.
        /// </summary>
        /// <param name="markdown">A Markdown text.</param>
        /// <param name="renderer">The renderer to convert Markdown to.</param>
        /// <param name="pipeline">The pipeline used for the conversion.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <exception cref="System.ArgumentNullException">if markdown or writer variable are null</exception>
        public static object Convert(string markdown, IMarkdownRenderer renderer, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();

            pipeline = CheckForSelfPipeline(pipeline, markdown);
            var document = Parse(markdown, pipeline, context);

            pipeline.Setup(renderer);
            return(renderer.Render(document));
        }