mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add StrikethroughSpan support to SpannedToHtmlConverter
PiperOrigin-RevId: 310332708
This commit is contained in:
parent
4e8ea009b8
commit
c4c826fbfe
2 changed files with 23 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ import android.text.style.AbsoluteSizeSpan;
|
||||||
import android.text.style.BackgroundColorSpan;
|
import android.text.style.BackgroundColorSpan;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.text.style.RelativeSizeSpan;
|
import android.text.style.RelativeSizeSpan;
|
||||||
|
import android.text.style.StrikethroughSpan;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
import android.text.style.TypefaceSpan;
|
import android.text.style.TypefaceSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
|
|
@ -128,7 +129,9 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String getOpeningTag(Object span, float displayDensity) {
|
private static String getOpeningTag(Object span, float displayDensity) {
|
||||||
if (span instanceof ForegroundColorSpan) {
|
if (span instanceof StrikethroughSpan) {
|
||||||
|
return "<span style='text-decoration:line-through;'>";
|
||||||
|
} else if (span instanceof ForegroundColorSpan) {
|
||||||
ForegroundColorSpan colorSpan = (ForegroundColorSpan) span;
|
ForegroundColorSpan colorSpan = (ForegroundColorSpan) span;
|
||||||
return Util.formatInvariant(
|
return Util.formatInvariant(
|
||||||
"<span style='color:%s;'>", HtmlUtils.toCssRgba(colorSpan.getForegroundColor()));
|
"<span style='color:%s;'>", HtmlUtils.toCssRgba(colorSpan.getForegroundColor()));
|
||||||
|
|
@ -186,7 +189,8 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String getClosingTag(Object span) {
|
private static String getClosingTag(Object span) {
|
||||||
if (span instanceof ForegroundColorSpan
|
if (span instanceof StrikethroughSpan
|
||||||
|
|| span instanceof ForegroundColorSpan
|
||||||
|| span instanceof BackgroundColorSpan
|
|| span instanceof BackgroundColorSpan
|
||||||
|| span instanceof HorizontalTextInVerticalContextSpan
|
|| span instanceof HorizontalTextInVerticalContextSpan
|
||||||
|| span instanceof AbsoluteSizeSpan
|
|| span instanceof AbsoluteSizeSpan
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import android.text.style.AbsoluteSizeSpan;
|
||||||
import android.text.style.BackgroundColorSpan;
|
import android.text.style.BackgroundColorSpan;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.text.style.RelativeSizeSpan;
|
import android.text.style.RelativeSizeSpan;
|
||||||
|
import android.text.style.StrikethroughSpan;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
import android.text.style.TypefaceSpan;
|
import android.text.style.TypefaceSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
|
|
@ -176,6 +177,22 @@ public class SpannedToHtmlConverterTest {
|
||||||
assertThat(html).isEqualTo("String with unstyled section");
|
assertThat(html).isEqualTo("String with unstyled section");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convert_supportsStrikethroughSpan() {
|
||||||
|
SpannableString spanned = new SpannableString("String with crossed-out section");
|
||||||
|
spanned.setSpan(
|
||||||
|
new StrikethroughSpan(),
|
||||||
|
"String with ".length(),
|
||||||
|
"String with crossed-out".length(),
|
||||||
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
|
String html = SpannedToHtmlConverter.convert(spanned, displayDensity);
|
||||||
|
|
||||||
|
assertThat(html)
|
||||||
|
.isEqualTo(
|
||||||
|
"String with <span style='text-decoration:line-through;'>crossed-out</span> section");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convert_supportsStyleSpan() {
|
public void convert_supportsStyleSpan() {
|
||||||
SpannableString spanned =
|
SpannableString spanned =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue