Skip to content

Commit

Permalink
Adding support of dl dd and dt
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltey committed Nov 21, 2023
1 parent 137795f commit 3045b0d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/src/main/java/org/wikipedia/richtext/CustomHtmlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.Typeface
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.text.Editable
Expand All @@ -15,6 +16,7 @@ import android.text.Spannable
import android.text.Spanned
import android.text.style.AlignmentSpan
import android.text.style.LeadingMarginSpan
import android.text.style.StyleSpan
import android.text.style.TypefaceSpan
import android.text.style.URLSpan
import android.webkit.MimeTypeMap
Expand Down Expand Up @@ -246,6 +248,24 @@ class CustomHtmlParser constructor(private val handler: TagHandler) : TagHandler
output.setSpan(AlignmentSpan.Standard(alignmentSpan), start, end, 0)
}
}
} else if ((tag == "dd" || tag == "dl") && output != null) {
if (opening) {
// TODO: maybe replace with LeadingMarginSpan
output.append("\n")
output.append(" ")
}
} else if (tag == "dt" && output != null) {
if (opening) {
output.setSpan(StyleSpan(Typeface.BOLD), output.length, output.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
} else {
val spans = output.getSpans<StyleSpan>(output.length)
if (spans.isNotEmpty()) {
val span = spans.last()
val start = output.getSpanStart(span)
output.removeSpan(span)
output.setSpan(StyleSpan(Typeface.BOLD), start, output.length, 0)
}
}
}
return false
}
Expand Down

0 comments on commit 3045b0d

Please sign in to comment.