From 5606f32f13be3d9579e544e2282d0746e398feb6 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 14 Mar 2017 21:50:10 -0400 Subject: [PATCH] WIP; messaging much more logical, except @todo noted. --- include/tidyenum.h | 1 + src/language_en.h | 1 + src/message.c | 5 +++++ src/tags.c | 48 +++++++++++++++++++++++++++------------------- src/tags.h | 8 +++++++- src/tidylib.c | 17 +++++++++++++++- 6 files changed, 58 insertions(+), 22 deletions(-) diff --git a/include/tidyenum.h b/include/tidyenum.h index 1889a85..24f81c4 100644 --- a/include/tidyenum.h +++ b/include/tidyenum.h @@ -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) \ diff --git a/src/language_en.h b/src/language_en.h index 8fc04ba..59cae7b 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -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" }, diff --git a/src/message.c b/src/message.c index a4ca645..a5e17f7 100755 --- a/src/message.c +++ b/src/message.c @@ -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 ); diff --git a/src/tags.c b/src/tags.c index 7965002..1c6819b 100644 --- a/src/tags.c +++ b/src/tags.c @@ -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,12 +562,12 @@ 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; else if ( configtype == TidyCustomInline ) @@ -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,24 +1056,30 @@ 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, '-'); - + /* Tag must contain hyphen not in first character. */ if ( ptr && (ptr - node->element > 0) ) { return yes; } } - + 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 ) diff --git a/src/tags.h b/src/tags.h index 988ceca..0b962c6 100644 --- a/src/tags.h +++ b/src/tags.h @@ -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 ); diff --git a/src/tidylib.c b/src/tidylib.c index 2187d97..8b8acfd 100755 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -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;