summaryrefslogtreecommitdiff
path: root/core/src/main/java/de/danoeh
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2015-08-15 19:27:47 +0200
committerMartin Fietz <Martin.Fietz@gmail.com>2015-08-15 19:27:47 +0200
commitf8b70081822a3f85542c7b38f9d885571fecca75 (patch)
tree0bd322d5a695694335cb2dbd3f36842ae9a940b1 /core/src/main/java/de/danoeh
parentcf1259e0b312494dc328e45fd7074817337635dd (diff)
downloadAntennaPod-f8b70081822a3f85542c7b38f9d885571fecca75.zip
Only replace ASCII line breaks if shownotes don't already contain HTML ones
Diffstat (limited to 'core/src/main/java/de/danoeh')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
index 77cf72ba8..0de9863e7 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java
@@ -14,7 +14,6 @@ import org.jsoup.select.Elements;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.ShownotesProvider;
@@ -59,6 +58,8 @@ public class Timeline {
private static final Pattern TIMECODE_LINK_REGEX = Pattern.compile("antennapod://timecode/((\\d+))");
private static final String TIMECODE_LINK = "<a class=\"timecode\" href=\"antennapod://timecode/%d\">%s</a>";
private static final Pattern TIMECODE_REGEX = Pattern.compile("\\b(?:(?:(([0-9][0-9])):))?(([0-9][0-9])):(([0-9][0-9]))\\b");
+ private static final Pattern LINE_BREAK_REGEX = Pattern.compile("<br *\\/?>");
+
/**
* Applies an app-specific CSS stylesheet and adds timecode links (optional).
@@ -82,13 +83,14 @@ public class Timeline {
return null;
}
if (shownotes == null) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "shownotesProvider contained no shownotes. Returning empty string");
+ Log.d(TAG, "shownotesProvider contained no shownotes. Returning empty string");
return "";
}
- // ASCII line breaks to HTML line breaks
- shownotes = shownotes.replace("\n", "<br />");
+ // replace ASCII line breaks with HTML ones if shownotes don't contain HTML line breaks already
+ if(!LINE_BREAK_REGEX.matcher(shownotes).find()) {
+ shownotes = shownotes.replace("\n", "<br />");
+ }
Document document = Jsoup.parse(shownotes);
@@ -100,8 +102,7 @@ public class Timeline {
// apply timecode links
if (addTimecodes) {
Elements elementsWithTimeCodes = document.body().getElementsMatchingOwnText(TIMECODE_REGEX);
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Recognized " + elementsWithTimeCodes.size() + " timecodes");
+ Log.d(TAG, "Recognized " + elementsWithTimeCodes.size() + " timecodes");
for (Element element : elementsWithTimeCodes) {
Matcher matcherLong = TIMECODE_REGEX.matcher(element.html());
StringBuffer buffer = new StringBuffer();