/** * HTML escape an input string, using the default settings (UTF-8, base entities). That is, {@code <} is returned as * {@code <} * * @param string the un-escaped string to escape * @return the escaped string */ public static String escape(String string) { return escape(string, DefaultOutput); }
final void html(final Appendable accum, final Document.OutputSettings out) throws IOException { final int sz = size; for (int i = 0; i < sz; i++) { // inlined from Attribute.html() final String key = keys[i]; final String val = vals[i]; accum.append(' ').append(key); // collapse checked=null, checked="", checked=checked; write out others if (!Attribute.shouldCollapseAttribute(key, val, out)) { accum.append("=\""); Entities.escape(accum, val == null ? EmptyString : val, out, true, false, false); accum.append('"'); } } }
/** * HTML escape an input string. That is, {@code <} is returned as {@code <} * * @param string the un-escaped string to escape * @param out the output settings to use * @return the escaped string */ public static String escape(String string, Document.OutputSettings out) { if (string == null) return ""; StringBuilder accum = new StringBuilder(string.length() * 2); try { escape(accum, string, out, false, false, false); } catch (IOException e) { throw new SerializationException(e); // doesn't happen } return accum.toString(); }
protected static void html(String key, String val, Appendable accum, Document.OutputSettings out) throws IOException { accum.append(key); if (!shouldCollapseAttribute(key, val, out)) { accum.append("=\""); Entities.escape(accum, Attributes.checkNotNull(val) , out, true, false, false); accum.append('"'); } }
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (out.prettyPrint() && ((siblingIndex() == 0 && parentNode instanceof Element && ((Element) parentNode).tag().formatAsBlock() && !isBlank()) || (out.outline() && siblingNodes().size()>0 && !isBlank()) )) indent(accum, depth, out); boolean normaliseWhite = out.prettyPrint() && parent() instanceof Element && !Element.preserveWhitespace(parent()); Entities.escape(accum, coreValue(), out, false, normaliseWhite, false); }