Skip to content

Commit

Permalink
OnLineBible export fixes
Browse files Browse the repository at this point in the history
- Use UTF-8 charset
- Do not force a verse split if a verse contains a headline in the
  middle

Fixes #44.
See #42.
  • Loading branch information
schierlm committed Mar 26, 2021
1 parent 54e5e3d commit c7d695c
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package biblemulticonverter.format;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.BitSet;
import java.util.EnumMap;
import java.util.EnumSet;
Expand All @@ -15,7 +18,6 @@
import biblemulticonverter.data.Chapter;
import biblemulticonverter.data.FormattedText.ExtraAttributePriority;
import biblemulticonverter.data.FormattedText.FormattingInstructionKind;
import biblemulticonverter.data.FormattedText.Headline;
import biblemulticonverter.data.FormattedText.LineBreakKind;
import biblemulticonverter.data.FormattedText.RawHTMLMode;
import biblemulticonverter.data.FormattedText.Visitor;
Expand Down Expand Up @@ -142,7 +144,7 @@ public void doExport(Bible bible, String... exportArgs) throws Exception {
}
}

try (BufferedWriter bw = new BufferedWriter(new FileWriter(outFile))) {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8))) {
for (BookMeta bm : BOOK_META) {
String prefix = "";
if (bm.id == BookID.BOOK_Matt && includeStrongs) {
Expand All @@ -155,7 +157,7 @@ public void doExport(Bible bible, String... exportArgs) throws Exception {
int maxVerse = verseCount[i];
BitSet allowedNumbers = new BitSet(maxVerse + 1);
allowedNumbers.set(1, maxVerse + 1);
List<VirtualVerse> vvs = ch == null ? null : ch.createVirtualVerses(null);
List<VirtualVerse> vvs = ch == null ? null : ch.createVirtualVerses(false, allowedNumbers, false);
for (int vnum = 1; vnum <= verseCount[i]; vnum++) {

bw.write("$$$ " + bm.abbr + " " + (i + 1) + ":" + vnum + " ");
Expand All @@ -164,11 +166,6 @@ public void doExport(Bible bible, String... exportArgs) throws Exception {
if (vvs != null) {
for (VirtualVerse vv : vvs) {
if (vv.getNumber() == vnum) {
for (Headline h : vv.getHeadlines()) {
text.append(" {\\$");
h.accept(new OnLineBibleVisitor(text, includeStrongs));
text.append("\\$} ");
}
boolean firstVerse = true;
for (Verse v : vv.getVerses()) {
if (!firstVerse || !v.getNumber().equals("" + vv.getNumber())) {
Expand Down Expand Up @@ -227,7 +224,8 @@ public int visitElementTypes(String elementTypes) throws RuntimeException {

@Override
public Visitor<RuntimeException> visitHeadline(int depth) throws RuntimeException {
throw new RuntimeException("Headlines should have been exported before");
content.append(" {\\$");
return new OnLineBibleVisitor(content, includeStrongs, "\\$} ");
}

@Override
Expand Down

1 comment on commit c7d695c

@Michahel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine.

Please sign in to comment.