Skip to content

Support property on link element in html5 #833

Open
@geoffmcl

Description

@geoffmcl

This issue originally raised by @da2x, in April, 2019, as PR #814 -

<link itemprop="subject" href="../example"> in Microdata is equivalent to <link property="subject" href="../example"> in RDFa. This HTML+RDFa syntax doesn’t trigger any errors or warnings from the W3C Nu Html Checker in HTML5 mode.

This change changes the requirement from link[itemprop|rel] to link[itemprop|property|rel] to support the HTML5+RDFa syntax.

See also: https://www.w3.org/TR/html-rdfa/#extensions-to-the-html5-syntax

While the PR #814 has been closed, since it was against master, it raises several important questions... maybe bugs!

Have added 2 tests - in_814.html, for html5, and in_814-1.html, for legacy html4... which can be put to the W3C validator... should get pass and fail respectively...

Running current tidy, 5.7.27, on either sample will give a warning, Warning: <link> lacks "rel" attribute! That seems wrong in both cases...

Presently experimenting with the following patch -

diff --git a/src/tags.c b/src/tags.c
index af2b7d9..ecc0ee7 100644
--- a/src/tags.c
+++ b/src/tags.c
@@ -1008,21 +1008,44 @@ void CheckTABLE( TidyDocImpl* doc, Node *node )
     }
 }
 
-/* report missing href attribute; report missing rel attribute */
+/* report missing href attribute; report missing rel attribute
+   Is. #814 - change from link[itemprop|rel] to link[itemprop|property|rel]
+   to support the HTML5+RDFa syntax.
+   Ref: https://www.w3.org/TR/html-rdfa/#extensions-to-the-html5-syntax
+ */
 void CheckLINK( TidyDocImpl* doc, Node *node )
 {
     Bool HasHref = TY_(AttrGetById)(node, TidyAttr_HREF) != NULL;
     Bool HasRel = TY_(AttrGetById)(node, TidyAttr_REL) != NULL;
     Bool HasItemprop = TY_(AttrGetById)(node, TidyAttr_ITEMPROP) != NULL;
+    AttVal *prop = TY_(AttrGetById)(node, TidyAttr_PROPERTY);
+    Bool HasProperty = (prop == NULL) ? no : yes; /* Is #814 */
 
     if (!HasHref)
     {
       TY_(ReportMissingAttr)( doc, node, "href" );
     }
 
-    if (!HasItemprop && !HasRel)
+    if (TY_(IsHTML5Mode)(doc))
+    {
+        /* Is. #814 - @da2x patch - add 'property' attr */
+        if (!HasItemprop && !HasRel && !HasProperty)
+        {
+            TY_(ReportMissingAttr)(doc, node, "rel");
+        }
+    }
+    else 
     {
-      TY_(ReportMissingAttr)( doc, node, "rel" );
+        /* legacy doc parsing */
+        if (HasProperty)
+        {
+            TY_(ReportAttrError)(doc, node, prop, MISMATCHED_ATTRIBUTE_WARN);
+        }
+        else if (!HasItemprop && !HasRel)
+        {
+            TY_(ReportMissingAttr)(doc, node, "rel");
+        }
+
     }
 }
 

Running the resultant tidy 5.7.27.I814 on the samples appears to now do the right thing... the in_814.html, the html5, has no errors/warnings, while the in_814-1.html, the html4, outputs Warning: <link> attribute "property" not allowed for HTML 4.01 Transitional...

After as little more testing, will try to set this up as a PR... unless someone beats me to it...

Look forward to further feedback... thanks...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions