📄 attrs.c
字号:
{ dict = hashtab[i]; while(dict) { next = dict->next; MemFree(dict->name); MemFree(dict); dict = next; } hashtab[i] = null; }}/* the same attribute name can't be used more than once in each element*/void CheckUniqueAttribute(Lexer *lexer, Node *node, AttVal *attval){ AttVal *attr; int count = 0; for (attr = node->attributes; attr; attr = attr->next) { if (wstrcasecmp(attval->attribute, attr->attribute) == 0) ++count; } if (count > 1) ReportAttrError(lexer, node, attval->attribute, REPEATED_ATTRIBUTE);}void CheckUniqueAttributes(Lexer *lexer, Node *node){ AttVal *attval; for (attval = node->attributes; attval != null; attval = attval->next) CheckUniqueAttribute(lexer, node, attval);}/* ignore unknown attributes for proprietary elements */Attribute *CheckAttribute(Lexer *lexer, Node *node, AttVal *attval){ Attribute *attribute; CheckUniqueAttribute(lexer, node, attval); if ((attribute = attval->dict) != null) { /* title is vers 2.0 for A and LINK otherwise vers 4.0 */ if (attribute == attr_title && (node->tag == tag_a || node->tag == tag_link)) lexer->versions &= VERS_ALL; else if (attribute->versions & VERS_XML) { if (!(XmlTags || XmlOut)) ReportAttrError(lexer, node, attval->attribute, XML_ATTRIBUTE_VALUE); } else lexer->versions &= attribute->versions; if (attribute->attrchk) attribute->attrchk(lexer, node, attval); } else if (!XmlTags && !(node->tag == null) && attval->asp == null && !(node->tag && (node->tag->versions & VERS_PROPRIETARY))) ReportAttrError(lexer, node, attval->attribute, UNKNOWN_ATTRIBUTE); return attribute;}Bool IsBoolAttribute(AttVal *attval){ Attribute *attribute; if ((attribute = attval->dict) != null) { if (attribute->attrchk == CheckBool) return yes; } return no;}/* methods for checking value of a specific attribute */void CheckUrl(Lexer *lexer, Node *node, AttVal *attval){ char c, *p = attval->value; if (p == null) ReportAttrError(lexer, node, attval->attribute, MISSING_ATTR_VALUE); else if (FixBackslash) { while ((c = *p)) { if (c =='\\') *p = '/'; ++p; } }}void CheckScript(Lexer *lexer, Node *node, AttVal *attval){}void CheckName(Lexer *lexer, Node *node, AttVal *attval){}void CheckId(Lexer *lexer, Node *node, AttVal *attval){}void CheckBool(Lexer *lexer, Node *node, AttVal *attval){}void CheckAlign(Lexer *lexer, Node *node, AttVal *attval){ char *value; /* IMG, OBJECT, APPLET and EMBED use align for vertical position */ if (node->tag && (node->tag->model & CM_IMG)) { CheckValign(lexer, node, attval); return; } value = attval->value; if (value == null) ReportAttrError(lexer, node, attval->attribute, MISSING_ATTR_VALUE); else if (! (wstrcasecmp(value, "left") == 0 || wstrcasecmp(value, "center") == 0 || wstrcasecmp(value, "right") == 0 || wstrcasecmp(value, "justify") == 0)) ReportAttrError(lexer, node, attval->value, BAD_ATTRIBUTE_VALUE);}void CheckValign(Lexer *lexer, Node *node, AttVal *attval){ char *value; value = attval->value; if (value == null) ReportAttrError(lexer, node, attval->attribute, MISSING_ATTR_VALUE); else if (wstrcasecmp(value, "top") == 0 || wstrcasecmp(value, "middle") == 0 || wstrcasecmp(value, "bottom") == 0 || wstrcasecmp(value, "baseline") == 0) { /* all is fine */ } else if (wstrcasecmp(value, "left") == 0 || wstrcasecmp(value, "right") == 0) { if (!(node->tag && (node->tag->model & CM_IMG))) ReportAttrError(lexer, node, value, BAD_ATTRIBUTE_VALUE); } else if (wstrcasecmp(value, "texttop") == 0 || wstrcasecmp(value, "absmiddle") == 0 || wstrcasecmp(value, "absbottom") == 0 || wstrcasecmp(value, "textbottom") == 0) { lexer->versions &= VERS_PROPRIETARY; ReportAttrError(lexer, node, value, PROPRIETARY_ATTR_VALUE); } else ReportAttrError(lexer, node, value, BAD_ATTRIBUTE_VALUE);}/* default method for checking an element's attributes */void CheckAttributes(Lexer *lexer, Node *node){ AttVal *attval; for (attval = node->attributes; attval != null; attval = attval->next) CheckAttribute(lexer, node, attval);}/* methods for checking attributes for specific elements */void CheckIMG(Lexer *lexer, Node *node){ AttVal *attval; Attribute *attribute; Bool HasAlt = no; Bool HasSrc = no; Bool HasUseMap = no; Bool HasIsMap = no; for (attval = node->attributes; attval != null; attval = attval->next) { attribute = CheckAttribute(lexer, node, attval); if (attribute == attr_alt) HasAlt = yes; else if (attribute == attr_src) HasSrc = yes; else if (attribute == attr_usemap) HasUseMap = yes; else if (attribute == attr_ismap) HasIsMap = yes; } if (!HasAlt) { lexer->badAccess |= MISSING_IMAGE_ALT; ReportAttrError(lexer, node, "alt", MISSING_ATTRIBUTE); if (alt_text) AddAttribute(node, "alt", alt_text); } if (!HasSrc) ReportAttrError(lexer, node, "src", MISSING_ATTRIBUTE); if (HasIsMap && !HasUseMap) ReportAttrError(lexer, node, "ismap", MISSING_IMAGEMAP);}void CheckAnchor(Lexer *lexer, Node *node){ FixId(lexer, node);}void CheckMap(Lexer *lexer, Node *node){ FixId(lexer, node);}void CheckCaption(Lexer *lexer, Node *node){ AttVal *attval; char *value = null; for (attval = node->attributes; attval != null; attval = attval->next) { if (wstrcasecmp(attval->attribute, "align") == 0) { value = attval->value; break; } } if (value != null) { if (wstrcasecmp(value, "left") == 0 || wstrcasecmp(value, "right") == 0) lexer->versions &= (VERS_HTML40_LOOSE|VERS_FRAMES); else if (wstrcasecmp(value, "top") == 0 || wstrcasecmp(value, "bottom") == 0) lexer->versions &= VERS_FROM32; else ReportAttrError(lexer, node, value, BAD_ATTRIBUTE_VALUE); }}void CheckHTML(Lexer *lexer, Node *node){ AttVal *attval; Attribute *attribute; for (attval = node->attributes; attval != null; attval = attval->next) { attribute = CheckAttribute(lexer, node, attval); if (attribute == attr_xmlns) lexer->isvoyager = yes; }}void CheckAREA(Lexer *lexer, Node *node){ AttVal *attval; Attribute *attribute; Bool HasAlt = no; Bool HasHref = no; for (attval = node->attributes; attval != null; attval = attval->next) { attribute = CheckAttribute(lexer, node, attval); if (attribute == attr_alt) HasAlt = yes; else if (attribute == attr_href) HasHref = yes; } if (!HasAlt) { lexer->badAccess |= MISSING_LINK_ALT; ReportAttrError(lexer, node, "alt", MISSING_ATTRIBUTE); } if (!HasHref) ReportAttrError(lexer, node, "href", MISSING_ATTRIBUTE);}void CheckTABLE(Lexer *lexer, Node *node){ AttVal *attval; Attribute *attribute; Bool HasSummary = no; for (attval = node->attributes; attval != null; attval = attval->next) { attribute = CheckAttribute(lexer, node, attval); if (attribute == attr_summary) HasSummary = yes; } /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */ if (!HasSummary && lexer->doctype != VERS_HTML20 && lexer->doctype != VERS_HTML32) { lexer->badAccess |= MISSING_SUMMARY; ReportAttrError(lexer, node, "summary", MISSING_ATTRIBUTE); } /* convert <table border> to <table border="1"> */ if (XmlOut && (attval = GetAttrByName(node, "border"))) { if (attval->value == null) attval->value = wstrdup("1"); }}/* add missing type attribute when appropriate */void CheckSCRIPT(Lexer *lexer, Node *node){ AttVal *lang, *type; char buf[16]; lang = GetAttrByName(node, "language"); type = GetAttrByName(node, "type"); if (!type) { ReportAttrError(lexer, node, "type", MISSING_ATTRIBUTE); /* check for javascript */ if (lang) { wstrncpy(buf, lang->value, 10); buf[10] = '\0'; if ( (wstrncasecmp(buf, "javascript", 10) == 0) || (wstrncasecmp(buf, "jscript", 7) == 0) ) { AddAttribute(node, "type", "text/javascript"); } } else AddAttribute(node, "type", "text/javascript"); }}/* add missing type attribute when appropriate */void CheckSTYLE(Lexer *lexer, Node *node){ AttVal *type = GetAttrByName(node, "type"); if (!type) { ReportAttrError(lexer, node, "type", MISSING_ATTRIBUTE); AddAttribute(node, "type", "text/css"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -