Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSOUP-2227] Added HTML5 tags #2228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/main/java/org/jsoup/safety/Safelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,70 @@ public Safelist(Safelist copy) {
preserveRelativeLinks = copy.preserveRelativeLinks;
}

/**
* Add HTML5 tags
*/
public Safelist addHtml5() {
// structural
// note: <summary> must be the first child of <details>
addTags("article", "aside", "details", "figcaption", "figure", "footer",
"header", "hgroup", "main", "nav", "section", "summary");
addAttributes("details", "open");

// form tags
addTags("datalist", "keygen", "output", "progress");
addAttributes("keygen", "autofocus", "challenge", "disabled",
"form", "keytype", "name");
addAttributes("output", "for", "form", "name");
addAttributes("progress", "max", "value");

// graphics tags - path? mask?
addTags("canvas", "svg");
addAttributes("canvas", "height", "width");
addAttributes("svg", "height", "viewbox", "width");

// svg elements (need to verify...)
addTags("circle", "g", "mask", "path", "rect");
addAttributes("circle", "cx", "cy", "r", "stroke", "stroke-width");
addAttributes("path", "d", "fill", "stroke", "stroke-width");
addAttributes("rect", "fill", "height", "stroke", "stroke-width", "width", "x", "y");

// media tags
addTags("audio", "embed", "source", "track", "video");
addAttributes("audio", "autoplay", "controls", "loop", "muted", "preload", "src");
addAttributes("embed", "height", "src", "type", "width");
addAttributes("source", "src", "media", "type");
addAttributes("track", "src", "default", "kind", "label", "srclang");
addAttributes("video", "autoplay", "controls", "height", "loop", "muted", "poster",
"preload", "src", "width");

addProtocols("audio", "src", "http", "https");
addProtocols("embed", "src", "http", "https");
addProtocols("source", "src", "http", "https");
addProtocols("track", "src", "http", "https");
addProtocols("video", "src", "http", "https");
addProtocols("video", "poster", "http", "https");

// text-level elements
addTags("bdi", "bdo", "mark", "meter", "time", "wbr");
addAttributes("bdo", "dir");
addAttributes("meter", "value", "form", "high", "low", "max", "min", "optimum");
addAttributes("time", "datetime");

// ruby elements (support for Eastern Asia languages)
addTags("ruby", "rp", "rt");

// other
// note: <menu> was introduced in HTML 2 but we should be include it if we include the child <menuitem>
addTags("menu", "menuitem");
addAttributes("menu", "label", "type");
addAttributes("menuitem", "label", "checked", "command", "default", "disabled",
"icon", "radiogroup", "type");
addProtocols("menuitem", "icon", "http", "https");

return this;
}

/**
Add a list of allowed elements to a safelist. (If a tag is not allowed, it will be removed from the HTML.)

Expand Down