Skip to content

Commit

Permalink
Add horizontal line
Browse files Browse the repository at this point in the history
  • Loading branch information
xiety committed Apr 30, 2024
1 parent f22dfe4 commit c36735b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
19 changes: 12 additions & 7 deletions AnkiPoetry.Engine/BaseCreatorPerLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace AnkiPoetry.Engine;

public abstract class BaseCreatorPerLine<T> : BaseCreator<T>
{
protected abstract IEnumerable<T> CreateCard(string number, string beginning, MyLine to, int colors, bool line_numbers);
protected abstract T CreateCard(string number, string beginning, string ending, MyLine to, int colors, bool line_numbers);

protected virtual MyLine[] FilterLines(MyLine[] lines)
=> lines;

protected static string JoinLines(MyLine[] list, int colors, bool line_numbers)
{
Expand All @@ -21,17 +24,19 @@ protected static string JoinLines(MyLine[] list, int colors, bool line_numbers)

protected override IEnumerable<T> CardFromChunk(Chunk chunk, int colors, bool line_numbers)
{
for (var i = 0; i < chunk.Lines.Length - 1; ++i)
var filtered = FilterLines(chunk.Lines);

for (var i = 0; i < filtered.Length - 1; ++i)
{
var to = chunk.Lines[i + 1];
var to = filtered[i + 1];
var number = CreateNumber(chunk.MaxSongNumber, chunk.SectionNumber, chunk.SongNumber, to.LineNumber);

var beginning = CreateHeader(chunk.Header) + JoinLines(chunk.Lines[..(i + 1)], colors, line_numbers);
var beginning = CreateHeader(chunk.Header) + JoinLines(filtered[..(i + 1)], colors, line_numbers);
var ending = (i == filtered.Length - 2) ? "<hr>" : "";

var cards = CreateCard(number, beginning, to, colors, line_numbers);
var card = CreateCard(number, beginning, ending, to, colors, line_numbers);

foreach (var card in cards)
yield return card;
yield return card;
}
}
}
4 changes: 2 additions & 2 deletions AnkiPoetry.Engine/LineCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

public class LineCreator : BaseCreatorPerLine<Card>
{
protected override IEnumerable<Card> CreateCard(string number, string beginning, MyLine to, int colors, bool line_numbers)
protected override Card CreateCard(string number, string beginning, string ending, MyLine to, int colors, bool line_numbers)
{
var text = MakeCloze(AddPrefixPostfix(to.Text, to.LineType));
var cloze = AddLineNumber(to.LineNumber, text, colors, line_numbers);
yield return new(number, beginning + cloze);
return new(number, beginning + cloze + ending);
}

private static string MakeCloze(string text)
Expand Down
2 changes: 2 additions & 0 deletions AnkiPoetry.Engine/PageCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected override IEnumerable<Card> CardFromChunk(Chunk chunk, int colors, bool
even = !even;
}

sb.Append("<hr>");

yield return new(number, sb.ToString());
}

Expand Down
12 changes: 5 additions & 7 deletions AnkiPoetry.Engine/WordCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ namespace AnkiPoetry.Engine;

public partial class WordCreator : BaseCreatorPerLine<Card>
{
protected override IEnumerable<Card> CreateCard(string number, string beginning, MyLine to, int colors, bool line_numbers)
{
if (to.LineType != LineType.Norm)
yield break;
protected override MyLine[] FilterLines(MyLine[] lines)
=> lines.Where(a => a.LineType != LineType.Next).ToArray();

protected override Card CreateCard(string number, string beginning, string ending, MyLine to, int colors, bool line_numbers)
{
var cloze = GetLineText(MakeCloze(to.Text), to, colors, line_numbers);
var text = beginning + cloze;

yield return new(number, text);
return new(number, beginning + cloze + ending);
}

private static string MakeCloze(string text)
Expand Down

0 comments on commit c36735b

Please sign in to comment.