Skip to content

Commit

Permalink
Paratext: Fix importing verse start inside tables
Browse files Browse the repository at this point in the history
When a verse start happened inside the table, the text up to the next
cell separator went into the new verse, but the rest of the table back
into the old verse. This was caused by an incorrectly reset
`outsideCellVisitor` reference.
  • Loading branch information
schierlm committed Oct 23, 2024
1 parent 65b82e8 commit 18b899b
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public void visitChapterStart(ChapterIdentifier location) throws RuntimeExceptio
}
ctx.currentVisitor = null;
ctx.currentVisitorExtraCSS = null;
ctx.outsideCellVisitor = null;
ctx.insideTableHead = false;
ctx.currentVerse = null;
ctx.currentParagraph = ParatextImportContext.CurrentParagraph.NONE;
ctx.currentParagraphExtraCSS = null;
Expand All @@ -199,6 +201,7 @@ public void visitParagraphStart(ParagraphKind kind) throws RuntimeException {
ctx.currentVisitor.visitCSSFormatting("-bmc-usfm-tag: " + kind.getTag()).visitText("\uFEFF");
}
ctx.outsideCellVisitor = null;
ctx.insideTableHead = false;
ExtendedLineBreakKind elbk = kind.getLineBreakKind();
if (ctx.currentParagraph != ParatextImportContext.CurrentParagraph.NONE) {
if (ctx.currentParagraph == ParatextImportContext.CurrentParagraph.PROLOG ||
Expand Down Expand Up @@ -309,7 +312,8 @@ public void visitTableCellStart(String tag) throws RuntimeException {
}
ctx.currentVisitor.visitLineBreak(lbk, indent);
ctx.outsideCellVisitor = ctx.currentVisitor;
if (tag.startsWith("th")) {
ctx.insideTableHead = tag.startsWith("th");
if (ctx.insideTableHead) {
ctx.currentVisitor = ctx.currentVisitor.visitFormattingInstruction(FormattingInstructionKind.BOLD);
}
}
Expand Down Expand Up @@ -372,6 +376,12 @@ public void visitVerseStart(VerseIdentifier location, String verseNumber) {
ctx.currentChapter.getVerses().add(ctx.currentVerse);
ctx.currentVisitor = ctx.currentVerse.getAppendVisitor();
ctx.flushHeadlines();
if (ctx.outsideCellVisitor != null) {
ctx.outsideCellVisitor = ctx.currentVisitor;
if (ctx.insideTableHead) {
ctx.currentVisitor = ctx.currentVisitor.visitFormattingInstruction(FormattingInstructionKind.BOLD);
}
}
ctx.currentVisitorExtraCSS = ctx.currentParagraphExtraCSS;
if (ctx.currentParagraphExtraCSS != null) {
ctx.currentVisitor = ctx.currentVisitor.visitCSSFormatting(ctx.currentParagraphExtraCSS);
Expand Down Expand Up @@ -627,6 +637,7 @@ private static class ParatextImportContext {
private Verse currentVerse = null;
private List<Headline> headlines = new ArrayList<>();
private Visitor<RuntimeException> currentVisitor, outsideCellVisitor;
private boolean insideTableHead = false;
private String currentVisitorExtraCSS;
private CurrentParagraph currentParagraph = CurrentParagraph.NONE;
private String currentParagraphExtraCSS;
Expand Down Expand Up @@ -679,6 +690,7 @@ private void swapFields(ParatextImportContext other) {
List<Headline> h = this.headlines; this.headlines = other.headlines; other.headlines = h;
Visitor<RuntimeException> vv = this.currentVisitor; this.currentVisitor = other.currentVisitor; other.currentVisitor = vv;
vv = this.outsideCellVisitor; this.outsideCellVisitor = other.outsideCellVisitor; other.outsideCellVisitor = vv;
boolean f = this.insideTableHead; this.insideTableHead = other.insideTableHead; other.insideTableHead = f;
String s = this.currentVisitorExtraCSS; this.currentVisitorExtraCSS = other.currentVisitorExtraCSS; other.currentVisitorExtraCSS = s;
CurrentParagraph p = this.currentParagraph; this.currentParagraph = other.currentParagraph; other.currentParagraph =p;
s = this.currentParagraphExtraCSS; this.currentParagraphExtraCSS = other.currentParagraphExtraCSS; other.currentParagraphExtraCSS = s;
Expand Down

0 comments on commit 18b899b

Please sign in to comment.