Skip to content

Commit

Permalink
Improve CSS handling in USFX export
Browse files Browse the repository at this point in the history
First, add a special case to convert CSS created by MyBibleZone's `<n>`
tag to \add tag.

In addition, when there is custom CSS to be exported and there is no
exactly matching USFM tag, check if the CSS includes bold and/or italic
and fall back to \bd or \it or \bdit tags.

Finally, convert red text to \wj and small caps to \sc.

When these fuzzy rules find nothing, behave as before (print a warning
and leave the content unformatted.

See #32.
  • Loading branch information
schierlm committed Apr 6, 2020
1 parent b557089 commit a9326c3
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import java.util.Comparator;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import biblemulticonverter.data.Bible;
import biblemulticonverter.data.Book;
Expand Down Expand Up @@ -670,6 +672,26 @@ public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructio
@Override
public Visitor<RuntimeException> visitCSSFormatting(String css) {
AutoClosingFormattingKind kind = ALL_FORMATTINGS_CSS.get(css);
if (kind == null && css.equals("font-style: italic; myBibleType=note")) {
kind = AutoClosingFormattingKind.ADDITION;
}
if (kind == null) {
// fuzzy search
Set<String> cleanedCSS = new HashSet<>(Arrays.asList(css.toLowerCase().replace(" ", "").split(";")));
if (cleanedCSS.contains("font-weight:bold") && cleanedCSS.contains("font-style:italic"))
kind = AutoClosingFormattingKind.BOLD_ITALIC;
else if (cleanedCSS.contains("font-weight:bold"))
kind = AutoClosingFormattingKind.BOLD;
else if (cleanedCSS.contains("font-style:italic"))
kind = AutoClosingFormattingKind.ITALIC;
else if (cleanedCSS.contains("font-variant:small-caps"))
kind = AutoClosingFormattingKind.SMALL_CAPS;
else if (cleanedCSS.contains("color:red"))
kind = AutoClosingFormattingKind.WORDS_OF_JESUS;
if (kind != null) {
System.out.println("WARNING: Replaced CSS formatting \"" + css + "\" by fuzzy match \"" + kind.getCss() + "\" (tag: \\" + kind.getTag() + ")");
}
}
if (kind == null) {
System.out.println("WARNING: No tag found for formatting: " + css);
return this;
Expand Down

0 comments on commit a9326c3

Please sign in to comment.