Skip to content

Commit

Permalink
Use collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon committed Dec 14, 2023
1 parent f52ecee commit 342e264
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AbbreviationParser : BlockParser
/// </summary>
public AbbreviationParser()
{
OpeningCharacters = new[] { '*' };
OpeningCharacters = ['*'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Emoji/EmojiMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,6 @@ public EmojiMapping(IDictionary<string, string> shortcodeToUnicode, IDictionary<
ThrowHelper.ArgumentException(string.Format("Smiley {0} is already present in the emoji mapping", smiley.Key));
}

OpeningCharacters = new List<char>(firstChars).ToArray();
OpeningCharacters = [.. firstChars];
}
}
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Figures/FigureBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FigureBlockParser : BlockParser
/// </summary>
public FigureBlockParser()
{
OpeningCharacters = new[] { '^' };
OpeningCharacters = ['^'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Footers/FooterBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FooterBlockParser : BlockParser
/// </summary>
public FooterBlockParser()
{
OpeningCharacters = new[] {'^'};
OpeningCharacters = ['^'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GenericAttributesParser : InlineParser
/// </summary>
public GenericAttributesParser()
{
OpeningCharacters = new[] { '{' };
OpeningCharacters = ['{'];
}

public override bool Match(InlineProcessor processor, ref StringSlice slice)
Expand Down Expand Up @@ -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<string>();
}
classes ??= new List<string>();
classes.Add(text);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Mathematics/MathInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MathInlineParser : InlineParser
/// </summary>
public MathInlineParser()
{
OpeningCharacters = new[] { '$' };
OpeningCharacters = ['$'];
DefaultClass = "math";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NoFollowLinksExtension : IMarkdownExtension

public NoFollowLinksExtension()
{
_referralLinksExtension = new ReferralLinksExtension(new[] { "nofollow" });
_referralLinksExtension = new ReferralLinksExtension(["nofollow"]);
}

public void Setup(MarkdownPipelineBuilder pipeline)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Tables/GridTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GridTableParser : BlockParser
{
public GridTableParser()
{
OpeningCharacters = new[] { '+' };
OpeningCharacters = ['+'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/Tables/PipeTableBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PipeTableBlockParser : BlockParser
/// </summary>
public PipeTableBlockParser()
{
OpeningCharacters = new[] {'-'};
OpeningCharacters = ['-'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Extensions/TaskLists/TaskListInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TaskListInlineParser : InlineParser
/// </summary>
public TaskListInlineParser()
{
OpeningCharacters = new[] {'['};
OpeningCharacters = ['['];
ListClass = "contains-task-list";
ListItemClass = "task-list-item";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/HeadingBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class HeadingBlockParser : BlockParser, IAttributesParseable
/// </summary>
public HeadingBlockParser()
{
OpeningCharacters = new[] {'#'};
OpeningCharacters = ['#'];
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/HtmlBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HtmlBlockParser : BlockParser
/// </summary>
public HtmlBlockParser()
{
OpeningCharacters = new[] { '<' };
OpeningCharacters = ['<'];
}

public override BlockState TryOpen(BlockProcessor processor)
Expand Down
10 changes: 5 additions & 5 deletions src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Markdig.Parsers.Inlines;
public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
{
private CharacterMap<EmphasisDescriptor>? 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);
Expand All @@ -31,11 +31,11 @@ public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
/// </summary>
public EmphasisInlineParser()
{
EmphasisDescriptors = new List<EmphasisDescriptor>()
{
EmphasisDescriptors =
[
new EmphasisDescriptor('*', 1, 2, true),
new EmphasisDescriptor('_', 1, 2, false)
};
];
}

/// <summary>
Expand Down Expand Up @@ -65,7 +65,7 @@ public bool HasEmphasisChar(char c)
/// </summary>
[Obsolete("Use TryCreateEmphasisInlineList instead", error: false)]
public CreateEmphasisInlineDelegate? CreateEmphasisInline { get; set; }
public readonly List<TryCreateEmphasisInlineDelegate> TryCreateEmphasisInlineList = new List<TryCreateEmphasisInlineDelegate>();
public readonly List<TryCreateEmphasisInlineDelegate> TryCreateEmphasisInlineList = [];

public override void Initialize()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/Inlines/EscapeInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EscapeInlineParser : InlineParser
{
public EscapeInlineParser()
{
OpeningCharacters = new[] {'\\'};
OpeningCharacters = ['\\'];
}

public override bool Match(InlineProcessor processor, ref StringSlice slice)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/Inlines/HtmlEntityParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class HtmlEntityParser : InlineParser
/// </summary>
public HtmlEntityParser()
{
OpeningCharacters = new[] {'&'};
OpeningCharacters = ['&'];
}

public static bool TryParse(ref StringSlice slice, [NotNullWhen(true)] out string? literal, out int match)
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/Inlines/LineBreakInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LineBreakInlineParser : InlineParser
/// </summary>
public LineBreakInlineParser()
{
OpeningCharacters = new[] { '\n', '\r' };
OpeningCharacters = ['\n', '\r'];
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Markdig/Parsers/Inlines/LinkInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LinkInlineParser : InlineParser
/// </summary>
public LinkInlineParser()
{
OpeningCharacters = new[] {'[', ']', '!'};
OpeningCharacters = ['[', ']', '!'];
}

public override bool Match(InlineProcessor processor, ref StringSlice slice)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Polyfills/NullableAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Syntax/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CodeBlockLine
}

private List<CodeBlockLine>? _codeBlockLines;
public List<CodeBlockLine> CodeBlockLines => _codeBlockLines ??= new();
public List<CodeBlockLine> CodeBlockLines => _codeBlockLines ??= [];

/// <summary>
/// Initializes a new instance of the <see cref="CodeBlock"/> class.
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Syntax/ContainerBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class ContainerBlock : Block, IList<Block>, IReadOnlyList<Block>
/// <param name="parser">The parser used to create this block.</param>
protected ContainerBlock(BlockParser? parser) : base(parser)
{
_children = Array.Empty<BlockWrapper>();
_children = [];
SetTypeKind(isInline: false, isContainer: true);
}

Expand Down

0 comments on commit 342e264

Please sign in to comment.