Issue #210 - Add new warning for summary attr in table if HTML5.

This new warning will only be seen if the document remains in HTML5 mode,
where the summary attribute is obsolete. The W3C validator flags this as
an error, and suggests 'Consider describing the structure of the table in
a caption element or in a figure element containing the table; or simplify
the structure of the table so that no description is needed'.

At the same time this patch also restored the old warning if the document
is HTML4--, if the table element lacks a summary attribute. This has been
a tidy warning since the beginning of time, although the W3C validator
does not presently flag this.
This commit is contained in:
Geoff McLane 2015-06-06 11:07:41 +02:00
parent f67300963e
commit 3f72b6e335
3 changed files with 25 additions and 2 deletions

View File

@ -113,7 +113,8 @@ static struct _msgfmt
/* HTML5 */
{ REMOVED_HTML5, "%s element removed from HTML5" }, /* Warning */
{ BAD_BODY_HTML5, "Found attribute on body that is obsolete in HTML5. Use CSS" }, /* Warning */
{ BAD_ALIGN_HTML5, "The align attribute on the %s element is obsolete, Use CSS" }, /* Wanring */
{ BAD_ALIGN_HTML5, "The align attribute on the %s element is obsolete, Use CSS" }, /* Warning */
{ BAD_SUMMARY_HTML5, "The summary attribute on the %s element is obsolete in HTML5" }, /* Warning */
/* ReportNotice */
{ TRIM_EMPTY_ELEMENT, "trimming empty %s" }, /* Notice */
@ -1499,6 +1500,7 @@ void TY_(ReportWarning)(TidyDocImpl* doc, Node *element, Node *node, uint code)
case REMOVED_HTML5:
case BAD_BODY_HTML5:
case BAD_ALIGN_HTML5:
case BAD_SUMMARY_HTML5:
messageNode(doc, TidyWarning, rpt, fmt, nodedesc);
break;
case COERCE_TO_ENDTAG_WARN:

View File

@ -157,8 +157,9 @@ void TY_(ReportFatal)(TidyDocImpl* doc, Node* element, Node* node, uint code);
#define REMOVED_HTML5 88 /* this element removed from HTML5 */
#define BAD_BODY_HTML5 89 /* attr on body removed from HTML5 */
#define BAD_ALIGN_HTML5 90 /* use of align attr removed from HTML5 */
#define BAD_SUMMARY_HTML5 91 /* use of summary attr removed from HTML5 */
#define PREVIOUS_LOCATION 91 /* last */
#define PREVIOUS_LOCATION 92 /* last */
/* character encoding errors */

View File

@ -873,9 +873,29 @@ void CheckAREA( TidyDocImpl* doc, Node *node )
void CheckTABLE( TidyDocImpl* doc, Node *node )
{
AttVal* attval;
Bool HasSummary = (TY_(AttrGetById)(node, TidyAttr_SUMMARY) != NULL) ? yes : no;
Bool isHTML5 = (TY_(HTMLVersion)(doc) == HT50) ? yes : no;
TY_(CheckAttributes)(doc, node);
/* Issue #210 - a missing summary attribute is bad accessibility, no matter
what HTML version is involved; a document without is valid
EXCEPT for HTML5, when to have a summary is wrong */
if (cfg(doc, TidyAccessibilityCheckLevel) == 0)
{
if (HasSummary && isHTML5)
{
/* #210 - has summary, and is HTML5, then report obsolete */
TY_(ReportWarning)(doc, node, node, BAD_SUMMARY_HTML5);
}
else if (!HasSummary && !isHTML5)
{
/* #210 - No summary, and NOT HTML5, then report as before */
doc->badAccess |= BA_MISSING_SUMMARY;
TY_(ReportMissingAttr)( doc, node, "summary");
}
}
/* convert <table border> to <table border="1"> */
if ( cfgBool(doc, TidyXmlOut) && (attval = TY_(AttrGetById)(node, TidyAttr_BORDER)) )
{