html-validate 10.3.1 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,8 @@ const {
6
6
  allowedIfAttributeIsPresent,
7
7
  allowedIfAttributeIsAbsent,
8
8
  allowedIfAttributeHasValue,
9
- allowedIfParentIsPresent
9
+ allowedIfParentIsPresent,
10
+ hasKeyword
10
11
  } = metaHelper.metadataHelper;
11
12
  const validId = "/\\S+/";
12
13
  const ReferrerPolicy = [
@@ -1659,9 +1660,46 @@ var html5 = {
1659
1660
  boolean: true
1660
1661
  },
1661
1662
  href: {
1662
- required: true,
1663
+ required(node) {
1664
+ if (node.hasAttribute("imagesrcset")) {
1665
+ return false;
1666
+ }
1667
+ return `{{ tagName }} is missing required "href" or "imagesrcset" attribute`;
1668
+ },
1663
1669
  enum: ["/.+/"]
1664
1670
  },
1671
+ imagesrcset: {
1672
+ allowed(node) {
1673
+ const rel = node.getAttribute("rel");
1674
+ const as = node.getAttribute("as");
1675
+ if (!rel || typeof rel === "string" && !hasKeyword(rel, "preload")) {
1676
+ return `"rel" attribute must be "preload"`;
1677
+ }
1678
+ if (!as || typeof as === "string" && as !== "image") {
1679
+ return `"as" attribute must be "image"`;
1680
+ }
1681
+ return null;
1682
+ }
1683
+ },
1684
+ imagesizes: {
1685
+ allowed(node) {
1686
+ const rel = node.getAttribute("rel");
1687
+ const as = node.getAttribute("as");
1688
+ if (!rel || typeof rel === "string" && !hasKeyword(rel, "preload")) {
1689
+ return `"rel" attribute must be "preload"`;
1690
+ }
1691
+ if (!as || typeof as === "string" && as !== "image") {
1692
+ return `"as" attribute must be "image"`;
1693
+ }
1694
+ return null;
1695
+ },
1696
+ required(node) {
1697
+ if (node.hasAttribute("imagesrcset")) {
1698
+ return `{{ tagName }} requires "{{ attr }}" attribute when "imagesrcset" attribute is set`;
1699
+ }
1700
+ return false;
1701
+ }
1702
+ },
1665
1703
  integrity: {
1666
1704
  allowed: allowedIfAttributeHasValue("rel", ["stylesheet", "preload", "modulepreload"]),
1667
1705
  enum: ["/.+/"]