From 46c2d49243c2cd02820fbdaf74006ad34ba36b46 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 8 Mar 2021 11:43:02 -0800 Subject: [PATCH] Begin nullability enablement --- src/Markdig/Helpers/CharNormalizer.cs | 8 +-- src/Markdig/Helpers/HtmlHelper.cs | 11 +++-- src/Markdig/Helpers/LinkHelper.cs | 54 +++++++++++---------- src/Markdig/Helpers/StringLineGroup.cs | 7 ++- src/Markdig/Helpers/ThrowHelper.cs | 32 ++++++++++++ src/Markdig/Markdown.cs | 36 +++++++------- src/Markdig/MarkdownExtensions.cs | 12 +++-- src/Markdig/Polyfills/NullableAttributes.cs | 20 ++++++++ 8 files changed, 123 insertions(+), 57 deletions(-) create mode 100644 src/Markdig/Polyfills/NullableAttributes.cs diff --git a/src/Markdig/Helpers/CharNormalizer.cs b/src/Markdig/Helpers/CharNormalizer.cs index 6f63e3de..0226ae31 100644 --- a/src/Markdig/Helpers/CharNormalizer.cs +++ b/src/Markdig/Helpers/CharNormalizer.cs @@ -1,7 +1,9 @@ -// Copyright (c) Alexandre Mutel. All rights reserved. +// Copyright (c) Alexandre Mutel. All rights reserved. // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +#nullable enable + using System.Collections.Generic; namespace Markdig.Helpers @@ -18,9 +20,9 @@ namespace Markdig.Helpers /// /// The input char. /// The simple ASCII string or null if the char itself cannot be simplified - public static string ConvertToAscii(char c) + public static string? ConvertToAscii(char c) { - return CodeToAscii.TryGetValue(c, out string str) ? str : null; + return CodeToAscii.TryGetValue(c, out string? str) ? str : null; } static CharNormalizer() diff --git a/src/Markdig/Helpers/HtmlHelper.cs b/src/Markdig/Helpers/HtmlHelper.cs index 4d385ad3..07322d7d 100644 --- a/src/Markdig/Helpers/HtmlHelper.cs +++ b/src/Markdig/Helpers/HtmlHelper.cs @@ -2,6 +2,8 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +#nullable enable + using System; using System.Text; @@ -30,7 +32,8 @@ namespace Markdig.Helpers } } } - public static string EscapeUrlCharacter(char c) + + public static string? EscapeUrlCharacter(char c) { return c < 128 ? EscapeUrlsForAscii[c] : null; } @@ -431,7 +434,7 @@ namespace Markdig.Helpers /// The string data that will be changed by unescaping any punctuation or symbol characters. /// if set to true [remove back slash]. /// - public static string Unescape(string text, bool removeBackSlash = true) + public static string Unescape(string? text, bool removeBackSlash = true) { // Credits: code from CommonMark.NET // Copyright (c) 2014, Kārlis Gaņģis All rights reserved. @@ -446,9 +449,9 @@ namespace Markdig.Helpers int lastPos = 0; char c; char[] search = removeBackSlash ? SearchBackAndAmp : SearchAmp; - StringBuilder sb = null; + StringBuilder? sb = null; - while ((searchPos = text.IndexOfAny(search, searchPos)) != -1) + while ((searchPos = text!.IndexOfAny(search, searchPos)) != -1) { sb ??= StringBuilderCache.Local(); c = text[searchPos]; diff --git a/src/Markdig/Helpers/LinkHelper.cs b/src/Markdig/Helpers/LinkHelper.cs index 50f841d0..98deb9d9 100644 --- a/src/Markdig/Helpers/LinkHelper.cs +++ b/src/Markdig/Helpers/LinkHelper.cs @@ -2,7 +2,9 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. -using System; +#nullable enable + +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; using Markdig.Syntax; @@ -14,7 +16,7 @@ namespace Markdig.Helpers /// public static class LinkHelper { - public static bool TryParseAutolink(StringSlice text, out string link, out bool isEmail) + public static bool TryParseAutolink(StringSlice text, [NotNullWhen(true)] out string? link, out bool isEmail) { return TryParseAutolink(ref text, out link, out isEmail); } @@ -118,7 +120,7 @@ namespace Markdig.Helpers return c == '_' || c == '-' || c == '.'; } - public static bool TryParseAutolink(ref StringSlice text, out string link, out bool isEmail) + public static bool TryParseAutolink(ref StringSlice text, [NotNullWhen(true)] out string? link, out bool isEmail) { link = null; isEmail = false; @@ -322,22 +324,22 @@ namespace Markdig.Helpers return false; } - public static bool TryParseInlineLink(StringSlice text, out string link, out string title) + public static bool TryParseInlineLink(StringSlice text, out string? link, out string? title) { return TryParseInlineLink(ref text, out link, out title, out _, out _); } - public static bool TryParseInlineLink(StringSlice text, out string link, out string title, out SourceSpan linkSpan, out SourceSpan titleSpan) + public static bool TryParseInlineLink(StringSlice text, out string? link, out string? title, out SourceSpan linkSpan, out SourceSpan titleSpan) { return TryParseInlineLink(ref text, out link, out title, out linkSpan, out titleSpan); } - public static bool TryParseInlineLink(ref StringSlice text, out string link, out string title) + public static bool TryParseInlineLink(ref StringSlice text, out string? link, out string? title) { return TryParseInlineLink(ref text, out link, out title, out SourceSpan linkSpan, out SourceSpan titleSpan); } - public static bool TryParseInlineLink(ref StringSlice text, out string link, out string title, out SourceSpan linkSpan, out SourceSpan titleSpan) + public static bool TryParseInlineLink(ref StringSlice text, out string? link, out string? title, out SourceSpan linkSpan, out SourceSpan titleSpan) { // 1. An inline link consists of a link text followed immediately by a left parenthesis (, // 2. optional whitespace, TODO: specs: is it whitespace or multiple whitespaces? @@ -417,9 +419,9 @@ namespace Markdig.Helpers public static bool TryParseInlineLinkTrivia( ref StringSlice text, - out string link, + out string? link, out SourceSpan unescapedLink, - out string title, + out string? title, out SourceSpan unescapedTitle, out char titleEnclosingCharacter, out SourceSpan linkSpan, @@ -521,12 +523,12 @@ namespace Markdig.Helpers return isValid; } - public static bool TryParseTitle(T text, out string title) where T : ICharIterator + public static bool TryParseTitle(T text, out string? title) where T : ICharIterator { return TryParseTitle(ref text, out title, out _); } - public static bool TryParseTitle(ref T text, out string title, out char enclosingCharacter) where T : ICharIterator + public static bool TryParseTitle(ref T text, out string? title, out char enclosingCharacter) where T : ICharIterator { bool isValid = false; var buffer = StringBuilderCache.Local(); @@ -620,7 +622,7 @@ namespace Markdig.Helpers return isValid; } - public static bool TryParseTitleTrivia(ref T text, out string title, out char enclosingCharacter) where T : ICharIterator + public static bool TryParseTitleTrivia(ref T text, out string? title, out char enclosingCharacter) where T : ICharIterator { bool isValid = false; var buffer = StringBuilderCache.Local(); @@ -714,12 +716,12 @@ namespace Markdig.Helpers return isValid; } - public static bool TryParseUrl(T text, out string link) where T : ICharIterator + public static bool TryParseUrl(T text, out string? link) where T : ICharIterator { return TryParseUrl(ref text, out link, out _); } - public static bool TryParseUrl(ref T text, out string link, out bool hasPointyBrackets, bool isAutoLink = false) where T : ICharIterator + public static bool TryParseUrl(ref T text, out string? link, out bool hasPointyBrackets, bool isAutoLink = false) where T : ICharIterator { bool isValid = false; hasPointyBrackets = false; @@ -859,7 +861,7 @@ namespace Markdig.Helpers return isValid; } - public static bool TryParseUrlTrivia(ref T text, out string link, out bool hasPointyBrackets, bool isAutoLink = false) where T : ICharIterator + public static bool TryParseUrlTrivia(ref T text, out string? link, out bool hasPointyBrackets, bool isAutoLink = false) where T : ICharIterator { bool isValid = false; hasPointyBrackets = false; @@ -1069,7 +1071,7 @@ namespace Markdig.Helpers segmentCount - lastUnderscoreSegment >= 2; // No underscores are present in the last two segments of the domain } - public static bool TryParseLinkReferenceDefinition(ref T text, out string label, out string url, out string title, out SourceSpan labelSpan, out SourceSpan urlSpan, out SourceSpan titleSpan) where T : ICharIterator + public static bool TryParseLinkReferenceDefinition(ref T text, out string? label, out string? url, out string? title, out SourceSpan labelSpan, out SourceSpan urlSpan, out SourceSpan titleSpan) where T : ICharIterator { url = null; title = null; @@ -1158,14 +1160,14 @@ namespace Markdig.Helpers public static bool TryParseLinkReferenceDefinitionTrivia( ref T text, out SourceSpan triviaBeforeLabel, - out string label, + out string? label, out SourceSpan labelWithTrivia, out SourceSpan triviaBeforeUrl, // can contain newline - out string url, + out string? url, out SourceSpan unescapedUrl, out bool urlHasPointyBrackets, out SourceSpan triviaBeforeTitle, // can contain newline - out string title, // can contain non-consecutive newlines + out string? title, // can contain non-consecutive newlines out SourceSpan unescapedTitle, out char titleEnclosingCharacter, out NewLine newLine, @@ -1303,32 +1305,32 @@ namespace Markdig.Helpers return true; } - public static bool TryParseLabel(T lines, out string label) where T : ICharIterator + public static bool TryParseLabel(T lines, out string? label) where T : ICharIterator { return TryParseLabel(ref lines, false, out label, out SourceSpan labelSpan); } - public static bool TryParseLabel(T lines, out string label, out SourceSpan labelSpan) where T : ICharIterator + public static bool TryParseLabel(T lines, out string? label, out SourceSpan labelSpan) where T : ICharIterator { return TryParseLabel(ref lines, false, out label, out labelSpan); } - public static bool TryParseLabel(ref T lines, out string label) where T : ICharIterator + public static bool TryParseLabel(ref T lines, out string? label) where T : ICharIterator { return TryParseLabel(ref lines, false, out label, out SourceSpan labelSpan); } - public static bool TryParseLabel(ref T lines, out string label, out SourceSpan labelSpan) where T : ICharIterator + public static bool TryParseLabel(ref T lines, out string? label, out SourceSpan labelSpan) where T : ICharIterator { return TryParseLabel(ref lines, false, out label, out labelSpan); } - public static bool TryParseLabelTrivia(ref T lines, out string label, out SourceSpan labelSpan) where T : ICharIterator + public static bool TryParseLabelTrivia(ref T lines, out string? label, out SourceSpan labelSpan) where T : ICharIterator { return TryParseLabelTrivia(ref lines, false, out label, out labelSpan); } - public static bool TryParseLabel(ref T lines, bool allowEmpty, out string label, out SourceSpan labelSpan) where T : ICharIterator + public static bool TryParseLabel(ref T lines, bool allowEmpty, out string? label, out SourceSpan labelSpan) where T : ICharIterator { label = null; char c = lines.CurrentChar; @@ -1443,7 +1445,7 @@ namespace Markdig.Helpers return isValid; } - public static bool TryParseLabelTrivia(ref T lines, bool allowEmpty, out string label, out SourceSpan labelSpan) where T : ICharIterator + public static bool TryParseLabelTrivia(ref T lines, bool allowEmpty, out string? label, out SourceSpan labelSpan) where T : ICharIterator { label = null; char c = lines.CurrentChar; diff --git a/src/Markdig/Helpers/StringLineGroup.cs b/src/Markdig/Helpers/StringLineGroup.cs index 940f9ed5..e47f9241 100644 --- a/src/Markdig/Helpers/StringLineGroup.cs +++ b/src/Markdig/Helpers/StringLineGroup.cs @@ -2,6 +2,8 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +#nullable enable + using System; using System.Collections; using System.Collections.Generic; @@ -30,6 +32,7 @@ namespace Markdig.Helpers Lines = _pool.Rent(capacity); Count = 0; } + internal StringLineGroup(int capacity, bool willRelease) { if (capacity <= 0) ThrowHelper.ArgumentOutOfRangeException(nameof(capacity)); @@ -116,7 +119,7 @@ namespace Markdig.Helpers /// /// The position of the `\n` line offsets from the beginning of the returned slice. /// A single slice concatenating the lines of this instance - public readonly StringSlice ToSlice(List lineOffsets = null) + public readonly StringSlice ToSlice(List? lineOffsets = null) { // Optimization case for a single line. if (Count == 1) @@ -201,7 +204,7 @@ namespace Markdig.Helpers { Array.Clear(Lines, 0, Count); _pool.Return(Lines); - Lines = null; + Lines = null!; Count = -1; } diff --git a/src/Markdig/Helpers/ThrowHelper.cs b/src/Markdig/Helpers/ThrowHelper.cs index 6fdb8241..6fab635d 100644 --- a/src/Markdig/Helpers/ThrowHelper.cs +++ b/src/Markdig/Helpers/ThrowHelper.cs @@ -15,24 +15,52 @@ namespace Markdig.Helpers [ExcludeFromCodeCoverage] internal static class ThrowHelper { + [DoesNotReturn] public static void ArgumentNullException(string paramName) => throw new ArgumentNullException(paramName); + + [DoesNotReturn] public static void ArgumentNullException_item() => throw new ArgumentNullException("item"); + + [DoesNotReturn] public static void ArgumentNullException_text() => throw new ArgumentNullException("text"); + + [DoesNotReturn] public static void ArgumentNullException_label() => throw new ArgumentNullException("label"); + + [DoesNotReturn] public static void ArgumentNullException_key() => throw new ArgumentNullException("key"); + + [DoesNotReturn] public static void ArgumentNullException_name() => throw new ArgumentNullException("name"); + + [DoesNotReturn] public static void ArgumentNullException_markdown() => throw new ArgumentNullException("markdown"); + + [DoesNotReturn] public static void ArgumentNullException_writer() => throw new ArgumentNullException("writer"); + + [DoesNotReturn] public static void ArgumentNullException_leafBlock() => throw new ArgumentNullException("leafBlock"); + + [DoesNotReturn] public static void ArgumentNullException_markdownObject() => throw new ArgumentNullException("markdownObject"); + [DoesNotReturn] public static void ArgumentException(string message) => throw new ArgumentException(message); + + [DoesNotReturn] public static void ArgumentException(string message, string paramName) => throw new ArgumentException(message, paramName); + [DoesNotReturn] public static void ArgumentOutOfRangeException(string paramName) => throw new ArgumentOutOfRangeException(paramName); + + [DoesNotReturn] public static void ArgumentOutOfRangeException(string message, string paramName) => throw new ArgumentOutOfRangeException(message, paramName); + + [DoesNotReturn] public static void ArgumentOutOfRangeException_index() => throw new ArgumentOutOfRangeException("index"); + [DoesNotReturn] public static void InvalidOperationException(string message) => throw new InvalidOperationException(message); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -57,21 +85,25 @@ namespace Markdig.Helpers static void DepthLimitExceeded() => throw new ArgumentException("Markdown elements in the input are too deeply nested - depth limit exceeded. Input is most likely not sensible or is a very large table."); } + [DoesNotReturn] public static void ThrowArgumentNullException(ExceptionArgument argument) { throw new ArgumentNullException(argument.ToString()); } + [DoesNotReturn] public static void ThrowArgumentException(ExceptionArgument argument, ExceptionReason reason) { throw new ArgumentException(argument.ToString(), GetExceptionReason(reason)); } + [DoesNotReturn] public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionReason reason) { throw new ArgumentOutOfRangeException(argument.ToString(), GetExceptionReason(reason)); } + [DoesNotReturn] public static void ThrowIndexOutOfRangeException() { throw new IndexOutOfRangeException(); diff --git a/src/Markdig/Markdown.cs b/src/Markdig/Markdown.cs index 5e64626b..34c5317f 100644 --- a/src/Markdig/Markdown.cs +++ b/src/Markdig/Markdown.cs @@ -2,6 +2,8 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +#nullable enable + using System; using System.IO; using System.Reflection; @@ -29,7 +31,7 @@ namespace Markdig /// 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, MarkdownParserContext context = 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, context); @@ -45,7 +47,7 @@ namespace Markdig /// 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, MarkdownParserContext context = null) + public static MarkdownDocument Normalize(string markdown, TextWriter writer, NormalizeOptions? options = null, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { pipeline ??= new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); @@ -69,9 +71,9 @@ namespace Markdig /// A parser context used for the parsing. /// The result of the conversion /// if markdown variable is null - public static string ToHtml(string markdown, MarkdownPipeline pipeline = null, MarkdownParserContext context = null) + public static string ToHtml(string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { - if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); + if (markdown is null) ThrowHelper.ArgumentNullException_markdown(); pipeline ??= new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); @@ -81,7 +83,7 @@ namespace Markdig renderer.Render(document); renderer.Writer.Flush(); - string html = renderer.Writer.ToString(); + string html = renderer.Writer.ToString()!; pipeline.ReleaseCacheableHtmlRenderer(renderer); return html; } @@ -95,10 +97,10 @@ namespace Markdig /// 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, MarkdownParserContext context = null) + public static MarkdownDocument ToHtml(string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { - if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); - if (writer == null) ThrowHelper.ArgumentNullException_writer(); + if (markdown is null) ThrowHelper.ArgumentNullException_markdown(); + if (writer is null) ThrowHelper.ArgumentNullException_writer(); pipeline ??= new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); @@ -121,10 +123,10 @@ namespace Markdig /// 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, MarkdownParserContext context = null) + public static object Convert(string markdown, IMarkdownRenderer renderer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { - if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); - if (renderer == null) ThrowHelper.ArgumentNullException(nameof(renderer)); + if (markdown is null) ThrowHelper.ArgumentNullException_markdown(); + if (renderer is null) ThrowHelper.ArgumentNullException(nameof(renderer)); pipeline ??= new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); @@ -141,9 +143,9 @@ namespace Markdig /// if markdown variable is null public static MarkdownDocument Parse(string markdown, bool trackTrivia = false) { - if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); + if (markdown is null) ThrowHelper.ArgumentNullException_markdown(); - MarkdownPipeline pipeline = trackTrivia ? new MarkdownPipelineBuilder() + MarkdownPipeline? pipeline = trackTrivia ? new MarkdownPipelineBuilder() .EnableTrackTrivia() .Build() : null; @@ -158,9 +160,9 @@ namespace Markdig /// A parser context used for the parsing. /// An AST Markdown document /// if markdown variable is null - public static MarkdownDocument Parse(string markdown, MarkdownPipeline pipeline, MarkdownParserContext context = null) + public static MarkdownDocument Parse(string markdown, MarkdownPipeline? pipeline, MarkdownParserContext? context = null) { - if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); + if (markdown is null) ThrowHelper.ArgumentNullException_markdown(); pipeline ??= new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); @@ -186,7 +188,7 @@ namespace Markdig /// 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, MarkdownParserContext context = null) + public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); if (writer == null) ThrowHelper.ArgumentNullException_writer(); @@ -217,7 +219,7 @@ namespace Markdig /// 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, MarkdownParserContext context = null) + public static string ToPlainText(string markdown, MarkdownPipeline? pipeline = null, MarkdownParserContext? context = null) { if (markdown == null) ThrowHelper.ArgumentNullException_markdown(); var writer = new StringWriter(); diff --git a/src/Markdig/MarkdownExtensions.cs b/src/Markdig/MarkdownExtensions.cs index 6a4e5286..3dd67a69 100644 --- a/src/Markdig/MarkdownExtensions.cs +++ b/src/Markdig/MarkdownExtensions.cs @@ -2,6 +2,8 @@ // This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +#nullable enable + using System; using Markdig.Extensions.Abbreviations; using Markdig.Extensions.AutoIdentifiers; @@ -101,7 +103,7 @@ namespace Markdig /// The pipeline. /// The options. /// The modified pipeline - public static MarkdownPipelineBuilder UseAutoLinks(this MarkdownPipelineBuilder pipeline, AutoLinkOptions options = null) + public static MarkdownPipelineBuilder UseAutoLinks(this MarkdownPipelineBuilder pipeline, AutoLinkOptions? options = null) { pipeline.Extensions.ReplaceOrAdd(new AutoLinkExtension(options)); return pipeline; @@ -136,7 +138,7 @@ namespace Markdig /// The default tag to use to match the self pipeline configuration. By default, , meaning that the HTML tag will be <--markdig:extensions--> /// The default extensions to configure if no pipeline setup was found from the Markdown document /// The modified pipeline - public static MarkdownPipelineBuilder UseSelfPipeline(this MarkdownPipelineBuilder pipeline, string defaultTag = SelfPipelineExtension.DefaultTag, string defaultExtensions = null) + public static MarkdownPipelineBuilder UseSelfPipeline(this MarkdownPipelineBuilder pipeline, string defaultTag = SelfPipelineExtension.DefaultTag, string? defaultExtensions = null) { if (pipeline.Extensions.Count != 0) { @@ -210,7 +212,7 @@ namespace Markdig /// /// The modified pipeline /// - public static MarkdownPipelineBuilder UseMediaLinks(this MarkdownPipelineBuilder pipeline, MediaOptions options = null) + public static MarkdownPipelineBuilder UseMediaLinks(this MarkdownPipelineBuilder pipeline, MediaOptions? options = null) { if (!pipeline.Extensions.Contains()) { @@ -244,7 +246,7 @@ namespace Markdig /// /// The modified pipeline /// - public static MarkdownPipelineBuilder UseSmartyPants(this MarkdownPipelineBuilder pipeline, SmartyPantOptions options = null) + public static MarkdownPipelineBuilder UseSmartyPants(this MarkdownPipelineBuilder pipeline, SmartyPantOptions? options = null) { if (!pipeline.Extensions.Contains()) { @@ -316,7 +318,7 @@ namespace Markdig /// /// The modified pipeline /// - public static MarkdownPipelineBuilder UsePipeTables(this MarkdownPipelineBuilder pipeline, PipeTableOptions options = null) + public static MarkdownPipelineBuilder UsePipeTables(this MarkdownPipelineBuilder pipeline, PipeTableOptions? options = null) { if (!pipeline.Extensions.Contains()) { diff --git a/src/Markdig/Polyfills/NullableAttributes.cs b/src/Markdig/Polyfills/NullableAttributes.cs new file mode 100644 index 00000000..17fce013 --- /dev/null +++ b/src/Markdig/Polyfills/NullableAttributes.cs @@ -0,0 +1,20 @@ +// Based on code at located at https://github.com/dotnet/runtime/blob/79ae74f5ca5c8a6fe3a48935e85bd7374959c570/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics.CodeAnalysis +{ +#if !NETCORE || NETCOREAPP2_1 + internal sealed class DoesNotReturnAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class NotNullWhenAttribute : Attribute + { + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + public bool ReturnValue { get; } + } + +#endif +}