public static FormattedVerse FormattedVerse(int verseNumber) { var result = new FormattedVerse(); var text = new StringBuilder(); var preventSpace = false; foreach (var word in VerseWords(verseNumber)) { if (!NoPreSpace.Contains(word)) { if (!preventSpace) { text.Append(' '); } FormatWord(word, text, result); } else { FormatWord(word, text, result); } preventSpace = NoPostSpace.Contains(word); } result.Text = text.ToString(); return(result); }
private static void FormatWord(string word, StringBuilder text, FormattedVerse result) { if (word == "<") { result.Spans.Add(new FormattedVerse.Span { Type = Text.FormattedVerse.SpanType.Colophon, Begin = text.Length }); } else if (word == "[") { result.Spans.Add(new FormattedVerse.Span { Type = Text.FormattedVerse.SpanType.Italics, Begin = text.Length }); } else if (word == ">") { result.Spans.Last(x => x.Type == Text.FormattedVerse.SpanType.Colophon).End = text.Length; } else if (word == "]") { result.Spans.Last(x => x.Type == Text.FormattedVerse.SpanType.Italics).End = text.Length; } else if (word == "-") { text.Append("-\u200B"); } else if (word == "—") { text.Append("—"); } else { text.Append(word); } }