Skip to content

Commit

Permalink
imagesrcset and imagesizes in link (#1444)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedziolkaMichal committed Oct 24, 2022
1 parent 52c649c commit 49656db
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
12 changes: 11 additions & 1 deletion schema/html5/meta.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ datatypes w = "http://whattf.org/datatype-draft"
& common.attrs.i18n
& common.attrs.present
& common.attrs.other
& link.attrs.href
& link.attrs.rel
& link.attrs.href?
& link.attrs.as?
& link.attrs.integrity?
& shared-hyperlink.attrs.hreflang?
Expand All @@ -156,6 +156,8 @@ datatypes w = "http://whattf.org/datatype-draft"
& link.attrs.scope?
& link.attrs.updateviacache?
& link.attrs.workertype?
& link.attrs.imagesrcset?
& link.attrs.imagesizes?
# link.attrs.title included in common.attrs
& embedded.content.attrs.crossorigin?
& common.attrs.aria.role.link?
Expand Down Expand Up @@ -222,6 +224,14 @@ datatypes w = "http://whattf.org/datatype-draft"
string "classic"
| string "module"
}
link.attrs.imagesrcset =
attribute imagesrcset {
string
} & v5only
link.attrs.imagesizes =
attribute imagesizes {
common.data.source.size.list
} & v5only
link.inner =
( empty )

Expand Down
65 changes: 52 additions & 13 deletions src/nu/validator/checker/schematronequiv/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2108,11 +2108,13 @@ localName, uri, msg, getDocumentLocator(),
}
}
}
if ("img".equals(localName) || "source".equals(localName)) {
if (atts.getIndex("", "srcset") > -1) {
String srcsetVal = atts.getValue("", "srcset");
if ("img".equals(localName) || "source".equals(localName) || "link".equals(localName)) {
String srcSetName = "link".equals(localName) ? "imagesrcset" : "srcset";
String sizesName = "link".equals(localName) ? "imagesizes" : "sizes";
if (atts.getIndex("", srcSetName) > -1) {
String srcsetVal = atts.getValue("", srcSetName);
try {
if (atts.getIndex("", "sizes") > -1) {
if (atts.getIndex("", sizesName) > -1) {
ImageCandidateStringsWidthRequired.THE_INSTANCE.checkValid(
srcsetVal);
} else {
Expand All @@ -2122,17 +2124,17 @@ localName, uri, msg, getDocumentLocator(),
// see nu.validator.datatype.ImageCandidateStrings
if ("1".equals(System.getProperty(
"nu.validator.checker.imageCandidateString.hasWidth"))) {
if (atts.getIndex("", "sizes") < 0) {
err("When the \u201csrcset\u201d attribute has"
if (atts.getIndex("", sizesName) < 0) {
err("When the \u201c" + srcSetName + "\u201d attribute has"
+ " any image candidate string with a"
+ " width descriptor, the"
+ " \u201csizes\u201d attribute"
+ " \u201c" + sizesName + "\u201d attribute"
+ " must also be present.");
}
}
} catch (DatatypeException e) {
Class<?> datatypeClass = ImageCandidateStrings.class;
if (atts.getIndex("", "sizes") > -1) {
if (atts.getIndex("", sizesName) > -1) {
datatypeClass = ImageCandidateStringsWidthRequired.class;
}
try {
Expand All @@ -2147,7 +2149,7 @@ localName, uri, msg, getDocumentLocator(),
}
}
VnuBadAttrValueException ex = new VnuBadAttrValueException(
localName, uri, "srcset", srcsetVal,
localName, uri, srcSetName, srcsetVal,
msg, getDocumentLocator(),
datatypeClass, false);
getErrorHandler().error(ex);
Expand All @@ -2167,7 +2169,7 @@ msg, getDocumentLocator(),
+ " following sibling"
+ " \u201csource\u201d element or"
+ " \u201cimg\u201d element with a"
+ " \u201csrcset\u201d attribute"
+ " \u201c" + srcSetName + "\u201d attribute"
+ " must have a"
+ " \u201cmedia\u201d attribute and/or"
+ " \u201ctype\u201d attribute.",
Expand All @@ -2187,9 +2189,9 @@ msg, getDocumentLocator(),
}
}
}
} else if (atts.getIndex("", "sizes") > -1) {
err("The \u201csizes\u201d attribute may be specified"
+ " only if the \u201csrcset\u201d attribute is"
} else if (atts.getIndex("", sizesName) > -1) {
err("The \u201c" + sizesName + "\u201d attribute may be specified"
+ " only if the \u201c" + srcSetName + "\u201d attribute is"
+ " also present.");
}
}
Expand Down Expand Up @@ -2994,6 +2996,13 @@ else if ("bdo" == localName && atts.getIndex("", "dir") < 0) {
atts.getValue("", "rel") //
.toLowerCase().split("\\s+"));
}
if (atts.getIndex("", "href") == -1
&& atts.getIndex("", "imagesrcset") == -1
&& atts.getIndex("", "resource") == -1) { //rdfa
err("A \u201Clink\u201D element must have an"
+ " \u201Chref\u201D or \u201Cimagesrcset\u201D"
+ " attribute, or both.");
}
if (relList.contains("preload")
&& atts.getIndex("", "as") < 0) {
err("A \u201Clink\u201D element with a"
Expand Down Expand Up @@ -3078,6 +3087,36 @@ else if ("bdo" == localName && atts.getIndex("", "dir") < 0) {
+ " \u201Crel\u201D attribute that contains the"
+ " value \u201Cserviceworker\u201D.");
}
if (atts.getIndex("", "imagesrcset") > -1
&& !(relList.contains("preload")
|| !hasRel)) {
err("A \u201Clink\u201D element with an"
+ " \u201Cimagesrcset\u201D attribute must have a"
+ " \u201Crel\u201D attribute that contains the"
+ " value \u201Cpreload\u201D.");
}
if (atts.getIndex("", "imagesizes") > -1
&& !(relList.contains("preload")
|| !hasRel)) {
err("A \u201Clink\u201D element with an"
+ " \u201Cimagesizes\u201D attribute must have a"
+ " \u201Crel\u201D attribute that contains the"
+ " value \u201Cpreload\u201D.");
}
if (atts.getIndex("", "imagesrcset") > -1
&& (atts.getIndex("", "as") == -1
|| !atts.getValue("", "as").equalsIgnoreCase("image"))) {
err("A \u201Clink\u201D element with an"
+ " \u201Cimagesrcset\u201D attribute must have an"
+ " \u201Cas\u201D attribute with value \u201Cimage\u201D.");
}
if (atts.getIndex("", "imagesizes") > -1
&& (atts.getIndex("", "as") == -1
|| !atts.getValue("", "as").equalsIgnoreCase("image"))) {
err("A \u201Clink\u201D element with an"
+ " \u201Cimagesizes\u201D attribute must have an"
+ " \u201Cas\u201D attribute with value \u201Cimage\u201D.");
}
if ((ancestorMask & BODY_MASK) != 0
&& (relList != null
&& !(relList.contains("dns-prefetch")
Expand Down

0 comments on commit 49656db

Please sign in to comment.