Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public override void EndPara(UsfmParserState state, string marker)
public override void StartRow(UsfmParserState state, string marker)
{
if (CurrentTextType == ScriptureTextType.NonVerse || CurrentTextType == ScriptureTextType.None)
{
if (_curVerseRef.IsDefault)
UpdateVerseRef(state.VerseRef, marker);

StartParentElement(marker);
}
}

public override void EndRow(UsfmParserState state, string marker)
Expand Down Expand Up @@ -172,6 +177,9 @@ public override void EndCell(UsfmParserState state, string marker)

public override void StartSidebar(UsfmParserState state, string marker, string category)
{
if (_curVerseRef.IsDefault)
UpdateVerseRef(state.VerseRef, marker);

StartParentElement(marker);
}

Expand Down
49 changes: 49 additions & 0 deletions tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,55 @@ public void GetRows_OptBreak_MiddleIncludeMarkers()
});
}

[Test]
public void GetRows_Sidebar_FirstTag()
{
TextRow[] rows = GetRows(
@"\id MAT - Test
\esb
\ip My sidebar text
\esbe
\c 1
\p
\v 1 First verse
",
includeAllText: true,
includeMarkers: true
);

Assert.That(rows, Has.Length.EqualTo(3), string.Join(",", rows.Select(tr => tr.Text)));
Assert.That(rows[0].Text, Is.EqualTo("My sidebar text"));
Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/1:esb/1:ip")));
Assert.That(rows[1].Text, Is.Empty);
Assert.That(rows[1].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/2:p")));
Assert.That(rows[2].Text, Is.EqualTo("First verse"));
Assert.That(rows[2].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1")));
}

[Test]
public void GetRows_TableRow_FirstTag()
{
TextRow[] rows = GetRows(
@"\id MAT - Test
\tr \th1 Day \th2 Tribe \th3 Leader
\tr \tcr1 1st \tc2 Judah \tc3 Nahshon son of Amminadab
\c 1
\p
\v 1 First verse
",
includeAllText: true,
includeMarkers: true
);

Assert.That(rows, Has.Length.EqualTo(8), string.Join(",", rows.Select(tr => tr.Text)));
Assert.That(rows[0].Text, Is.EqualTo("\\th1 Day"));
Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/1:tr/1:th1")));
Assert.That(rows[6].Text, Is.Empty);
Assert.That(rows[6].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:0/3:p")));
Assert.That(rows[7].Text, Is.EqualTo("First verse"));
Assert.That(rows[7].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1")));
}

[Test]
public void GetRows_VersePara_BeginningNonVerseSegment()
{
Expand Down
Loading