Skip to content

Commit 701950a

Browse files
authored
Merge pull request #273 from wordpress-mobile/issue/260-span-tag-space
Issue/260 span tag space
2 parents 9069cf5 + 4ff3ae8 commit 701950a

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/source/Format.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package org.wordpress.aztec.source
22

3-
import android.support.v4.util.ArrayMap
4-
import org.apache.commons.lang.StringEscapeUtils
53
import org.jsoup.Jsoup
6-
import org.jsoup.nodes.Document
74
import java.util.regex.Pattern
8-
import org.jsoup.nodes.Entities.EscapeMode
9-
import org.jsoup.safety.Cleaner
10-
import org.jsoup.safety.Whitelist
11-
125

136

147
object Format {
158

169
// list of block elements
17-
private val block = "div|span|br|blockquote|ul|ol|li|p|h1|h2|h3|h4|h5|h6|iframe"
10+
private val block = "div|br|blockquote|ul|ol|li|p|h1|h2|h3|h4|h5|h6|iframe"
1811

1912
private val iframePlaceholder = "iframe-replacement-0x0"
2013

@@ -25,7 +18,7 @@ object Format {
2518
html = replaceAll(html, iframePlaceholder, "iframe")
2619

2720
//remove newline around all non block elements
28-
val newlineToTheLeft = replaceAll(html, "(?<!</?($block)>)\n\\s*?<((?!/?($block)).*?)>", "<$2>")
21+
val newlineToTheLeft = replaceAll(html, "(?<!</?($block)>)\n<((?!/?($block)).*?)>", "<$2>")
2922
val newlineToTheRight = replaceAll(newlineToTheLeft, "<(/?(?!$block).)>\n(?!</?($block)>)", "<$1>")
3023
var fixBrNewlines = replaceAll(newlineToTheRight, "([\t ]*)(<br>)(?!\n)", "$1$2\n$1")
3124
fixBrNewlines = replaceAll(fixBrNewlines, ">([\t ]*)(<br>)", ">\n$1$2")

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import org.wordpress.aztec.source.Format
1313

1414
@RunWith(RobolectricTestRunner::class)
1515
@Config(constants = BuildConfig::class, sdk = intArrayOf(23))
16-
class HtmlFormattingTest() : AndroidTestCase() {
16+
class HtmlFormattingTest : AndroidTestCase() {
1717

1818
private var parser = AztecParser()
1919

20-
2120
private val HTML_LINE_BREAKS = "HI<br><br><br><br><br><br>BYE"
2221

2322
private val HTML_NESTED =
@@ -31,11 +30,11 @@ class HtmlFormattingTest() : AndroidTestCase() {
3130
"<div class=\"fifth\"></div>" +
3231
"</div>" +
3332
"<span class=\"second last\"></span>" +
34-
"<span></span><div><div><div><span></span></div></div></div><div></div>" +
33+
"<div><span></span><div><div><span></span></div></div></div><div></div>" +
3534
"</div>" +
3635
"<br><br>"
3736

38-
private val HTML_MIXED =
37+
private val HTML_MIXED_WITH_NEWLINES =
3938
"\n\n<span><i>Italic</i></span>\n\n" +
4039
"<b>Bold</b><br>" +
4140
"\t<div class=\"first\">" +
@@ -52,9 +51,9 @@ class HtmlFormattingTest() : AndroidTestCase() {
5251
"</div>" +
5352
"<br>"
5453

55-
private val HTML_MIXED_NO_WS =
54+
private val HTML_MIXED_WITHOUT_NEWLINES =
5655
"<span><i>Italic</i></span>" +
57-
"<b>Bold</b><br>" +
56+
" <b>Bold</b><br>" +
5857
"<div class=\"first\">" +
5958
"<a href=\"https://github.com/wordpress-mobile/WordPress-Aztec-Android\">Link</a>" +
6059
"<div class=\"second\">" +
@@ -69,6 +68,9 @@ class HtmlFormattingTest() : AndroidTestCase() {
6968
"</div>" +
7069
"<br>"
7170

71+
private val HTML_BLOCK_WITH_NEWLINES = "\n\n<div>Division</div>\n\n"
72+
private val HTML_BLOCK_WITHOUT_NEWLINES = "<div>Division</div>"
73+
7274
/**
7375
* Initialize variables.
7476
*/
@@ -113,9 +115,23 @@ class HtmlFormattingTest() : AndroidTestCase() {
113115
@Test
114116
@Throws(Exception::class)
115117
fun formatMixedHtml() {
116-
val input = HTML_MIXED
118+
val input = HTML_MIXED_WITH_NEWLINES
119+
val span = SpannableString(parser.fromHtml(input, null, null, context))
120+
val output = Format.clearFormatting(Format.addFormatting(parser.toHtml(span)))
121+
Assert.assertEquals(HTML_MIXED_WITHOUT_NEWLINES, output)
122+
}
123+
124+
/**
125+
* Test block conversion from HTML to visual mode with newlines.
126+
*
127+
* @throws Exception
128+
*/
129+
@Test
130+
@Throws(Exception::class)
131+
fun formatNewlines() {
132+
val input = HTML_BLOCK_WITH_NEWLINES
117133
val span = SpannableString(parser.fromHtml(input, null, null, context))
118134
val output = Format.clearFormatting(Format.addFormatting(parser.toHtml(span)))
119-
Assert.assertEquals(HTML_MIXED_NO_WS, output)
135+
Assert.assertEquals(HTML_BLOCK_WITHOUT_NEWLINES, output)
120136
}
121-
}
137+
}

0 commit comments

Comments
 (0)