org.jsoup.nodes.Document.OutputSettings.Syntax Java Examples
The following examples show how to use
org.jsoup.nodes.Document.OutputSettings.Syntax.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHtmlAndXmlSyntax() { String h = "<!DOCTYPE html><body><img async checked='checked' src='&<>\"'><>&"<foo />bar"; Document doc = Jsoup.parse(h); doc.outputSettings().syntax(Syntax.html); assertEquals("<!doctype html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async checked src=\"&<>"\"><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); assertEquals("<!DOCTYPE html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async=\"\" checked=\"checked\" src=\"&<>"\" /><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); }
Example #2
Source File: DocumentType.java From astor with GNU General Public License v2.0 | 6 votes |
@Override void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (out.syntax() == Syntax.html && !has(PUBLIC_ID) && !has(SYSTEM_ID)) { // looks like a html5 doctype, go lowercase for aesthetics accum.append("<!doctype"); } else { accum.append("<!DOCTYPE"); } if (has(NAME)) accum.append(" ").append(attr(NAME)); if (has(PUB_SYS_KEY)) accum.append(" ").append(attr(PUB_SYS_KEY)); if (has(PUBLIC_ID)) accum.append(" \"").append(attr(PUBLIC_ID)).append('"'); if (has(SYSTEM_ID)) accum.append(" \"").append(attr(SYSTEM_ID)).append('"'); accum.append('>'); }
Example #3
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHtmlAndXmlSyntax() { String h = "<!DOCTYPE html><body><img async checked='checked' src='&<>\"'><>&"<foo />bar"; Document doc = Jsoup.parse(h); doc.outputSettings().syntax(Syntax.html); assertEquals("<!doctype html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async checked src=\"&<>"\"><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); assertEquals("<!DOCTYPE html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async=\"\" checked=\"checked\" src=\"&<>"\" /><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); }
Example #4
Source File: DocumentType.java From astor with GNU General Public License v2.0 | 6 votes |
@Override void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (out.syntax() == Syntax.html && !has(PUBLIC_ID) && !has(SYSTEM_ID)) { // looks like a html5 doctype, go lowercase for aesthetics accum.append("<!doctype"); } else { accum.append("<!DOCTYPE"); } if (has(NAME)) accum.append(" ").append(attr(NAME)); if (has(PUB_SYS_KEY)) accum.append(" ").append(attr(PUB_SYS_KEY)); if (has(PUBLIC_ID)) accum.append(" \"").append(attr(PUBLIC_ID)).append('"'); if (has(SYSTEM_ID)) accum.append(" \"").append(attr(SYSTEM_ID)).append('"'); accum.append('>'); }
Example #5
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHtmlAndXmlSyntax() { String h = "<!DOCTYPE html><body><img async checked='checked' src='&<>\"'><>&"<foo />bar"; Document doc = Jsoup.parse(h); doc.outputSettings().syntax(Syntax.html); assertEquals("<!doctype html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async checked src=\"&<>"\"><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); assertEquals("<!DOCTYPE html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async=\"\" checked=\"checked\" src=\"&<>"\" /><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); }
Example #6
Source File: JsoupBasedFormatter.java From formatter-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, String> options, ConfigurationSource cfg) { super.initCfg(cfg); formatter = new OutputSettings(); formatter.charset(Charset.forName(options.getOrDefault("charset", StandardCharsets.UTF_8.name()))); formatter.escapeMode(EscapeMode.valueOf(options.getOrDefault("escapeMode", EscapeMode.xhtml.name()))); formatter.indentAmount(Integer.parseInt(options.getOrDefault("indentAmount", "4"))); formatter.outline(Boolean.parseBoolean(options.getOrDefault("outlineMode", Boolean.TRUE.toString()))); formatter.prettyPrint(Boolean.parseBoolean(options.getOrDefault("pretty", Boolean.TRUE.toString()))); formatter.syntax(Syntax.valueOf(options.getOrDefault("syntax", Syntax.html.name()))); }
Example #7
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 5 votes |
private Document createXmlDocument(String version, String charset, boolean addDecl) { final Document doc = new Document(""); doc.appendElement("root").text("node"); doc.outputSettings().syntax(Syntax.xml); if( addDecl == true ) { XmlDeclaration decl = new XmlDeclaration("xml", "", false); decl.attr("version", version); decl.attr("encoding", charset); doc.prependChild(decl); } return doc; }
Example #8
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 5 votes |
private Document createXmlDocument(String version, String charset, boolean addDecl) { final Document doc = new Document(""); doc.appendElement("root").text("node"); doc.outputSettings().syntax(Syntax.xml); if( addDecl == true ) { XmlDeclaration decl = new XmlDeclaration("xml", false); decl.attr("version", version); decl.attr("encoding", charset); doc.prependChild(decl); } return doc; }
Example #9
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 5 votes |
private Document createXmlDocument(String version, String charset, boolean addDecl) { final Document doc = new Document(""); doc.appendElement("root").text("node"); doc.outputSettings().syntax(Syntax.xml); if( addDecl == true ) { XmlDeclaration decl = new XmlDeclaration("xml", false); decl.attr("version", version); decl.attr("encoding", charset); doc.prependChild(decl); } return doc; }
Example #10
Source File: PrefixXmlTreeBuilder.java From CrawlerPack with Apache License 2.0 | 4 votes |
protected void initialiseParse(String input, String baseUri, ParseErrorList errors) { super.initialiseParse(input, baseUri, errors); this.stack.add(this.doc); this.doc.outputSettings().syntax(Syntax.xml); }
Example #11
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void htmlParseDefaultsToHtmlOutputSyntax() { Document doc = Jsoup.parse("x"); assertEquals(Syntax.html, doc.outputSettings().syntax()); }
Example #12
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void htmlParseDefaultsToHtmlOutputSyntax() { Document doc = Jsoup.parse("x"); assertEquals(Syntax.html, doc.outputSettings().syntax()); }
Example #13
Source File: DocumentTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void htmlParseDefaultsToHtmlOutputSyntax() { Document doc = Jsoup.parse("x"); assertEquals(Syntax.html, doc.outputSettings().syntax()); }