WIP; messaging much more logical, except @todo noted.

This commit is contained in:
Jim Derry 2017-03-14 21:50:10 -04:00
parent 66ade9def4
commit 5606f32f13
6 changed files with 58 additions and 22 deletions

View file

@ -908,6 +908,7 @@ typedef enum
FN(PROPRIETARY_ELEMENT) \
FN(REPLACING_ELEMENT) \
FN(CUSTOM_TAG_DETECTED) \
FN(CUSTOM_TAG_DETECTED_SETTING) \
FN(REPLACING_UNEX_ELEMENT) \
FN(SPACE_PRECEDING_XMLDECL) \
FN(SUSPECTED_MISSING_QUOTE) \

View file

@ -386,6 +386,7 @@ static languageDefinition language_en = { whichPluralForm_en, {
{ TRIM_EMPTY_ELEMENT, 0, "trimming empty %s" }, /* Notice */
{ REPLACING_ELEMENT, 0, "replacing %s with %s" }, /* Notice */
{ CUSTOM_TAG_DETECTED, 0, "detected autonomous custom tag %s; will treat as %s" }, /* Notice */
{ CUSTOM_TAG_DETECTED_SETTING, 0, "%s appears to be an autonomous custom tag; did you mean to set the custom-tags option?" }, /* Notice */
{ TidyCustomBlocklevel, 0, "block level" },
{ TidyCustomEmpty, 0, "empty" },
{ TidyCustomInline, 0, "inline" },

View file

@ -232,6 +232,11 @@ void TY_(ReportNotice)(TidyDocImpl* doc, Node *element, Node *node, uint code)
tagtype = tidyLocalizedString( cfg( doc, TidyUseCustomTags ) );
message = TY_(tidyMessageCreateWithNode)(doc, element, code, TidyInfo, elemdesc, tagtype );
break;
case CUSTOM_TAG_DETECTED_SETTING:
message = TY_(tidyMessageCreateWithNode)(doc, node, code, TidyInfo, nodedesc );
break;
}
messageOut( message );

View file

@ -546,6 +546,8 @@ void show_have_html5(void)
/* public interface for finding tag by name */
Bool TY_(FindTag)( TidyDocImpl* doc, Node *node )
{
TidyUseCustomTagsState configtype = cfg( doc, TidyUseCustomTags );
Bool htmlIs5 = (doc->lexer->doctype & VERS_HTML5) > 0;
const Dict *np = NULL;
if ( cfgBool(doc, TidyXmlTags) )
@ -560,11 +562,11 @@ Bool TY_(FindTag)( TidyDocImpl* doc, Node *node )
return yes;
}
/* Add anonymous custom tag */
/* Add autonomous custom tag. This can be done in both HTML5 mode and
earlier, although if it's earlier we will complain about it elsewhere. */
if ( TY_(nodeIsAutonomousCustomTag)( doc, node) )
{
UserTagType type;
TidyUseCustomTagsState configtype = cfg( doc, TidyUseCustomTags );
if ( configtype == TidyCustomEmpty )
type = tagtype_empty;
@ -578,19 +580,19 @@ Bool TY_(FindTag)( TidyDocImpl* doc, Node *node )
TY_(DeclareUserTag)( doc, TidyCustomTags, type, node->element );
node->tag = tagsLookup(doc, &doc->tags, node->element);
if ( (doc->lexer->doctype & VERS_HTML5) )
{
TY_(ReportNotice)(doc, node, node, CUSTOM_TAG_DETECTED);
}
else
{
/* TODO: not sure whether to include this here, or let it
happen where it already happens; still need to suppress elsewhere */
TY_(ReportError)(doc, NULL, node, PROPRIETARY_ELEMENT);
}
/* Output a message the first time we encounter an autonomous custom
tag. This applies despite the HTML5 mode. */
TY_(ReportNotice)(doc, node, node, CUSTOM_TAG_DETECTED);
return yes;
}
else if ( TY_(nodeIsAutonomousCustomFormat)( node ) && htmlIs5 )
{
/* It looks like a custom tag, we're in HTML5, but custom-tags is
off, so warn the user. TODO: handle in the lexer so we don't
repeat this over and over again.*/
TY_(ReportNotice)(doc, node, node, CUSTOM_TAG_DETECTED_SETTING);
}
return no;
}
@ -1054,11 +1056,9 @@ Bool nodeMatchCM( Node* node, uint contentModel )
#endif
/* True if the node looks like it's an autonomous custom element tag.
*/
Bool TY_(nodeIsAutonomousCustomTag)( TidyDocImpl* doc, Node* node )
Bool TY_(nodeIsAutonomousCustomFormat)( Node* node )
{
if ( node->element && cfg( doc, TidyUseCustomTags ) != TidyCustomNo )
if ( node->element )
{
const char *ptr = strchr(node->element, '-');
@ -1072,6 +1072,14 @@ Bool TY_(nodeIsAutonomousCustomTag)( TidyDocImpl* doc, Node* node )
return no;
}
Bool TY_(nodeIsAutonomousCustomTag)( TidyDocImpl* doc, Node* node )
{
return TY_(nodeIsAutonomousCustomFormat)( node )
&& ( cfg( doc, TidyUseCustomTags ) != TidyCustomNo );
}
/* True if any of the bits requested are set.
*/
Bool TY_(nodeHasCM)( Node* node, uint contentModel )

View file

@ -134,10 +134,16 @@ Bool nodeMatchCM( Node* node, uint contentModel );
#endif
/* True if the node looks like it's an autonomous custom element tag.
/* True if the node looks like it's an autonomous custom element tag. */
Bool TY_(nodeIsAutonomousCustomFormat)( Node* node );
/* True if the node looks like it's an autonomous custom element tag, and
TidyCustomTags is not disabled, and we're in HTML5 mode, which are all
requirements for valid autonomous custom tags.
*/
Bool TY_(nodeIsAutonomousCustomTag)( TidyDocImpl* doc, Node* node );
/* True if any of the bits requested are set.
*/
Bool TY_(nodeHasCM)( Node* node, uint contentModel );

View file

@ -1747,6 +1747,8 @@ void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node )
AttVal *next_attr, *attval;
Bool attrIsProprietary = no;
Bool attrIsMismatched = yes;
Bool tagLooksCustom = no;
Bool htmlIs5 = (doc->lexer->doctype & VERS_HTML5) > 0;
while (node)
{
@ -1767,7 +1769,20 @@ void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node )
if ( !cfgBool(doc, TidyMakeClean) ||
( !nodeIsNOBR(node) && !nodeIsWBR(node) ) )
{
TY_(ReportError)(doc, NULL, node, PROPRIETARY_ELEMENT );
/* It looks custom, despite whether it's a known tag. */
tagLooksCustom = TY_(nodeIsAutonomousCustomFormat)( node );
/* If we're in HTML5 mode and the tag does not look
like a valid custom tag, then issue a warning.
Appearance is good enough because invalid tags have
been dropped. Also, if we're not in HTML5 mode, then
then everything that reaches here gets the warning.
Everything else can be ignored. */
if ( (htmlIs5 && !tagLooksCustom) || !htmlIs5 )
{
TY_(ReportError)(doc, NULL, node, PROPRIETARY_ELEMENT );
}
if ( nodeIsLAYER(node) )
doc->badLayout |= USING_LAYER;