/** * 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); }
/** * Un-escape an HTML escaped string. That is, {@code <} is returned as {@code <}. * * @param string the HTML string to un-escape * @return the unescaped string */ public static String unescape(String string) { return unescape(string, false); }
boolean looksLegit = reader.matches(';'); boolean found = (Entities.isBaseNamedEntity(nameRef) || (Entities.isNamedEntity(nameRef) && looksLegit)); int numChars = Entities.codepointsForName(nameRef, multipointHolder); if (numChars == 1) { codeRef[0] = multipointHolder[0];
break; default: if (canEncode(coreCharset, c, encoder)) accum.append(c); else appendEncoded(accum, escapeMode, codePoint); accum.append(c); else appendEncoded(accum, escapeMode, codePoint);
/** Create a new DataNode from HTML encoded data. @param encodedData encoded data @param baseUri bass URI @return new DataNode */ public static DataNode createFromEncoded(String encodedData, String baseUri) { String data = Entities.unescape(encodedData); return new DataNode(data); } }
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('"'); } } }
/** * Create a new TextNode from HTML encoded (aka escaped) data. * @param encodedText Text containing encoded HTML (e.g. &lt;) * @param baseUri Base uri * @return TextNode containing unencoded data (e.g. <) * @deprecated use {@link TextNode#createFromEncoded(String)} instead, as LeafNodes don't carry base URIs. */ public static TextNode createFromEncoded(String encodedText, String baseUri) { String text = Entities.unescape(encodedText); return new TextNode(text); }
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('"'); } }
/** * Create a new TextNode from HTML encoded (aka escaped) data. * @param encodedText Text containing encoded HTML (e.g. &lt;) * @return TextNode containing unencoded data (e.g. <) */ public static TextNode createFromEncoded(String encodedText) { String text = Entities.unescape(encodedText); return new TextNode(text); }
/** * 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(); }
/** * Create a new Attribute from an unencoded key and a HTML attribute encoded value. * @param unencodedKey assumes the key is not encoded, as can be only run of simple \w chars. * @param encodedValue HTML attribute encoded value * @return attribute */ public static Attribute createFromEncoded(String unencodedKey, String encodedValue) { String value = Entities.unescape(encodedValue, true); return new Attribute(unencodedKey, value, null); // parent will get set when Put }
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); }