Skip to content

Commit

Permalink
Validate: allow cross references in headlines
Browse files Browse the repository at this point in the history
Most formats cope just well with these (some formats like MyBibleZone
even have extra markup). The reason why I flagged those as an error was,
that old MyBible.DE and PalmBible+ could not support them (MyBible.DE
did support them if they were in footnotes in headlines, though).

But those two formats are really irrelevant today, so module authors
should not try to work around their limitations any more.
  • Loading branch information
schierlm committed Sep 16, 2024
1 parent f3f9b0c commit fb5a8dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,15 @@ public void visitText(String text) throws RuntimeException {
sb.append(text.replace('<', '〈').replace('>', '〉'));
}

@Override
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
if (BOOK_NUMBERS.containsKey(book)) {
String endVerse = firstChapter != lastChapter ? "-" + lastChapter + ":" + lastVerse : !firstVerse.equals(lastVerse) ? "-" + lastVerse : "";
sb.append("<x>" + BOOK_NUMBERS.get(book) + " " + firstChapter + ":" + firstVerse + endVerse + "</x>");
}
return this;
}

@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
// handle this separately; we do not like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ private void validateDictionaryEntry(String dictionary, String entry) {
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID bookID, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
if (context.ordinal() >= ValidationContext.XREF.ordinal())
violation(ValidationCategory.NESTED_XREF, "");
if (context != ValidationContext.NORMAL_TEXT && context.ordinal() < ValidationContext.FOOTNOTE.ordinal())
if (context == ValidationContext.VERSE)
violation(ValidationCategory.INVALID_XREF_LOCATION, "");
visitInlineElement();
Book book = bible.getBook(bookAbbr, bookID);
Expand Down Expand Up @@ -1133,7 +1133,7 @@ public static enum ValidationCategory {
INVALID_VIRTUAL_VERSE_ORDER("Invalid order of virtual verses: "),
INVALID_HEADLINE_DEPTH_ORDER("Invalid headline depth order: "),
INVALID_SEPARATOR_LOCATION("Verse separators are only allowed in verses!"),
INVALID_XREF_LOCATION("cross references may only appear inside footnotes"),
INVALID_XREF_LOCATION("cross references may only appear inside footnotes, prologs or headlines"),
INVALID_LINE_BREAK_LOCATION("Line breaks only allowed in block context or footnotes"),

WHITESPACE_ADJACENT("Whitespace adjacent to whitespace found"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ protected void beforeVisit() throws RuntimeException {
throw new IllegalStateException();
}

@Override
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
System.out.println("WARNING: Cross references in captions are not supported (stripped)");
return this;
}

@Override
public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructionKind kind) throws RuntimeException {
System.out.println("WARNING: Formatting instructions in captions are not supported (stripped)");
Expand Down

0 comments on commit fb5a8dc

Please sign in to comment.