Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Markdig/Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static MarkdownPipeline GetPipeline(MarkdownPipeline? pipeline, string m
/// <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)
public static string Normalize([StringSyntax("Markdown")] string markdown, NormalizeOptions? options = null, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
var writer = new StringWriter();
Normalize(markdown, writer, options, pipeline, context);
Expand All @@ -70,7 +70,7 @@ public static string Normalize(string markdown, NormalizeOptions? options = null
/// <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)
public static MarkdownDocument Normalize([StringSyntax("Markdown")] string markdown, TextWriter writer, NormalizeOptions? options = null, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();

Expand All @@ -95,7 +95,7 @@ public static MarkdownDocument Normalize(string markdown, TextWriter writer, Nor
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>The HTML string.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="markdown"/> is null.</exception>
public static string ToHtml(string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static string ToHtml([StringSyntax("Markdown")] string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();

Expand Down Expand Up @@ -159,7 +159,7 @@ public static void ToHtml(this MarkdownDocument document, TextWriter writer, Mar
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>The Markdown document that has been parsed</returns>
/// <exception cref="ArgumentNullException">if reader or writer variable are null</exception>
public static MarkdownDocument ToHtml(string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static MarkdownDocument ToHtml([StringSyntax("Markdown")] string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();
if (writer is null) ThrowHelper.ArgumentNullException_writer();
Expand All @@ -181,7 +181,7 @@ public static MarkdownDocument ToHtml(string markdown, TextWriter writer, Markdo
/// <param name="pipeline">The pipeline used for the conversion.</param>
/// <param name="context">A parser context used for the parsing.</param>
/// <exception cref="ArgumentNullException">if markdown or writer variable are null</exception>
public static object Convert(string markdown, IMarkdownRenderer renderer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static object Convert([StringSyntax("Markdown")] string markdown, IMarkdownRenderer renderer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();
if (renderer is null) ThrowHelper.ArgumentNullException(nameof(renderer));
Expand All @@ -201,7 +201,7 @@ public static object Convert(string markdown, IMarkdownRenderer renderer, Markdo
/// <param name="trackTrivia">Whether to parse trivia such as whitespace, extra heading characters and unescaped string values.</param>
/// <returns>An AST Markdown document</returns>
/// <exception cref="ArgumentNullException">if markdown variable is null</exception>
public static MarkdownDocument Parse(string markdown, bool trackTrivia = false)
public static MarkdownDocument Parse([StringSyntax("Markdown")] string markdown, bool trackTrivia = false)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();

Expand All @@ -218,7 +218,7 @@ public static MarkdownDocument Parse(string markdown, bool trackTrivia = false)
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>An AST Markdown document</returns>
/// <exception cref="ArgumentNullException">if markdown variable is null</exception>
public static MarkdownDocument Parse(string markdown, MarkdownPipeline? pipeline, MarkdownParserContext? context = null)
public static MarkdownDocument Parse([StringSyntax("Markdown")] string markdown, MarkdownPipeline? pipeline, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();

Expand All @@ -236,7 +236,7 @@ public static MarkdownDocument Parse(string markdown, MarkdownPipeline? pipeline
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>The Markdown document that has been parsed</returns>
/// <exception cref="ArgumentNullException">if reader or writer variable are null</exception>
public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static MarkdownDocument ToPlainText([StringSyntax("Markdown")] string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();
if (writer is null) ThrowHelper.ArgumentNullException_writer();
Expand Down Expand Up @@ -268,7 +268,7 @@ public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, M
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>The result of the conversion</returns>
/// <exception cref="ArgumentNullException">if markdown variable is null</exception>
public static string ToPlainText(string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static string ToPlainText([StringSyntax("Markdown")] string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (markdown is null) ThrowHelper.ArgumentNullException_markdown();
var writer = new StringWriter();
Expand Down
3 changes: 2 additions & 1 deletion src/Markdig/Parsers/MarkdownParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

using Markdig.Helpers;
Expand All @@ -28,7 +29,7 @@ public static class MarkdownParser
/// <param name="context">A parser context used for the parsing.</param>
/// <returns>An AST Markdown document</returns>
/// <exception cref="ArgumentNullException">if reader variable is null</exception>
public static MarkdownDocument Parse(string text, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
public static MarkdownDocument Parse([StringSyntax("Markdown")] string text, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null)
{
if (text is null) ThrowHelper.ArgumentNullException_text();

Expand Down
29 changes: 29 additions & 0 deletions src/Markdig/Polyfills/StringSyntaxAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if !NET7_0_OR_GREATER
namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
internal sealed class StringSyntaxAttribute : Attribute
{
public const string Regex = nameof(Regex);
public const string Uri = nameof(Uri);
public const string Json = nameof(Json);
public const string Xml = nameof(Xml);
public const string CompositeFormat = nameof(CompositeFormat);

public StringSyntaxAttribute(string syntax)
{
Syntax = syntax;
Arguments = Array.Empty<object?>();
}

public StringSyntaxAttribute(string syntax, params object?[] arguments)
{
Syntax = syntax;
Arguments = arguments;
}

public string Syntax { get; }

public object?[] Arguments { get; }
}
#endif
Loading