diff --git a/src/MfGames.Nitride.Markdown/MakeSingleLinkListItems.cs b/src/MfGames.Nitride.Markdown/MakeSingleLinkListItems.cs new file mode 100644 index 0000000..85ab750 --- /dev/null +++ b/src/MfGames.Nitride.Markdown/MakeSingleLinkListItems.cs @@ -0,0 +1,103 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +using MfGames.Gallium; +using MfGames.Nitride.Contents; +using MfGames.Nitride.Slugs; + +namespace MfGames.Nitride.Markdown; + +/// +/// An operation that turns list items that starts with a link into a single +/// link for the entire list item, even if there are additional links in the +/// list. +/// +public class MakeSingleLinkListItems : IOperation +{ + private readonly ISlugConverter slugs; + + public MakeSingleLinkListItems(ISlugConverter slugs) + { + this.slugs = slugs; + } + + /// + public IEnumerable Run(IEnumerable input) + { + return input + .SelectManyEntity( + x => x + .Select(this.MakeSingleLinkLists)); + } + + /// + /// This turns all links that start with a link into a single link while + /// removing all trailing links within the line. This is to simplify the + /// rendering of the link on page. + /// + private Entity MakeSingleLinkLists(Entity entity) + { + string content = entity.GetText()!; + + string output = Regex.Replace( + content, + @"- \[\[(?