Skip to content

Commit 284b848

Browse files
authored
Merge pull request #661 from wordpress-mobile/issue/660-attr-lost
Changes to <hr> tag handling
2 parents b62da83 + d8c45fe commit 284b848

File tree

9 files changed

+20
-8
lines changed

9 files changed

+20
-8
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/HistoryMixedTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HistoryMixedTests : BaseHistoryTest() {
2424
"\t<li></li>\n" +
2525
"</ol>\n" +
2626
"\n" +
27-
"<hr>\n" +
27+
"<hr />\n" +
2828
"\n" +
2929
"<ul>\n" +
3030
"\t<li>Unordered</li>\n" +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class MainActivity : AppCompatActivity(),
9191
private val UNDERLINE = "<u style=\"color:lime\">Underline</u><br>"
9292
private val STRIKETHROUGH = "<s style=\"color:#ff666666\" class=\"test\">Strikethrough</s><br>" // <s> or <strike> or <del>
9393
private val ORDERED = "<ol style=\"color:green\"><li>Ordered</li><li>should have color</li></ol>"
94-
private val LINE = "<hr>"
94+
private val LINE = "<hr />"
9595
private val UNORDERED = "<ul><li style=\"color:darkred\">Unordered</li><li>Should not have color</li></ul>"
9696
private val QUOTE = "<blockquote>Quote</blockquote>"
9797
private val LINK = "<a href=\"https://github.com/wordpress-mobile/WordPress-Aztec-Android\">Link</a><br>"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class AztecParser(val plugins: List<IAztecPlugin> = ArrayList()) {
473473
}
474474

475475
if (span is AztecHorizontalRuleSpan) {
476-
out.append("<${span.startTag}>")
476+
out.append("<${span.startTag} />")
477477
i = next
478478
}
479479

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
116116
LINE -> {
117117
if (opening) {
118118
// Add an extra newline above the line to prevent weird typing on the line above
119-
start(output, AztecHorizontalRuleSpan(context, ContextCompat.getDrawable(context, R.drawable.img_hr), nestingLevel))
119+
start(output, AztecHorizontalRuleSpan(context, ContextCompat.getDrawable(context, R.drawable.img_hr),
120+
nestingLevel, AztecAttributes(attributes)))
120121
output.append(Constants.MAGIC_CHAR)
121122
} else {
122123
end(output, AztecHorizontalRuleSpan::class.java)

aztec/src/main/kotlin/org/wordpress/aztec/formatting/LineBlockFormatter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
106106
editor.context,
107107
ContextCompat.getDrawable(editor.context, R.drawable.img_hr),
108108
nestingLevel,
109+
AztecAttributes(),
109110
editor
110111
)
111112

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHorizontalRuleSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.wordpress.aztec.AztecAttributes
66
import org.wordpress.aztec.AztecText
77

88
class AztecHorizontalRuleSpan(context: Context, drawable: Drawable, override var nestingLevel: Int,
9-
editor: AztecText? = null, override var attributes: AztecAttributes = AztecAttributes()) :
9+
override var attributes: AztecAttributes = AztecAttributes(), editor: AztecText? = null) :
1010
AztecDynamicImageSpan(context, drawable), IAztecFullWidthImageSpan, IAztecSpan {
1111
init {
1212
textView = editor

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AttributeTest {
5252
private val BIG = "<big b=\"B\">Big</big>"
5353
private val SMALL = "<small s=\"S\">Small</small>"
5454
private val P = "<p p=\"P\">Paragraph</p>"
55+
private val LINE = "<hr h=\"H\" />"
5556
private val MIXED = HEADING + BOLD + ITALIC + UNDERLINE + STRIKETHROUGH + ORDERED +
5657
UNORDERED + QUOTE + LINK + COMMENT + COMMENT_MORE + COMMENT_PAGE +
5758
UNKNOWN + LIST + SUB + SUP + FONT + TT + BIG + SMALL + P
@@ -240,6 +241,15 @@ class AttributeTest {
240241
Assert.assertEquals(input, output)
241242
}
242243

244+
@Test
245+
@Throws(Exception::class)
246+
fun rulerAttributes() {
247+
val input = LINE
248+
editText.fromHtml(input)
249+
val output = editText.toHtml()
250+
Assert.assertEquals(input, output)
251+
}
252+
243253
@Test
244254
@Throws(Exception::class)
245255
fun paragraphAttributes() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,11 @@ class AztecToolbarTest {
960960
@Throws(Exception::class)
961961
fun orderedListMultiselectAlignment() {
962962
editText.fromHtml("<ol><li>item 1</li><li style=\"text-align: center;\">item 2</li></ol>" +
963-
"<hr><ol><li>item 3</li><li>item 4</li></ol>")
963+
"<hr /><ol><li>item 3</li><li>item 4</li></ol>")
964964

965965
editText.setSelection(editText.text.indexOf("2"), editText.text.indexOf("3"))
966966
alignRightButton.performClick()
967-
Assert.assertEquals("<ol><li>item 1</li><li style=\"text-align: right;\">item 2</li></ol><hr>" +
967+
Assert.assertEquals("<ol><li>item 1</li><li style=\"text-align: right;\">item 2</li></ol><hr />" +
968968
"<ol><li style=\"text-align: right;\">item 3</li><li>item 4</li></ol>",
969969
editText.toHtml())
970970
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ClipboardTest {
2626
private val UNDERLINE = "<u>Underline</u><br>"
2727
private val STRIKETHROUGH = "<s class=\"test\">Strikethrough</s>" // <s> or <strike> or <del>
2828
private val ORDERED = "<ol><li>Ordered</li><li></li></ol>"
29-
private val LINE = "<hr>"
29+
private val LINE = "<hr />"
3030
private val UNORDERED = "<ul><li>Unordered</li><li></li></ul>"
3131
private val QUOTE = "<blockquote>Quote</blockquote>"
3232
private val LINK = "<a href=\"https://github.com/wordpress-mobile/WordPress-Aztec-Android\">Link</a><br>"

0 commit comments

Comments
 (0)