…lines 1–84 unchanged (84 lines)
85 Node insert = comment;
86 if (commentToken.bogus) { // xml declarations are emitted as bogus comments (which is right for html, but not xml)
87 // so we do a bit of a hack and parse the data as an element to pull the attributes out
88 String data = comment.getData();
89 if (data.length() > 1 && (data.startsWith("!") || data.startsWith("?"))) {
90 Document doc = Jsoup.parse("<" + data.substring(1, data.length() -1) + ">", baseUri, Parser.xmlParser());
91 if (doc.childNodeSize() > 0) {
92 Element el = doc.child(0);
93 insert = new XmlDeclaration(settings.normalizeTag(el.tagName()), data.startsWith("!"));
94 insert.attributes().addAll(el.attributes());
95 } // else, we couldn't parse it as a decl, so leave as a comment
96 }
97 }
98 insertNode(insert);
99 }
100
101 void insert(Token.Character token) {
…lines 102–146 unchanged (45 lines)