Add test for HtmlDocument.
This commit is contained in:
parent
bdae51f252
commit
2dae6b6d7b
42 changed files with 152 additions and 24 deletions
|
|
@ -23,19 +23,32 @@ import org.jsoup.nodes.Document
|
|||
open class DocumentProvider : PreviewParameterProvider<Document> {
|
||||
override val values: Sequence<Document>
|
||||
get() = sequenceOf(
|
||||
"hello",
|
||||
// TODO Find a way to make is work with real HTML data. For now there is an error with
|
||||
// jsoup: java.lang.NoSuchMethodError: 'java.lang.String org.jsoup.nodes.Element.normalName()'
|
||||
/*
|
||||
"<html>\n" +
|
||||
" <head></head>\n" +
|
||||
" <body>\n" +
|
||||
" <p><strong>Bold</strong></p>\n" +
|
||||
" </body>\n" +
|
||||
"</html>",
|
||||
"<html><head></head><body><b>Bold</b></body></html>",
|
||||
"<h1>Heading 1</h1>",
|
||||
"<h2>Heading 2</h2>",
|
||||
*/
|
||||
"text",
|
||||
"<strong>Strong</strong>",
|
||||
"<b>Bold</b>",
|
||||
"<i>Italic</i>",
|
||||
// FIXME This does not work
|
||||
"<b><i>Bold then italic</i></b>",
|
||||
// FIXME This does not work
|
||||
"<i><b>Italic then bold</b></i>",
|
||||
"<em>em</em>",
|
||||
"<unknown>unknown</unknown>",
|
||||
// FIXME `br` is not rendered correctly in the Preview.
|
||||
"Line 1<br/>Line 2",
|
||||
"<code>code</code>",
|
||||
"<del>del</del>",
|
||||
"<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><h6>Heading 6</h6><h7>Heading 7</h7>",
|
||||
"<a href=\"https://matrix.org\">link</a>",
|
||||
"<p>paragraph</p>",
|
||||
"<p>paragraph 1</p><p>paragraph 2</p>",
|
||||
"<ol><li>ol item 1</li><li>ol item 2</li></ol>",
|
||||
"<ol><li><i>ol item 1 italic</i></li><li><b>ol item 2 bold</b></li></ol>",
|
||||
"<ul><li>ul item 1</li><li>ul item 2</li></ul>",
|
||||
"<blockquote>blockquote</blockquote>",
|
||||
// TODO Find a way to make is work with `pre`. For now there is an error with
|
||||
// jsoup: java.lang.NoSuchMethodError: 'org.jsoup.nodes.Element org.jsoup.nodes.Element.firstElementChild()'
|
||||
// "<pre>pre</pre>",
|
||||
"<mx-reply><blockquote><a href=\\\"https://matrix.to/#/!roomId/\$eventId?via=matrix.org\\\">In reply to</a> " +
|
||||
"<a href=\\\"https://matrix.to/#/@alice:matrix.org\\\">@alice:matrix.org</a><br>original message</blockquote></mx-reply>reply",
|
||||
).map { Jsoup.parse(it) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ private fun HtmlBody(
|
|||
}
|
||||
|
||||
private fun Element.isInline(): Boolean {
|
||||
return when (normalName()) {
|
||||
return when (tagName().lowercase()) {
|
||||
"del" -> true
|
||||
"mx-reply" -> false
|
||||
else -> !isBlock
|
||||
|
|
@ -163,7 +163,7 @@ private fun HtmlBlock(
|
|||
) {
|
||||
val blockModifier = modifier
|
||||
.padding(top = 4.dp)
|
||||
when (element.normalName()) {
|
||||
when (element.tagName().lowercase()) {
|
||||
"p" -> HtmlParagraph(
|
||||
paragraph = element,
|
||||
modifier = blockModifier,
|
||||
|
|
@ -237,7 +237,7 @@ private fun HtmlPreformatted(
|
|||
pre: Element,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val isCode = pre.firstElementChild()?.normalName() == "code"
|
||||
val isCode = pre.firstElementChild()?.tagName()?.lowercase() == "code"
|
||||
val backgroundColor =
|
||||
if (isCode) MaterialTheme.colorScheme.codeBackground() else Color.Unspecified
|
||||
Box(
|
||||
|
|
@ -313,7 +313,7 @@ private fun HtmlHeading(
|
|||
onTextClicked: () -> Unit = {},
|
||||
onTextLongClicked: () -> Unit = {},
|
||||
) {
|
||||
val style = when (heading.normalName()) {
|
||||
val style = when (heading.tagName().lowercase()) {
|
||||
"h1" -> MaterialTheme.typography.headlineLarge.copy(fontSize = 30.sp)
|
||||
"h2" -> MaterialTheme.typography.headlineLarge.copy(fontSize = 26.sp)
|
||||
"h3" -> MaterialTheme.typography.headlineMedium.copy(fontSize = 22.sp)
|
||||
|
|
@ -369,7 +369,7 @@ private fun HtmlMxReply(
|
|||
}
|
||||
}
|
||||
is Element -> {
|
||||
when (blockquoteNode.normalName()) {
|
||||
when (blockquoteNode.tagName().lowercase()) {
|
||||
"br" -> {
|
||||
append('\n')
|
||||
}
|
||||
|
|
@ -491,7 +491,7 @@ private fun AnnotatedString.Builder.appendInlineChildrenElements(
|
|||
}
|
||||
|
||||
private fun AnnotatedString.Builder.appendInlineElement(element: Element, colors: ColorScheme) {
|
||||
when (element.normalName()) {
|
||||
when (element.tagName().lowercase()) {
|
||||
"br" -> {
|
||||
append('\n')
|
||||
}
|
||||
|
|
@ -510,6 +510,7 @@ private fun AnnotatedString.Builder.appendInlineElement(element: Element, colors
|
|||
appendInlineChildrenElements(element.childNodes(), colors)
|
||||
}
|
||||
}
|
||||
"i",
|
||||
"em" -> {
|
||||
withStyle(style = SpanStyle(fontStyle = FontStyle.Italic)) {
|
||||
appendInlineChildrenElements(element.childNodes(), colors)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:69d4f3e08d8b0a65f611ad2ffdccb2e7513af833e69e537e7e284aaafafd9886
|
||||
size 5632
|
||||
oid sha256:51223efd8b6dafa3eec8f8c59cdef68d9cc40998acaa1299622768a4102280c5
|
||||
size 5552
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:40535a40237d85a5ce26c07f55369651fb255fa354ef29f0b2a0d35d62febdc0
|
||||
size 6388
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:413dc7a95d136d7c4870f861083490fe374a584d5bb748fbffb52b8885ffd12d
|
||||
size 5427
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6a66e9b552fea34a9a70d23b6227ef37ec0659d8e356f2d45b117d3984e3aa72
|
||||
size 23185
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b55a38258ef2d7101b07479d5858a175df368df874b67953ade1b2c4f332ec07
|
||||
size 5189
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f41f1a7a137d38de354444e8d56df7545ced3071291ddf64ed9ced9252a1f88a
|
||||
size 7078
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6b7294a578576390cbea298adb5c83b9d538a85d9252513892cfff95e2301888
|
||||
size 10089
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:606159b0f04a74083b7a7afe4f27cf8ac1f7ec0495c518cfb9816f44e4f74da6
|
||||
size 8319
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bb0d3bfcfd75cbd75fd9270ff1dc27090e5dbac79ca8db8a46d91a4c12bc966b
|
||||
size 4457
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8a0c204812a6c211d5345f44733c0ef9d8bdb2ba5923715706045ef94145e073
|
||||
size 7877
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7e933c92da82cd01151dfe7decd1433b2e8eb59b7b74315987718d616b711dab
|
||||
size 7996
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:1bb8cb9be70a55ba59bcf36163022f6afc16507991ddab179639c9924630d30c
|
||||
size 14503
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cafce115f12e0ad1473f4a61fdfd22d12028942810be744777ee631412ebb7a8
|
||||
size 5780
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ff9964808f91801e9afb453b6601b88a10723eecab273de0c365834e3c7f839f
|
||||
size 6255
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0ec5186266c2d88b537d7408c3443266f9d6410b4b01bf60f97ab9ca8692b45b
|
||||
size 8353
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:da17e16933a86695b3bd827c283bef1da14a0e1ad0258b3c231997e4b1362e02
|
||||
size 8333
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5c871aab4f412b39ec67cb4adef24138b01d95cc3c187d79271c702232003adf
|
||||
size 5554
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:eec40cd79b0b95d4a267aa95a1366244a69f2484d42d50453173d37280b92cbd
|
||||
size 6489
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:31f0774553de4d9f20448f576b8912ef972d5cda5907da06004b017bb5d19594
|
||||
size 6678
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3de455a137fa2600f3e08fcdfb4fea2dfe26a84d76a16e89d611b6a1af3d723b
|
||||
size 5990
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2d8ae0565ccd61c915b76f8f17441fae86c36d7b2c18091285a79c8f29ff2435
|
||||
size 5500
|
||||
oid sha256:cb9eec03862e9a4ef32603342ffaabdebb270739d2e3513d2e60c47f28a14f10
|
||||
size 5484
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0308e7b12a7d04a8f29d3e738d78d85dd81dec82951aa88bc5a9155ee778958c
|
||||
size 6291
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b22800154f21ec18a7ab2fce7494e5ca9f6d6afc9bf266d58cfeff72d69f9613
|
||||
size 5292
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:289a6f7ecc3f74dbaad940e59e484e1725715482d75d978b479e5b3816435271
|
||||
size 20989
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:dd10104dbe89a00378f167c76283d08417b4599d27aabc16a73fc2be6e6b8137
|
||||
size 5155
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:00449d5edc3e8f9380119122e99597947e110b243dd8dc85e8c04019ef37639c
|
||||
size 6903
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b9206810d50ecdad90c65ee4674cbe331fc926e28f0a4b2a638e029a507d3922
|
||||
size 9606
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:723ab970db8052d11a39a84c7103597bbc311eed875ed73ee06a8b2266c4d041
|
||||
size 8054
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bb0d3bfcfd75cbd75fd9270ff1dc27090e5dbac79ca8db8a46d91a4c12bc966b
|
||||
size 4457
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c83f99853842b747339ad91832891c3f935f1ad713ba0a3e24c9d1cf37e48386
|
||||
size 7404
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:63ca8490f704a9c6a0b445a970950dcc8861005949878007b5c870e56e3eede5
|
||||
size 7702
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:90ba48aab29df450a7d4ce80cd8b695aff25e6c1e74156d8dcb8a30405889cb8
|
||||
size 13456
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a78e4a778e4c7dad5308014c02fcde06bee3c066a23a6e6fe2daab0dbb838696
|
||||
size 5624
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:47bd5b6a34ccd9eb8da4be779d472fb7ce3f4af4630133eb5f362a5ee8d5e45e
|
||||
size 6067
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:17684d7b3086456ab99b6c67472f3e795a7d467c79e39d844c9437b371574b02
|
||||
size 8140
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:271bae6f3f4a63f7531175b496ea1765d4e010812f42ebc93d6e82ff7b71a25e
|
||||
size 8082
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:fb8c57f165e10321a42b4ea685d83065fbf22158b397e6616a582d7ba263ff82
|
||||
size 5420
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0d945fb9cfe8ccfb1a54812de406755b5c80f3f9436e3f985e0642b3ff38b2ea
|
||||
size 6341
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:54d103a1b78f31147b8148a9f2535b82f69c9ec16869480a40b5776a64bb40b6
|
||||
size 6308
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f896b0bae0d388ba893886595cd0a308c0b149992d9c4ef4fe7e89311c0811c3
|
||||
size 5825
|
||||
Loading…
Add table
Add a link
Reference in a new issue