Skip to content

Commit 621ec1f

Browse files
authored
Merge pull request #727 from wordpress-mobile/issue/724-prepend-text-to-figcaption
Treat div, figure, figcaption and section as block level html elements
2 parents 555df8b + 9711df9 commit 621ec1f

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ open class MainActivity : AppCompatActivity(),
113113
"</div>" +
114114
"<br>"
115115
private val GUTENBERG_CODE_BLOCK = "<!-- wp:core/image {\"id\":316} -->\n" +
116-
"<figure class=\"wp-block-image\"><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png\" alt=\"\" /></figure>\n" +
116+
"<figure class=\"wp-block-image\"><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/WordPress_blue_logo.svg/1200px-WordPress_blue_logo.svg.png\" alt=\"\" />\n" +
117+
" <figcaption>The WordPress logo!</figcaption>\n" +
118+
"</figure>\n" +
117119
"<!-- /wp:core/image -->"
118120
private val PREFORMAT =
119121
"<pre>" +

aztec/src/main/kotlin/org/wordpress/aztec/AztecTagHandler.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.wordpress.aztec.spans.AztecQuoteSpan
4141
import org.wordpress.aztec.spans.AztecStrikethroughSpan
4242
import org.wordpress.aztec.spans.AztecUnorderedListSpan
4343
import org.wordpress.aztec.spans.AztecVideoSpan
44+
import org.wordpress.aztec.spans.HiddenHtmlBlock
4445
import org.wordpress.aztec.spans.HiddenHtmlSpan
4546
import org.wordpress.aztec.spans.IAztecAttributedSpan
4647
import org.wordpress.aztec.spans.IAztecNestable
@@ -75,10 +76,14 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
7576
handleElement(output, opening, AztecStrikethroughSpan(tag, AztecAttributes(attributes)))
7677
return true
7778
}
78-
DIV, SPAN, FIGURE, FIGCAPTION, SECTION -> {
79+
SPAN -> {
7980
handleElement(output, opening, HiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel))
8081
return true
8182
}
83+
DIV, FIGURE, FIGCAPTION, SECTION -> {
84+
handleElement(output, opening, HiddenHtmlBlock(tag, AztecAttributes(attributes), nestingLevel))
85+
return true
86+
}
8287
LIST_UL -> {
8388
handleElement(output, opening, AztecUnorderedListSpan(nestingLevel, AztecAttributes(attributes)))
8489
return true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.text.Layout
4+
import org.wordpress.aztec.AztecAttributes
5+
6+
class HiddenHtmlBlock(tag: String, override var attributes: AztecAttributes = AztecAttributes(),
7+
override var nestingLevel: Int) : IAztecBlockSpan {
8+
override var endBeforeBleed: Int = -1
9+
override var startBeforeCollapse: Int = -1
10+
11+
override var align: Layout.Alignment? = null
12+
13+
override val TAG: String = tag
14+
}

aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,23 +1019,23 @@ class AztecToolbarTest {
10191019
@Test
10201020
@Throws(Exception::class)
10211021
fun hiddenElementAlignment() {
1022-
editText.fromHtml("<div>a<br><div>b<br><span>c</span><br>d</div></div>")
1022+
editText.fromHtml("<div>a<div>b<br><span>c</span><br>d</div></div>")
10231023

10241024
editText.setSelection(editText.text.indexOf("a"))
10251025
alignRightButton.performClick()
1026-
Assert.assertEquals("<div style=\"text-align:right;\">a<br><div>b<br><span>c</span><br>d</div></div>",
1026+
Assert.assertEquals("<div style=\"text-align:right;\">a<div>b<br><span>c</span><br>d</div></div>",
10271027
editText.toHtml())
10281028

10291029
editText.setSelection(editText.text.indexOf("c") + 1)
10301030
alignCenterButton.performClick()
1031-
Assert.assertEquals("<div style=\"text-align:center;\">a<br>" +
1031+
Assert.assertEquals("<div style=\"text-align:center;\">a" +
10321032
"<div style=\"text-align:center;\">b<br>" +
10331033
"<span style=\"text-align:center;\">c</span><br>d</div></div>",
10341034
editText.toHtml())
10351035

10361036
editText.setSelection(editText.text.indexOf("d"))
10371037
alignLeftButton.performClick()
1038-
Assert.assertEquals("<div style=\"text-align:left;\">a<br>" +
1038+
Assert.assertEquals("<div style=\"text-align:left;\">a" +
10391039
"<div style=\"text-align:left;\">b<br>" +
10401040
"<span style=\"text-align:center;\">c</span><br>d</div></div>",
10411041
editText.toHtml())

0 commit comments

Comments
 (0)