diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-08-20 22:20:52 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-08-20 22:20:52 -0400 |
commit | 56cc15276fbeb597db6f6edebf77135e0c528b69 (patch) | |
tree | 2ff819397064965a890d2c38088d96cd209b193b | |
parent | 5bd341fd8a8c069268c60644e2498506e2d7f23d (diff) | |
parent | f8b70081822a3f85542c7b38f9d885571fecca75 (diff) | |
download | AntennaPod-56cc15276fbeb597db6f6edebf77135e0c528b69.zip |
Merge pull request #1090 from mfietz/issue/1089-shownotes-line-breaks
Display line breaks in shownotes correctly
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/playback/Timeline.java | 16 |
1 files changed, 10 insertions, 6 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 f31297b41..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,11 +83,15 @@ 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 ""; } + // 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); // apply style @@ -97,10 +102,9 @@ 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.text()); + Matcher matcherLong = TIMECODE_REGEX.matcher(element.html()); StringBuffer buffer = new StringBuffer(); while (matcherLong.find()) { String h = matcherLong.group(1); |