Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
87: The HtmlParser should preserve the Ideographic (CJK) Space (U+3000)
Browse files Browse the repository at this point in the history
Task-Url: #87
  • Loading branch information
leods committed May 2, 2023
1 parent 5ae90cc commit b5ab9d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ private void append(ElementState elementState, char[] ch, int start, int length)
for (int x = 0; x < length; ++x) {
int index = start + x;
char c = ch[index];
if (Character.isWhitespace(c)) {
// preserve ideographic whitespace U+3000
if (Character.isWhitespace(c) && c != '\u3000') {
if (previousWhitespaceIndex == index - 1) {
previousWhitespaceIndex = index;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,36 @@ public void blockPreformatted() {
assertParse("<pre>some\ncode</pre>", "<body><pre>some\ncode</pre></body>");
}

@Test
public void paragraphWithSpacePreserved() {
assertParse("<p>foo bar</p>", "<body><p>foo bar</p></body>");
}

@Test
public void preformattedWithSpacePreserved() {
assertParse("<pre>foo bar</pre>", "<body><pre>foo bar</pre></body>");
}

@Test
public void paragraphWithExtraSpacesCollapsed() {
assertParse("<p>foo bar</p>", "<body><p>foo bar</p></body>");
}

@Test
public void preformattedWithExtraSpacesPreserved() {
assertParse("<pre>foo bar</pre>", "<body><pre>foo bar</pre></body>");
}

@Test
public void paragraphWithIdeographicSpacePreserved() {
assertParse("<p>foo bar</p>", "<body><p>foo bar</p></body>");
}

@Test
public void preformattedWithIdeographicSpacePreserved() {
assertParse("<pre>foo bar</pre>", "<body><pre>foo bar</pre></body>");
}

private void assertParse(String expected, String content) {
StringWriter out = new StringWriter();
DocumentBuilder builder = new HtmlDocumentBuilder(out);
Expand Down

0 comments on commit b5ab9d7

Please sign in to comment.