diff --git a/src/Markdig/Markdown.cs b/src/Markdig/Markdown.cs
index 9e11388c4..d09ac8011 100644
--- a/src/Markdig/Markdown.cs
+++ b/src/Markdig/Markdown.cs
@@ -29,11 +29,12 @@ public static partial class Markdown
/// The markdown.
/// The normalize options
/// The pipeline.
+ /// A parser context used for the parsing.
/// A normalized markdown text.
- public static string Normalize(string markdown, NormalizeOptions options = null, MarkdownPipeline pipeline = null)
+ public static string Normalize(string markdown, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
{
var writer = new StringWriter();
- Normalize(markdown, writer, options, pipeline);
+ Normalize(markdown, writer, options, pipeline, context);
return writer.ToString();
}
@@ -44,8 +45,9 @@ public static string Normalize(string markdown, NormalizeOptions options = null,
/// The destination that will receive the result of the conversion.
/// The normalize options
/// The pipeline.
+ /// A parser context used for the parsing.
/// A normalized markdown text.
- public static MarkdownDocument Normalize(string markdown, TextWriter writer, NormalizeOptions options = null, MarkdownPipeline pipeline = null)
+ 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);
@@ -54,7 +56,7 @@ public static MarkdownDocument Normalize(string markdown, TextWriter writer, Nor
var renderer = new NormalizeRenderer(writer, options);
pipeline.Setup(renderer);
- var document = Parse(markdown, pipeline);
+ var document = Parse(markdown, pipeline, context);
renderer.Render(document);
writer.Flush();
@@ -82,9 +84,10 @@ public static string ToHtml(string markdown, MarkdownPipeline pipeline = null)
/// A Markdown text.
/// The destination that will receive the result of the conversion.
/// The pipeline used for the conversion.
+ /// A parser context used for the parsing.
/// The Markdown document that has been parsed
/// if reader or writer variable are null
- public static MarkdownDocument ToHtml(string markdown, TextWriter writer, MarkdownPipeline pipeline = null)
+ public static MarkdownDocument ToHtml(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));
@@ -95,7 +98,7 @@ public static MarkdownDocument ToHtml(string markdown, TextWriter writer, Markdo
var renderer = new HtmlRenderer(writer);
pipeline.Setup(renderer);
- var document = Parse(markdown, pipeline);
+ var document = Parse(markdown, pipeline, context);
renderer.Render(document);
writer.Flush();
@@ -108,15 +111,16 @@ public static MarkdownDocument ToHtml(string markdown, TextWriter writer, Markdo
/// A Markdown text.
/// The renderer to convert Markdown to.
/// The pipeline used for the conversion.
+ /// A parser context used for the parsing.
/// if markdown or writer variable are null
- public static object Convert(string markdown, IMarkdownRenderer renderer, MarkdownPipeline pipeline = null)
+ 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);
+ var document = Parse(markdown, pipeline, context);
pipeline.Setup(renderer);
return renderer.Render(document);
}
@@ -138,15 +142,16 @@ public static MarkdownDocument Parse(string markdown)
///
/// The markdown text.
/// The pipeline used for the parsing.
+ /// A parser context used for the parsing.
/// An AST Markdown document
/// if markdown variable is null
- public static MarkdownDocument Parse(string markdown, MarkdownPipeline pipeline)
+ 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);
+ return MarkdownParser.Parse(markdown, pipeline, context);
}
private static MarkdownPipeline CheckForSelfPipeline(MarkdownPipeline pipeline, string markdown)
@@ -165,9 +170,10 @@ private static MarkdownPipeline CheckForSelfPipeline(MarkdownPipeline pipeline,
/// A Markdown text.
/// The destination that will receive the result of the conversion.
/// The pipeline used for the conversion.
+ /// A parser context used for the parsing.
/// The Markdown document that has been parsed
/// if reader or writer variable are null
- public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, MarkdownPipeline pipeline = null)
+ 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));
@@ -182,7 +188,7 @@ public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, M
};
pipeline.Setup(renderer);
- var document = Parse(markdown, pipeline);
+ var document = Parse(markdown, pipeline, context);
renderer.Render(document);
writer.Flush();
@@ -194,13 +200,14 @@ public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, M
///
/// A Markdown text.
/// The pipeline used for the conversion.
+ /// A parser context used for the parsing.
/// The result of the conversion
/// if markdown variable is null
- public static string ToPlainText(string markdown, MarkdownPipeline pipeline = null)
+ 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);
+ ToPlainText(markdown, writer, pipeline, context);
return writer.ToString();
}
}
diff --git a/src/Markdig/MarkdownParserContext.cs b/src/Markdig/MarkdownParserContext.cs
new file mode 100644
index 000000000..aa326ee17
--- /dev/null
+++ b/src/Markdig/MarkdownParserContext.cs
@@ -0,0 +1,23 @@
+using System.Collections.Generic;
+
+namespace Markdig
+{
+ ///
+ /// Provides a context that can be used as part of parsing Markdown documents.
+ ///
+ public sealed class MarkdownParserContext
+ {
+ ///
+ /// Gets or sets the context property collection.
+ ///
+ public Dictionary