fix: additional fixes for formatting lists for single entry
Some checks failed
deploy / deploy (push) Has been cancelled

This commit is contained in:
D. Moonfire 2024-04-20 23:13:49 -05:00
parent a08f54ca14
commit 701331772f
2 changed files with 22 additions and 4 deletions

View file

@ -39,7 +39,7 @@ public class MakeSingleLinkListItems : IOperation
string output = Regex.Replace(
content,
@"(?<item>-|\*) \[\[(?<label>[^\]]+?)\]\](?<post>[^\n]+)\n",
@"(?<item>(:?-|\*)\s+)\[\[(?<label>[^\]]+?)\]\](?<post>[^\n]+)\n",
match =>
{
string item = match.Groups["item"].ToString();
@ -48,7 +48,7 @@ public class MakeSingleLinkListItems : IOperation
string label = wiki.Split('|').Last();
string after = match.Groups["post"].ToString();
string post = this.RemoveLinks(after);
string value = $"{item} [{label}{post}]({path})\n";
string value = $"{item}[{label}{post}]({path})\n";
return value;
}
@ -56,7 +56,7 @@ public class MakeSingleLinkListItems : IOperation
output = Regex.Replace(
output,
@"(?<item>-|\*) \[(?<label>[^\]]+?)\]\((?<path>[^\)]+?)\)(?<post>[^\n]+)\n",
@"(?<item>(:?-|\*)\s+)\[(?<label>[^\]]+?)\]\((?<path>[^\)]+?)\)(?<post>[^\n]+)\n",
match =>
{
string item = match.Groups["item"].ToString();
@ -64,7 +64,7 @@ public class MakeSingleLinkListItems : IOperation
string path = match.Groups["path"].ToString();
string after = match.Groups["post"].ToString();
string post = this.RemoveLinks(after);
string value = $"{item} [{label}{post}]({path})\n";
string value = $"{item}[{label}{post}]({path})\n";
return value;
}

View file

@ -64,6 +64,24 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
Assert.Equal("* [Empty space](link)", content);
}
[Fact]
public void ExtendSingleMarkdownLinkSpaces()
{
// Prettier formats lists like this.
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("- [Empty](link) space"),
};
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty space](link)", content);
}
[Fact]
public void NoLinksNoChange()
{