protected static boolean shouldCollapseAttribute(final String key, final String val, final Document.OutputSettings out) { return ( out.syntax() == Document.OutputSettings.Syntax.html && (val == null || ("".equals(val) || val.equalsIgnoreCase(key)) && Attribute.isBooleanAttribute(key))); }
@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('>'); }
void outerHtmlHead(final Appendable accum, int depth, final Document.OutputSettings out) throws IOException { if (out.prettyPrint() && (tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline())) { if (accum instanceof StringBuilder) { if (((StringBuilder) accum).length() > 0) indent(accum, depth, out); } else { indent(accum, depth, out); } } accum.append('<').append(tagName()); if (attributes != null) attributes.html(accum, out); // selfclosing includes unknown tags, isEmpty defines tags that are always empty if (childNodes.isEmpty() && tag.isSelfClosing()) { if (out.syntax() == Document.OutputSettings.Syntax.html && tag.isEmpty()) accum.append('>'); else accum.append(" />"); // <img> in html, <img /> in xml } else accum.append('>'); }
document.outputSettings().prettyPrint(false).syntax(Syntax.xml).charset(StandardCharsets.UTF_16); outSettings.syntax(Syntax.xml); outSettings.outline(true); outSettings.prettyPrint(false); document.outputSettings().prettyPrint(false).syntax(OutputSettings.Syntax.xml) .charset(StandardCharsets.UTF_16);
jsoupDoc.outputSettings().prettyPrint(false).syntax(Syntax.xml).charset(StandardCharsets.UTF_16); outSettings.syntax(Syntax.xml); outSettings.outline(true); outSettings.prettyPrint(false); jsoupDoc.outputSettings().prettyPrint(false).syntax(OutputSettings.Syntax.xml).charset(StandardCharsets.UTF_16);
jsoupDoc.outputSettings().prettyPrint(false).syntax(Syntax.xml).charset(StandardCharsets.UTF_16); outSettings.syntax(Syntax.xml); outSettings.outline(true); outSettings.prettyPrint(false); jsoupDoc.outputSettings().prettyPrint(false).syntax(OutputSettings.Syntax.xml).charset(StandardCharsets.UTF_16);
doc.outputSettings() .prettyPrint(false) .syntax(Document.OutputSettings.Syntax.xml) .escapeMode(Entities.EscapeMode.xhtml) .charset(charset);
@Override public void generatePDF(OutputStream outputStream, Path template, Path renderingRoot, Map<String, Object> context) throws PdfRenderingException { ITextRenderer renderer = new ITextRenderer(); try { String html = templateRenderer.renderAsString(template, context); // Ensure we have a valid XHTML document using JSoup Document jsoupDoc = Jsoup.parse(html); jsoupDoc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); jsoupDoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml); jsoupDoc.outputSettings().charset("UTF-8"); String path = renderingRoot.toAbsolutePath().toUri().toString(); renderer.setDocumentFromString(jsoupDoc.toString(), path); renderer.layout(); renderer.createPDF(outputStream); } catch (DocumentException | TemplateRenderingException e) { throw new PdfRenderingException(e); } } }
/** * Takes an input string representing an html document and processes it with * the Css Inliner. * * @param input the html document * @return the processed html document */ public String process(String input) { Document doc = Jsoup.parse(input); // check if the user wants to inline the data Elements elements = doc.getElementsByAttributeValue(DATA_INLINE_ATTR, "true"); if (elements.isEmpty()) { return input; } extractStyles(doc); applyStyles(doc); inlineImages(doc); doc.outputSettings(doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).prettyPrint(false).escapeMode(Entities.EscapeMode.extended)); return StringEscapeUtils.unescapeHtml(doc.outerHtml()); }
private InputStream convertHTMLToPDFInputStream(InputStream paramSource) throws ConversionException { Document document; try { document = Jsoup.parse(paramSource, getConfiguredCharset(), ""); } catch (IOException e) { throw new ConversionException( "Conversion is not possible due to an IOException. Error message is " + e.getMessage(), e); } document.outputSettings().syntax(Document.OutputSettings.Syntax.xml); String xhtmlString = document.html(); ByteArrayInputStream bais = new ByteArrayInputStream(xhtmlString.getBytes()); return convertXHTMLToPDFInputStream(bais); }
@Override public String body() { final Document html = Jsoup.parse(super.body()); html.outputSettings().syntax(Document.OutputSettings.Syntax.xml); html.outputSettings().escapeMode(Entities.EscapeMode.xhtml); return html.html(); }
/** * Ensures that text will have balanced tags * * @param text xml or html based content * @return valid XML string */ private static String rewrite( String text ) { Document document = Jsoup.parseBodyFragment( text ); document.outputSettings().syntax( Document.OutputSettings.Syntax.xml ); return document.body().html(); } }
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); }
@Override public String processHtml(String source) { org.jsoup.nodes.Document document = Jsoup.parse(source); processHtmlDocument(document); document.outputSettings() .syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml) .prettyPrint(false) .escapeMode(Entities.EscapeMode.xhtml); return document.html(); }
@Override public String processHtml(String source) { org.jsoup.nodes.Document document = Jsoup.parse(source); processHtmlDocument(document); document.outputSettings() .syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml) .prettyPrint(false) .escapeMode(Entities.EscapeMode.xhtml); return document.html(); }
/** * Writes the given jsoup document to the output stream (in UTF-8) * * @param doc * the document to write * @param outputStream * the stream to write to * @throws IOException * if writing fails */ private static void write(Document doc, OutputStream outputStream) throws IOException { doc.outputSettings().indentAmount(4); doc.outputSettings().syntax(Syntax.html); doc.outputSettings().prettyPrint(true); outputStream.write(doc.html().getBytes(UTF_8)); }
OutputSettings.Syntax syntax = outputSettings().syntax();
@Override protected void initialiseParse(Reader input, String baseUri, ParseErrorList errors, ParseSettings settings) { super.initialiseParse(input, baseUri, errors, settings); stack.add(doc); // place the document onto the stack. differs from HtmlTreeBuilder (not on stack) doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); }