diff --git a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs index 9c451eac7..863e882fb 100644 --- a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs +++ b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs @@ -20,7 +20,7 @@ public class AbbreviationParser : BlockParser /// public AbbreviationParser() { - OpeningCharacters = new[] { '*' }; + OpeningCharacters = ['*']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Extensions/Emoji/EmojiMapping.cs b/src/Markdig/Extensions/Emoji/EmojiMapping.cs index f20e1517a..08de98ee3 100644 --- a/src/Markdig/Extensions/Emoji/EmojiMapping.cs +++ b/src/Markdig/Extensions/Emoji/EmojiMapping.cs @@ -1786,6 +1786,6 @@ public EmojiMapping(IDictionary shortcodeToUnicode, IDictionary< ThrowHelper.ArgumentException(string.Format("Smiley {0} is already present in the emoji mapping", smiley.Key)); } - OpeningCharacters = new List(firstChars).ToArray(); + OpeningCharacters = [.. firstChars]; } } \ No newline at end of file diff --git a/src/Markdig/Extensions/Figures/FigureBlockParser.cs b/src/Markdig/Extensions/Figures/FigureBlockParser.cs index 1ad28bed4..744969e8b 100644 --- a/src/Markdig/Extensions/Figures/FigureBlockParser.cs +++ b/src/Markdig/Extensions/Figures/FigureBlockParser.cs @@ -18,7 +18,7 @@ public class FigureBlockParser : BlockParser /// public FigureBlockParser() { - OpeningCharacters = new[] { '^' }; + OpeningCharacters = ['^']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Extensions/Footers/FooterBlockParser.cs b/src/Markdig/Extensions/Footers/FooterBlockParser.cs index 8ab204445..ab6023e2f 100644 --- a/src/Markdig/Extensions/Footers/FooterBlockParser.cs +++ b/src/Markdig/Extensions/Footers/FooterBlockParser.cs @@ -19,7 +19,7 @@ public class FooterBlockParser : BlockParser /// public FooterBlockParser() { - OpeningCharacters = new[] {'^'}; + OpeningCharacters = ['^']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs b/src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs index e719335f8..ae34e21dd 100644 --- a/src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs +++ b/src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs @@ -23,7 +23,7 @@ public class GenericAttributesParser : InlineParser /// public GenericAttributesParser() { - OpeningCharacters = new[] { '{' }; + OpeningCharacters = ['{']; } public override bool Match(InlineProcessor processor, ref StringSlice slice) @@ -136,10 +136,7 @@ public static bool TryParse(ref StringSlice slice, [NotNullWhen(true)] out HtmlA var text = slice.Text.Substring(start, end - start + 1); if (isClass) { - if (classes is null) - { - classes = new List(); - } + classes ??= new List(); classes.Add(text); } else diff --git a/src/Markdig/Extensions/Mathematics/MathInlineParser.cs b/src/Markdig/Extensions/Mathematics/MathInlineParser.cs index 13700bfb8..89f434bae 100644 --- a/src/Markdig/Extensions/Mathematics/MathInlineParser.cs +++ b/src/Markdig/Extensions/Mathematics/MathInlineParser.cs @@ -21,7 +21,7 @@ public class MathInlineParser : InlineParser /// public MathInlineParser() { - OpeningCharacters = new[] { '$' }; + OpeningCharacters = ['$']; DefaultClass = "math"; } diff --git a/src/Markdig/Extensions/NoRefLinks/NoFollowLinksExtension.cs b/src/Markdig/Extensions/NoRefLinks/NoFollowLinksExtension.cs index 9c7c1b7b2..c8e9c1084 100644 --- a/src/Markdig/Extensions/NoRefLinks/NoFollowLinksExtension.cs +++ b/src/Markdig/Extensions/NoRefLinks/NoFollowLinksExtension.cs @@ -17,7 +17,7 @@ public class NoFollowLinksExtension : IMarkdownExtension public NoFollowLinksExtension() { - _referralLinksExtension = new ReferralLinksExtension(new[] { "nofollow" }); + _referralLinksExtension = new ReferralLinksExtension(["nofollow"]); } public void Setup(MarkdownPipelineBuilder pipeline) diff --git a/src/Markdig/Extensions/Tables/GridTableParser.cs b/src/Markdig/Extensions/Tables/GridTableParser.cs index ae6048eb7..23119b9fc 100644 --- a/src/Markdig/Extensions/Tables/GridTableParser.cs +++ b/src/Markdig/Extensions/Tables/GridTableParser.cs @@ -12,7 +12,7 @@ public class GridTableParser : BlockParser { public GridTableParser() { - OpeningCharacters = new[] { '+' }; + OpeningCharacters = ['+']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Extensions/Tables/PipeTableBlockParser.cs b/src/Markdig/Extensions/Tables/PipeTableBlockParser.cs index 74b75ff91..3b7509220 100644 --- a/src/Markdig/Extensions/Tables/PipeTableBlockParser.cs +++ b/src/Markdig/Extensions/Tables/PipeTableBlockParser.cs @@ -22,7 +22,7 @@ public class PipeTableBlockParser : BlockParser /// public PipeTableBlockParser() { - OpeningCharacters = new[] {'-'}; + OpeningCharacters = ['-']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs b/src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs index a4fe4c164..33aeb1ba7 100644 --- a/src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs +++ b/src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs @@ -19,7 +19,7 @@ public class TaskListInlineParser : InlineParser /// public TaskListInlineParser() { - OpeningCharacters = new[] {'['}; + OpeningCharacters = ['[']; ListClass = "contains-task-list"; ListItemClass = "task-list-item"; } diff --git a/src/Markdig/Parsers/HeadingBlockParser.cs b/src/Markdig/Parsers/HeadingBlockParser.cs index bf00e685e..9f99e539b 100644 --- a/src/Markdig/Parsers/HeadingBlockParser.cs +++ b/src/Markdig/Parsers/HeadingBlockParser.cs @@ -20,7 +20,7 @@ public class HeadingBlockParser : BlockParser, IAttributesParseable /// public HeadingBlockParser() { - OpeningCharacters = new[] {'#'}; + OpeningCharacters = ['#']; } /// diff --git a/src/Markdig/Parsers/HtmlBlockParser.cs b/src/Markdig/Parsers/HtmlBlockParser.cs index 978441456..0afe86484 100644 --- a/src/Markdig/Parsers/HtmlBlockParser.cs +++ b/src/Markdig/Parsers/HtmlBlockParser.cs @@ -18,7 +18,7 @@ public class HtmlBlockParser : BlockParser /// public HtmlBlockParser() { - OpeningCharacters = new[] { '<' }; + OpeningCharacters = ['<']; } public override BlockState TryOpen(BlockProcessor processor) diff --git a/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs b/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs index 599aca3b3..4fc6268c4 100644 --- a/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs @@ -20,7 +20,7 @@ namespace Markdig.Parsers.Inlines; public class EmphasisInlineParser : InlineParser, IPostInlineProcessor { private CharacterMap? emphasisMap; - private readonly DelimitersObjectCache inlinesCache = new DelimitersObjectCache(); + private readonly DelimitersObjectCache inlinesCache = new(); [Obsolete("Use TryCreateEmphasisInlineDelegate instead", error: false)] public delegate EmphasisInline CreateEmphasisInlineDelegate(char emphasisChar, bool isStrong); @@ -31,11 +31,11 @@ public class EmphasisInlineParser : InlineParser, IPostInlineProcessor /// public EmphasisInlineParser() { - EmphasisDescriptors = new List() - { + EmphasisDescriptors = + [ new EmphasisDescriptor('*', 1, 2, true), new EmphasisDescriptor('_', 1, 2, false) - }; + ]; } /// @@ -65,7 +65,7 @@ public bool HasEmphasisChar(char c) /// [Obsolete("Use TryCreateEmphasisInlineList instead", error: false)] public CreateEmphasisInlineDelegate? CreateEmphasisInline { get; set; } - public readonly List TryCreateEmphasisInlineList = new List(); + public readonly List TryCreateEmphasisInlineList = []; public override void Initialize() { diff --git a/src/Markdig/Parsers/Inlines/EscapeInlineParser.cs b/src/Markdig/Parsers/Inlines/EscapeInlineParser.cs index 665bacd43..122b2c971 100644 --- a/src/Markdig/Parsers/Inlines/EscapeInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/EscapeInlineParser.cs @@ -15,7 +15,7 @@ public class EscapeInlineParser : InlineParser { public EscapeInlineParser() { - OpeningCharacters = new[] {'\\'}; + OpeningCharacters = ['\\']; } public override bool Match(InlineProcessor processor, ref StringSlice slice) diff --git a/src/Markdig/Parsers/Inlines/HtmlEntityParser.cs b/src/Markdig/Parsers/Inlines/HtmlEntityParser.cs index a52f4a358..1ea30a487 100644 --- a/src/Markdig/Parsers/Inlines/HtmlEntityParser.cs +++ b/src/Markdig/Parsers/Inlines/HtmlEntityParser.cs @@ -21,7 +21,7 @@ public class HtmlEntityParser : InlineParser /// public HtmlEntityParser() { - OpeningCharacters = new[] {'&'}; + OpeningCharacters = ['&']; } public static bool TryParse(ref StringSlice slice, [NotNullWhen(true)] out string? literal, out int match) diff --git a/src/Markdig/Parsers/Inlines/LineBreakInlineParser.cs b/src/Markdig/Parsers/Inlines/LineBreakInlineParser.cs index 6bfdd9ffe..8f6c4d437 100644 --- a/src/Markdig/Parsers/Inlines/LineBreakInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/LineBreakInlineParser.cs @@ -18,7 +18,7 @@ public class LineBreakInlineParser : InlineParser /// public LineBreakInlineParser() { - OpeningCharacters = new[] { '\n', '\r' }; + OpeningCharacters = ['\n', '\r']; } /// diff --git a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs index 211f552f8..0caa1ef46 100644 --- a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs @@ -19,7 +19,7 @@ public class LinkInlineParser : InlineParser /// public LinkInlineParser() { - OpeningCharacters = new[] {'[', ']', '!'}; + OpeningCharacters = ['[', ']', '!']; } public override bool Match(InlineProcessor processor, ref StringSlice slice) @@ -322,7 +322,7 @@ private bool TryProcessLinkOrImage(InlineProcessor inlineState, ref StringSlice if (label != null || LinkHelper.TryParseLabelTrivia(ref text, true, out label, out labelSpan)) { - SourceSpan labelWithTrivia = new SourceSpan(labelSpan.Start, labelSpan.End); + var labelWithTrivia = new SourceSpan(labelSpan.Start, labelSpan.End); if (isLabelSpanLocal) { labelSpan = inlineState.GetSourcePositionFromLocalSpan(labelSpan); diff --git a/src/Markdig/Polyfills/NullableAttributes.cs b/src/Markdig/Polyfills/NullableAttributes.cs index 81baed28e..c65100332 100644 --- a/src/Markdig/Polyfills/NullableAttributes.cs +++ b/src/Markdig/Polyfills/NullableAttributes.cs @@ -23,7 +23,7 @@ internal sealed class AllowNullAttribute : Attribute { } #if !NET5_0_OR_GREATER internal sealed class MemberNotNullAttribute : Attribute { - public MemberNotNullAttribute(string member) => Members = new[] { member }; + public MemberNotNullAttribute(string member) => Members = [member]; public MemberNotNullAttribute(params string[] members) => Members = members; diff --git a/src/Markdig/Syntax/CodeBlock.cs b/src/Markdig/Syntax/CodeBlock.cs index 2d82bd061..97dfa8ee9 100644 --- a/src/Markdig/Syntax/CodeBlock.cs +++ b/src/Markdig/Syntax/CodeBlock.cs @@ -21,7 +21,7 @@ public class CodeBlockLine } private List? _codeBlockLines; - public List CodeBlockLines => _codeBlockLines ??= new(); + public List CodeBlockLines => _codeBlockLines ??= []; /// /// Initializes a new instance of the class. diff --git a/src/Markdig/Syntax/ContainerBlock.cs b/src/Markdig/Syntax/ContainerBlock.cs index 11a9430d7..dc7edab76 100644 --- a/src/Markdig/Syntax/ContainerBlock.cs +++ b/src/Markdig/Syntax/ContainerBlock.cs @@ -27,7 +27,7 @@ public abstract class ContainerBlock : Block, IList, IReadOnlyList /// The parser used to create this block. protected ContainerBlock(BlockParser? parser) : base(parser) { - _children = Array.Empty(); + _children = []; SetTypeKind(isInline: false, isContainer: true); }