html-validate 10.3.1 → 10.5.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.
@@ -4,7 +4,8 @@ const {
4
4
  allowedIfAttributeIsPresent,
5
5
  allowedIfAttributeIsAbsent,
6
6
  allowedIfAttributeHasValue,
7
- allowedIfParentIsPresent
7
+ allowedIfParentIsPresent,
8
+ hasKeyword
8
9
  } = metadataHelper;
9
10
  const validId = "/\\S+/";
10
11
  const ReferrerPolicy = [
@@ -1657,9 +1658,46 @@ var html5 = {
1657
1658
  boolean: true
1658
1659
  },
1659
1660
  href: {
1660
- required: true,
1661
+ required(node) {
1662
+ if (node.hasAttribute("imagesrcset")) {
1663
+ return false;
1664
+ }
1665
+ return `{{ tagName }} is missing required "href" or "imagesrcset" attribute`;
1666
+ },
1661
1667
  enum: ["/.+/"]
1662
1668
  },
1669
+ imagesrcset: {
1670
+ allowed(node) {
1671
+ const rel = node.getAttribute("rel");
1672
+ const as = node.getAttribute("as");
1673
+ if (!rel || typeof rel === "string" && !hasKeyword(rel, "preload")) {
1674
+ return `"rel" attribute must be "preload"`;
1675
+ }
1676
+ if (!as || typeof as === "string" && as !== "image") {
1677
+ return `"as" attribute must be "image"`;
1678
+ }
1679
+ return null;
1680
+ }
1681
+ },
1682
+ imagesizes: {
1683
+ allowed(node) {
1684
+ const rel = node.getAttribute("rel");
1685
+ const as = node.getAttribute("as");
1686
+ if (!rel || typeof rel === "string" && !hasKeyword(rel, "preload")) {
1687
+ return `"rel" attribute must be "preload"`;
1688
+ }
1689
+ if (!as || typeof as === "string" && as !== "image") {
1690
+ return `"as" attribute must be "image"`;
1691
+ }
1692
+ return null;
1693
+ },
1694
+ required(node) {
1695
+ if (node.hasAttribute("imagesrcset")) {
1696
+ return `{{ tagName }} requires "{{ attr }}" attribute when "imagesrcset" attribute is set`;
1697
+ }
1698
+ return false;
1699
+ }
1700
+ },
1663
1701
  integrity: {
1664
1702
  allowed: allowedIfAttributeHasValue("rel", ["stylesheet", "preload", "modulepreload"]),
1665
1703
  enum: ["/.+/"]