From 34305a13d1027c54399ffe40d8f1ff2e032d4606 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sun, 20 Nov 2011 20:58:35 +0900 Subject: [PATCH] report missing href & rel for link elements --- include/tidyenum.h | 1 + src/attrdict.c | 1 + src/attrs.c | 1 + src/attrs.h | 1 + src/tags.c | 24 +++++++++++------------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/tidyenum.h b/include/tidyenum.h index 35fcdc5..a125bce 100644 --- a/include/tidyenum.h +++ b/include/tidyenum.h @@ -537,6 +537,7 @@ typedef enum TidyAttr_HTTP_EQUIV, /**< HTTP_EQUIV= */ TidyAttr_ID, /**< ID= */ TidyAttr_ISMAP, /**< ISMAP= */ + TidyAttr_ITEMPROP, /**< ITEMPROP= */ TidyAttr_LABEL, /**< LABEL= */ TidyAttr_LANG, /**< LANG= */ TidyAttr_LANGUAGE, /**< LANGUAGE= */ diff --git a/src/attrdict.c b/src/attrdict.c index 35e476e..474f134 100644 --- a/src/attrdict.c +++ b/src/attrdict.c @@ -4740,6 +4740,7 @@ const AttrVersion TY_(W3CAttrsFor_LINK)[] = { TidyAttr_HREF, HT20|HT32|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10|HT50|XH50 }, { TidyAttr_HREFLANG, xxxx|xxxx|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10|HT50|XH50 }, { TidyAttr_ID, xxxx|xxxx|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10|HT50|XH50 }, + { TidyAttr_ITEMPROP, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, { TidyAttr_LANG, xxxx|xxxx|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|xxxx|xxxx|HT50|XH50 }, { TidyAttr_MEDIA, xxxx|xxxx|H40T|H41T|X10T|H40F|H41F|X10F|H40S|H41S|X10S|XH11|XB10|HT50|XH50 }, { TidyAttr_METHODS, HT20|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx }, diff --git a/src/attrs.c b/src/attrs.c index f4808fb..85d0751 100644 --- a/src/attrs.c +++ b/src/attrs.c @@ -158,6 +158,7 @@ static const Attribute attribute_defs [] = { TidyAttr_HTTP_EQUIV, "http-equiv", CH_PCDATA }, /* META */ { TidyAttr_ID, "id", CH_IDDEF }, { TidyAttr_ISMAP, "ismap", CH_BOOL }, /* IMG */ + { TidyAttr_ITEMPROP, "itemprop", CH_PCDATA }, { TidyAttr_LABEL, "label", CH_PCDATA }, /* OPT, OPTGROUP */ { TidyAttr_LANG, "lang", CH_LANG }, { TidyAttr_LANGUAGE, "language", CH_PCDATA }, /* SCRIPT */ diff --git a/src/attrs.h b/src/attrs.h index 1668db6..7b06ab4 100644 --- a/src/attrs.h +++ b/src/attrs.h @@ -223,6 +223,7 @@ uint TY_(NodeAttributeVersions)( Node* node, TidyAttrId id ); #define attrIsHTTP_EQUIV(av) AttrIsId( av, TidyAttr_HTTP_EQUIV ) #define attrIsID(av) AttrIsId( av, TidyAttr_ID ) #define attrIsISMAP(av) AttrIsId( av, TidyAttr_ISMAP ) +#define attrIsITEMPROP(av) AttrIsId( av, TidyAttr_ITEMPROP ) #define attrIsLABEL(av) AttrIsId( av, TidyAttr_LABEL ) #define attrIsLANG(av) AttrIsId( av, TidyAttr_LANG ) #define attrIsLANGUAGE(av) AttrIsId( av, TidyAttr_LANGUAGE ) diff --git a/src/tags.c b/src/tags.c index 2fc3245..372728c 100644 --- a/src/tags.c +++ b/src/tags.c @@ -786,23 +786,21 @@ void CheckTABLE( TidyDocImpl* doc, Node *node ) } } -/* add missing type attribute when appropriate */ +/* report missing href attribute; report missing rel attribute */ void CheckLINK( TidyDocImpl* doc, Node *node ) { - AttVal *rel = TY_(AttrGetById)(node, TidyAttr_REL); + Bool HasHref = TY_(AttrGetById)(node, TidyAttr_HREF) != NULL; + Bool HasRel = TY_(AttrGetById)(node, TidyAttr_REL) != NULL; + Bool HasItemprop = TY_(AttrGetById)(node, TidyAttr_ITEMPROP) != NULL; - TY_(CheckAttributes)( doc, node ); - - /* todo: */ - if (AttrValueIs(rel, "stylesheet")) + if (!HasHref) { - AttVal *type = TY_(AttrGetById)(node, TidyAttr_TYPE); - if (!type) - { - TY_(AddAttribute)( doc, node, "type", "text/css" ); - type = TY_(AttrGetById)(node, TidyAttr_TYPE); - TY_(ReportAttrError)( doc, node, type, INSERTING_ATTRIBUTE ); - } + TY_(ReportMissingAttr)( doc, node, "href" ); + } + + if (!HasItemprop && !HasRel) + { + TY_(ReportMissingAttr)( doc, node, "rel" ); } }