Search in sources :

Example 1 with OutputSettings

use of org.jsoup.nodes.Document.OutputSettings in project jsoup by jhy.

the class EntitiesTest method escape.

@Test
public void escape() {
    String text = "Hello &<> Å å π 新 there ¾ © »";
    String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base));
    String escapedAsciiFull = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(extended));
    String escapedAsciiXhtml = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(xhtml));
    String escapedUtfFull = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(extended));
    String escapedUtfMin = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(xhtml));
    assertEquals("Hello &amp;&lt;&gt; &Aring; &aring; &#x3c0; &#x65b0; there &frac34; &copy; &raquo;", escapedAscii);
    assertEquals("Hello &amp;&lt;&gt; &angst; &aring; &pi; &#x65b0; there &frac34; &copy; &raquo;", escapedAsciiFull);
    assertEquals("Hello &amp;&lt;&gt; &#xc5; &#xe5; &#x3c0; &#x65b0; there &#xbe; &#xa9; &#xbb;", escapedAsciiXhtml);
    assertEquals("Hello &amp;&lt;&gt; Å å π 新 there ¾ © »", escapedUtfFull);
    assertEquals("Hello &amp;&lt;&gt; Å å π 新 there ¾ © »", escapedUtfMin);
    // odd that it's defined as aring in base but angst in full
    // round trip
    assertEquals(text, Entities.unescape(escapedAscii));
    assertEquals(text, Entities.unescape(escapedAsciiFull));
    assertEquals(text, Entities.unescape(escapedAsciiXhtml));
    assertEquals(text, Entities.unescape(escapedUtfFull));
    assertEquals(text, Entities.unescape(escapedUtfMin));
}
Also used : OutputSettings(org.jsoup.nodes.Document.OutputSettings) Test(org.junit.Test)

Example 2 with OutputSettings

use of org.jsoup.nodes.Document.OutputSettings in project jsoup by jhy.

the class EntitiesTest method unescapeMultiChars.

@Test
public void unescapeMultiChars() {
    // gg is not combo, but 8811 could conflict with NestedGreaterGreater or others
    String text = "&NestedGreaterGreater; &nGg; &nGt; &nGtv; &Gt; &gg;";
    String un = "≫ ⋙̸ ≫⃒ ≫̸ ≫ ≫";
    assertEquals(un, Entities.unescape(text));
    String escaped = Entities.escape(un, new OutputSettings().charset("ascii").escapeMode(extended));
    assertEquals("&Gt; &Gg;&#x338; &Gt;&#x20d2; &Gt;&#x338; &Gt; &Gt;", escaped);
    assertEquals(un, Entities.unescape(escaped));
}
Also used : OutputSettings(org.jsoup.nodes.Document.OutputSettings) Test(org.junit.Test)

Example 3 with OutputSettings

use of org.jsoup.nodes.Document.OutputSettings in project jsoup by jhy.

the class EntitiesTest method escapeSupplementaryCharacter.

@Test
public void escapeSupplementaryCharacter() {
    String text = new String(Character.toChars(135361));
    String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base));
    assertEquals("&#x210c1;", escapedAscii);
    String escapedUtf = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(base));
    assertEquals(text, escapedUtf);
}
Also used : OutputSettings(org.jsoup.nodes.Document.OutputSettings) Test(org.junit.Test)

Example 4 with OutputSettings

use of org.jsoup.nodes.Document.OutputSettings in project jsoup by jhy.

the class EntitiesTest method escapedSupplemtary.

@Test
public void escapedSupplemtary() {
    String text = "𝕙";
    String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base));
    assertEquals("&#x1d559;", escapedAscii);
    String escapedAsciiFull = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(extended));
    assertEquals("&hopf;", escapedAsciiFull);
    String escapedUtf = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(extended));
    assertEquals(text, escapedUtf);
}
Also used : OutputSettings(org.jsoup.nodes.Document.OutputSettings) Test(org.junit.Test)

Example 5 with OutputSettings

use of org.jsoup.nodes.Document.OutputSettings in project jsoup by jhy.

the class DocumentTest method testHtmlAppendable.

@Test
public void testHtmlAppendable() {
    String htmlContent = "<html><head><title>Hello</title></head><body><p>One</p><p>Two</p></body></html>";
    Document document = Jsoup.parse(htmlContent);
    OutputSettings outputSettings = new OutputSettings();
    outputSettings.prettyPrint(false);
    document.outputSettings(outputSettings);
    assertEquals(htmlContent, document.html(new StringWriter()).toString());
}
Also used : OutputSettings(org.jsoup.nodes.Document.OutputSettings) StringWriter(java.io.StringWriter) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Aggregations

OutputSettings (org.jsoup.nodes.Document.OutputSettings)5 Test (org.junit.Test)5 StringWriter (java.io.StringWriter)1 ParseTest (org.jsoup.integration.ParseTest)1