Skip to content

Commit

Permalink
merge from WordPress-Android@1a74364d0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Jul 9, 2014
1 parent 79b7014 commit 32e98a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ android {
minSdkVersion 14
targetSdkVersion 19
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import android.content.res.Resources;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.QuoteSpan;

import org.apache.commons.lang.StringEscapeUtils;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.CrashlyticsUtils.ExceptionType;
import org.wordpress.android.util.CrashlyticsUtils.ExtraKey;

public class HtmlUtils {
/*
Expand Down Expand Up @@ -98,7 +103,7 @@ public static String stripScript(final String text) {
int end = sb.indexOf("</script>", start);
if (end == -1)
return sb.toString();
sb.delete(start, end+9);
sb.delete(start, end + 9);
start = sb.indexOf("<script", start);
}

Expand All @@ -108,21 +113,30 @@ public static String stripScript(final String text) {
/**
* an alternative to Html.fromHtml() supporting <ul>, <ol>, <blockquote> tags and replacing Emoticons with Emojis
*/
public static SpannableStringBuilder fromHtml(String source) {
public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpImageGetter) {
SpannableStringBuilder html;
try {
html = (SpannableStringBuilder) Html.fromHtml(source, null, new WPHtmlTagHandler());
html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, new WPHtmlTagHandler());
} catch (RuntimeException runtimeException) {
// In case our tag handler fails
html = (SpannableStringBuilder) Html.fromHtml(source, null, null);
html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, null);
// Log the exception and text that produces the error
CrashlyticsUtils.setString(ExtraKey.NOTE_HTMLDATA, source);
CrashlyticsUtils.logException(runtimeException, ExceptionType.SPECIFIC, T.NOTIFS);
}
Emoticons.replaceEmoticonsWithEmoji(html);
QuoteSpan spans[] = html.getSpans(0, html.length(), QuoteSpan.class);
for (QuoteSpan span : spans) {
html.setSpan(new WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(
html.setSpan(new WPHtml.WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(
span));
html.setSpan(new ForegroundColorSpan(0xFF666666), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(
span));
html.removeSpan(span);
}
return html;
}

public static Spanned fromHtml(String source) {
return fromHtml(source, null);
}
}

0 comments on commit 32e98a9

Please sign in to comment.