public virtual void Check(Lexer lexer, Node node)
        {
            node.CheckUniqueAttributes(lexer);

            AttVal lang = node.GetAttrByName("language");
            AttVal type = node.GetAttrByName("type");
            if (type == null)
            {
                Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);

                /* check for javascript */
                if (lang != null)
                {
                    string str = lang.Val;
                    if (str.Length > 10)
                    {
                        str = str.Substring(0, 10);
                    }

                    if ((String.Compare(str, "javascript") == 0) || (String.Compare(str, "jscript") == 0))
                    {
                        node.AddAttribute("type", "text/javascript");
                    }
                }
                else
                {
                    node.AddAttribute("type", "text/javascript");
                }
            }
        }
        protected internal virtual void PreTraverse(Node node)
        {
            if (node == null)
            {
                return;
            }

            if (node.Type == Node.StartTag || node.Type == Node.StartEndTag)
            {
                if (_currIndex <= _maxIndex && (_tagName.Equals("*") || _tagName.Equals(node.Element)))
                {
                    _currIndex += 1;
                    _currNode = node;
                }
            }
            if (_currIndex > _maxIndex)
            {
                return;
            }

            node = node.Content;
            while (node != null)
            {
                PreTraverse(node);
                node = node.Next;
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            Attribute attribute;
            bool hasAlt = false;
            bool hasHref = false;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                attribute = attval.CheckAttribute(lexer, node);

                if (attribute == AttributeTable.AttrAlt)
                {
                    hasAlt = true;
                }
                else if (attribute == AttributeTable.AttrHref)
                {
                    hasHref = true;
                }
            }

            if (!hasAlt)
            {
                lexer.badAccess |= Report.MISSING_LINK_ALT;
                Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
            }
            if (!hasHref)
            {
                Report.AttrError(lexer, node, "href", Report.MISSING_ATTRIBUTE);
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            string val = null;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                if (String.Compare(attval.Attribute, "align") == 0)
                {
                    val = attval.Val;
                    break;
                }
            }

            if (val != null)
            {
                if (String.Compare(val, "left") == 0 || String.Compare(val, "right") == 0)
                {
                    lexer.versions &= HtmlVersion.Html40Loose | HtmlVersion.Frames;
                }
                else if (String.Compare(val, "top") == 0 || String.Compare(val, "bottom") == 0)
                {
                    lexer.versions &= HtmlVersion.From32;
                }
                else
                {
                    Report.AttrError(lexer, node, val, Report.BAD_ATTRIBUTE_VALUE);
                }
            }
        }
 public virtual void Check(Lexer lexer, Node node)
 {
     if (node.GetAttrByName("src") != null)
     {
         Report.AttrError(lexer, node, "src", Report.PROPRIETARY_ATTR_VALUE);
     }
 }
示例#6
0
        public virtual void Check(Lexer lexer, Node node, AttVal attval)
        {
            string val = attval.Val;

            if (val == null)
            {
                Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE);
            }
            else if (String.Compare(val, "top") == 0 || String.Compare(val, "middle") == 0 || String.Compare(val, "bottom") == 0 || String.Compare(val, "baseline") == 0)
            {
                /* all is fine */
            }
            else if (String.Compare(val, "left") == 0 || String.Compare(val, "right") == 0)
            {
                if (!(node.Tag != null && ((node.Tag.Model & ContentModel.Img) != 0)))
                {
                    Report.AttrError(lexer, node, val, Report.BAD_ATTRIBUTE_VALUE);
                }
            }
            else if (String.Compare(val, "texttop") == 0 || String.Compare(val, "absmiddle") == 0 || String.Compare(val, "absbottom") == 0 || String.Compare(val, "textbottom") == 0)
            {
                lexer.versions &= HtmlVersion.Proprietary;
                Report.AttrError(lexer, node, val, Report.PROPRIETARY_ATTR_VALUE);
            }
            else
            {
                Report.AttrError(lexer, node, val, Report.BAD_ATTRIBUTE_VALUE);
            }
        }
示例#7
0
 public AttVal(AttVal next, Attribute dict, int delim, string attribute, string val)
 {
     _next = next;
     _dict = dict;
     _asp = null;
     _php = null;
     _delim = delim;
     _attribute = attribute;
     _val = val;
 }
示例#8
0
 public AttVal(AttVal next, Attribute dict, Node asp, Node php, int delim, string attribute, string val)
 {
     _next = next;
     _dict = dict;
     _asp = asp;
     _php = php;
     _delim = delim;
     _attribute = attribute;
     _val = val;
 }
示例#9
0
 public AttVal()
 {
     _next = null;
     _dict = null;
     _asp = null;
     _php = null;
     _delim = 0;
     _attribute = null;
     _val = null;
 }
示例#10
0
 public virtual void Check(Lexer lexer, Node node, AttVal attval)
 {
     if (attval.Val == null)
     {
         Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE);
     }
     else if (lexer.Options.FixBackslash)
     {
         attval.Val = attval.Val.Replace('\\', '/');
     }
 }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal type = node.GetAttrByName("type");

            node.CheckUniqueAttributes(lexer);

            if (type == null)
            {
                Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);

                node.AddAttribute("type", "text/css");
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            node.CheckUniqueAttributes(lexer);

            /*
                HTML4 strict doesn't allow mixed content for
                elements with %block; as their content model
                */
            if (node.GetAttrByName("width") != null || node.GetAttrByName("height") != null)
            {
                lexer.versions &= ~ HtmlVersion.Html40Strict;
            }
        }
示例#13
0
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                Attribute attribute = attval.CheckAttribute(lexer, node);
                if (attribute == AttributeTable.AttrXmlns)
                {
                    lexer.isvoyager = true;
                }
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal rel = node.GetAttrByName("rel");

            node.CheckUniqueAttributes(lexer);

            if (rel != null && rel.Val != null && rel.Val.Equals("stylesheet"))
            {
                AttVal type = node.GetAttrByName("type");

                if (type == null)
                {
                    Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);

                    node.AddAttribute("type", "text/css");
                }
            }
        }
示例#15
0
        public virtual void Check(Lexer lexer, Node node, AttVal attval)
        {
            string val;

            /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
            if (node.Tag != null && ((node.Tag.Model & ContentModel.Img) != 0))
            {
                TidyNet.AttrCheckImpl.CheckValign.Check(lexer, node, attval);
                return;
            }

            val = attval.Val;

            if (val == null)
            {
                Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE);
            }
            else if (!(String.Compare(val, "left") == 0 || String.Compare(val, "center") == 0 || String.Compare(val, "right") == 0 || String.Compare(val, "justify") == 0))
            {
                Report.AttrError(lexer, node, attval.Val, Report.BAD_ATTRIBUTE_VALUE);
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            Attribute attribute;
            bool hasSummary = false;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                attribute = attval.CheckAttribute(lexer, node);

                if (attribute == AttributeTable.AttrSummary)
                {
                    hasSummary = true;
                }
            }

            /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
            if (!hasSummary && lexer.doctype != HtmlVersion.Html20 && lexer.doctype != HtmlVersion.Html32)
            {
                lexer.badAccess |= Report.MISSING_SUMMARY;
                Report.AttrError(lexer, node, "summary", Report.MISSING_ATTRIBUTE);
            }

            /* convert <table border> to <table border="1"> */
            if (lexer.Options.XmlOut)
            {
                attval = node.GetAttrByName("border");
                if (attval != null)
                {
                    if (attval.Val == null)
                    {
                        attval.Val = "1";
                    }
                }
            }
        }
示例#17
0
        public static void AttrError(Lexer lexer, Node node, string attr, short code)
        {
            /* keep quiet after 6 errors */
            if (lexer.messages.Errors > 6)
            {
                return;
            }

            /* on end of file adjust reported position to end of input */
            if (code == UNEXPECTED_END_OF_FILE)
            {
                lexer.lines = lexer.input.curline;
                lexer.columns = lexer.input.curcol;
            }

            if (code == UNKNOWN_ATTRIBUTE)
            {
                AddMessage(lexer, String.Format(GetMessage("unknown_attribute"), attr), MessageLevel.Warning);
            }
            else if (code == MISSING_ATTRIBUTE)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_attribute"), Tag(lexer, node), attr), MessageLevel.Warning);
            }
            else if (code == MISSING_ATTR_VALUE)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_attr_value"), Tag(lexer, node), attr), MessageLevel.Warning);
            }
            else if (code == MISSING_IMAGEMAP)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_imagemap"), Tag(lexer, node)), MessageLevel.Warning);

                lexer.badAccess |= MISSING_IMAGE_MAP;
            }
            else if (code == BAD_ATTRIBUTE_VALUE)
            {
                AddMessage(lexer, String.Format(GetMessage("bad_attribute_value"), Tag(lexer, node), attr), MessageLevel.Warning);
            }
            else if (code == XML_ATTRIBUTE_VALUE)
            {
                AddMessage(lexer, String.Format(GetMessage("xml_attribute_value"), Tag(lexer, node), attr), MessageLevel.Warning);
            }
            else if (code == UNEXPECTED_GT)
            {
                AddMessage(lexer, String.Format(GetMessage("unexpected_gt"), Tag(lexer, node)), MessageLevel.Error);
            }
            else if (code == UNEXPECTED_QUOTEMARK)
            {
                AddMessage(lexer, String.Format(GetMessage("unexpected_quotemark"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == REPEATED_ATTRIBUTE)
            {
                AddMessage(lexer, String.Format(GetMessage("repeated_attribute"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == PROPRIETARY_ATTR_VALUE)
            {
                AddMessage(lexer, String.Format(GetMessage("proprietary_attr_value"), Tag(lexer, node), attr), MessageLevel.Warning);
            }
            else if (code == UNEXPECTED_END_OF_FILE)
            {
                AddMessage(lexer, GetMessage("unexpected_end_of_file"), MessageLevel.Error);
            }
            else if (code == ID_NAME_MISMATCH)
            {
                AddMessage(lexer, String.Format(GetMessage("id_name_mismatch"), Tag(lexer, node)), MessageLevel.Warning);
            }

            if (code == UNEXPECTED_GT)
            {
                AddMessage(lexer, String.Format(GetMessage("unexpected_gt"), Tag(lexer, node)), MessageLevel.Error);
            }
        }
示例#18
0
        /* public method for finding tag by name */
        public bool FindTag(Node node)
        {
            Dict np;

            if (Options != null && Options.XmlTags)
            {
                node.Tag = XmlTags;
                return true;
            }

            if (node.Element != null)
            {
                np = Lookup(node.Element);
                if (np != null)
                {
                    node.Tag = np;
                    return true;
                }
            }

            return false;
        }
示例#19
0
        public IParser FindParser(Node node)
        {
            Dict np;

            if (node.Element != null)
            {
                np = Lookup(node.Element);
                if (np != null)
                {
                    return np.Parser;
                }
            }

            return null;
        }
示例#20
0
 protected internal DomNodeImpl(Node adaptee)
 {
     _adaptee = adaptee;
 }
示例#21
0
        public static void Warning(Lexer lexer, Node element, Node node, short code)
        {
            TagTable tt = lexer.Options.tt;

            /* keep quiet after 6 errors */
            if (lexer.messages.Errors > 6)
            {
                return;
            }

            /* on end of file adjust reported position to end of input */
            if (code == UNEXPECTED_END_OF_FILE)
            {
                lexer.lines = lexer.input.curline;
                lexer.columns = lexer.input.curcol;
            }

            if (code == MISSING_ENDTAG_FOR)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_endtag_for"), element.Element), MessageLevel.Warning);
            }
            else if (code == MISSING_ENDTAG_BEFORE)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_endtag_before"), element.Element, Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == DISCARDING_UNEXPECTED)
            {
                AddMessage(lexer, String.Format(GetMessage("discarding_unexpected"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == NESTED_EMPHASIS)
            {
                AddMessage(lexer, String.Format(GetMessage("nested_emphasis"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == COERCE_TO_ENDTAG)
            {
                AddMessage(lexer, String.Format(GetMessage("coerce_to_endtag"), element.Element), MessageLevel.Warning);
            }
            else if (code == NON_MATCHING_ENDTAG)
            {
                AddMessage(lexer, String.Format(GetMessage("non_matching_endtag_1"), Tag(lexer, node), element.Element), MessageLevel.Warning);
            }
            else if (code == TAG_NOT_ALLOWED_IN)
            {
                AddMessage(lexer, String.Format(GetMessage("tag_not_allowed_in"), Tag(lexer, node), element.Element), MessageLevel.Warning);
            }
            else if (code == DOCTYPE_AFTER_TAGS)
            {
                AddMessage(lexer, GetMessage("doctype_after_tags"), MessageLevel.Warning);
            }
            else if (code == MISSING_STARTTAG)
            {
                AddMessage(lexer, String.Format(GetMessage("missing_starttag"), node.Element), MessageLevel.Warning);
            }
            else if (code == UNEXPECTED_ENDTAG)
            {
                string message;
                if (element != null)
                {
                    message = String.Format(GetMessage("unexpected_endtag_suffix"), node.Element, element.Element);
                }
                else
                {
                    message = String.Format(GetMessage("unexpected_endtag"), node.Element);
                }

                AddMessage(lexer, message, MessageLevel.Warning);
            }
            else if (code == TOO_MANY_ELEMENTS)
            {
                string message;
                if (element != null)
                {
                    message = String.Format(GetMessage("too_many_elements_suffix"), node.Element, element.Element);
                }
                else
                {
                    message = String.Format(GetMessage("too_many_elements"), node.Element);
                }

                AddMessage(lexer, message, MessageLevel.Warning);
            }
            else if (code == USING_BR_INPLACE_OF)
            {
                AddMessage(lexer, GetMessage("using_br_inplace_of") + Tag(lexer, node), MessageLevel.Warning);
            }
            else if (code == INSERTING_TAG)
            {
                AddMessage(lexer, String.Format(GetMessage("inserting_tag"), node.Element), MessageLevel.Warning);
            }
            else if (code == CANT_BE_NESTED)
            {
                AddMessage(lexer, String.Format(GetMessage("cant_be_nested"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == PROPRIETARY_ELEMENT)
            {
                AddMessage(lexer, String.Format(GetMessage("proprietary_element"), Tag(lexer, node)), MessageLevel.Warning);

                if (node.Tag == tt.TagLayer)
                {
                    lexer.badLayout |= USING_LAYER;
                }
                else if (node.Tag == tt.TagSpacer)
                {
                    lexer.badLayout |= USING_SPACER;
                }
                else if (node.Tag == tt.TagNobr)
                {
                    lexer.badLayout |= USING_NOBR;
                }
            }
            else if (code == OBSOLETE_ELEMENT)
            {
                string message;
                if (element.Tag != null && (element.Tag.Model & ContentModel.Obsolete) != 0)
                {
                    message = String.Format(GetMessage("obsolete_element"), Tag(lexer, node), Tag(lexer, node));
                }
                else
                {
                    message = String.Format(GetMessage("replacing_element"), Tag(lexer, node), Tag(lexer, node));
                }

                AddMessage(lexer, message, MessageLevel.Warning);
            }
            else if (code == TRIM_EMPTY_ELEMENT)
            {
                AddMessage(lexer, String.Format(GetMessage("trim_empty_element"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == MISSING_TITLE_ELEMENT)
            {
                AddMessage(lexer, GetMessage("missing_title_element"), MessageLevel.Warning);
            }
            else if (code == ILLEGAL_NESTING)
            {
                AddMessage(lexer, String.Format(GetMessage("illegal_nesting"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == NOFRAMES_CONTENT)
            {
                AddMessage(lexer, String.Format(GetMessage("noframes_content"), Tag(lexer, node)), MessageLevel.Warning);
            }
            else if (code == INCONSISTENT_VERSION)
            {
                AddMessage(lexer, GetMessage("inconsistent_version"), MessageLevel.Warning);
            }
            else if (code == MALFORMED_DOCTYPE)
            {
                AddMessage(lexer, GetMessage("malformed_doctype"), MessageLevel.Warning);
            }
            else if (code == CONTENT_AFTER_BODY)
            {
                AddMessage(lexer, GetMessage("content_after_body"), MessageLevel.Warning);
            }
            else if (code == MALFORMED_COMMENT)
            {
                AddMessage(lexer, GetMessage("malformed_comment"), MessageLevel.Warning);
            }
            else if (code == BAD_COMMENT_CHARS)
            {
                AddMessage(lexer, GetMessage("bad_comment_chars"), MessageLevel.Warning);
            }
            else if (code == BAD_XML_COMMENT)
            {
                AddMessage(lexer, GetMessage("bad_xml_comment"), MessageLevel.Warning);
            }
            else if (code == BAD_CDATA_CONTENT)
            {
                AddMessage(lexer, GetMessage("bad_cdata_content"), MessageLevel.Warning);
            }
            else if (code == INCONSISTENT_NAMESPACE)
            {
                AddMessage(lexer, GetMessage("inconsistent_namespace"), MessageLevel.Warning);
            }
            else if (code == DTYPE_NOT_UPPER_CASE)
            {
                AddMessage(lexer, GetMessage("dtype_not_upper_case"), MessageLevel.Warning);
            }
            else if (code == UNEXPECTED_END_OF_FILE)
            {
                AddMessage(lexer, GetMessage("unexpected_end_of_file") + Tag(lexer, node), MessageLevel.Warning);
            }
        }
示例#22
0
        public static void Error(Lexer lexer, Node element, Node node, short code)
        {
            /* keep quiet after 6 errors */
            if (lexer.messages.Errors > 6)
            {
                return;
            }

            if (code == SUSPECTED_MISSING_QUOTE)
            {
                AddMessage(lexer, GetMessage("suspected_missing_quote"), MessageLevel.Error);
            }
            else if (code == DUPLICATE_FRAMESET)
            {
                AddMessage(lexer, GetMessage("duplicate_frameset"), MessageLevel.Error);
            }
            else if (code == UNKNOWN_ELEMENT)
            {
                AddMessage(lexer, String.Format(GetMessage("unknown_element"), Tag(lexer, node)), MessageLevel.Error);
            }
            else if (code == UNEXPECTED_ENDTAG)
            {
                string message;
                if (element != null)
                {
                    message = String.Format(GetMessage("unexpected_endtag_suffix"), element.Element);
                }
                else
                {
                    message = String.Format(GetMessage("unexpected_endtag"), node.Element, element.Element);
                }

                AddMessage(lexer, message, MessageLevel.Error);
            }
        }
示例#23
0
        /*
        the same attribute name can't be used
        more than once in each element
        */
        public virtual void CheckUniqueAttribute(Lexer lexer, Node node)
        {
            AttVal attr;
            int count = 0;

            for (attr = Next; attr != null; attr = attr.Next)
            {
                if (Attribute != null && attr.Attribute != null && attr.Asp == null && attr.Php == null && String.Compare(Attribute, attr.Attribute) == 0)
                {
                    ++count;
                }
            }

            if (count > 0)
            {
                Report.AttrError(lexer, node, Attribute, Report.REPEATED_ATTRIBUTE);
            }
        }
示例#24
0
        /* ignore unknown attributes for proprietary elements */
        public virtual Attribute CheckAttribute(Lexer lexer, Node node)
        {
            TagTable tt = lexer.Options.tt;

            if (Asp == null && Php == null)
            {
                CheckUniqueAttribute(lexer, node);
            }

            Attribute attribute = Dict;
            if (attribute != null)
            {
                /* title is vers 2.0 for A and LINK otherwise vers 4.0 */
                if (attribute == AttributeTable.AttrTitle && (node.Tag == tt.TagA || node.Tag == tt.TagLink))
                {
                    lexer.versions &= HtmlVersion.All;
                }
                else if ((attribute.Versions & HtmlVersion.Xml) != 0)
                {
                    if (!(lexer.Options.XmlTags || lexer.Options.XmlOut))
                    {
                        Report.AttrError(lexer, node, Attribute, Report.XML_ATTRIBUTE_VALUE);
                    }
                }
                else
                {
                    lexer.versions &= attribute.Versions;
                }

                if (attribute.AttrCheck != null)
                {
                    attribute.AttrCheck.Check(lexer, node, this);
                }
            }
            else if (!lexer.Options.XmlTags && !(node.Tag == null) && _asp == null && !(node.Tag != null && ((node.Tag.Versions & HtmlVersion.Proprietary) != HtmlVersion.Unknown)))
            {
                Report.AttrError(lexer, node, Attribute, Report.UNKNOWN_ATTRIBUTE);
            }

            return attribute;
        }
示例#25
0
文件: Clean.cs 项目: AlfieJ/TidyNet
        /*
        Replace implicit blockquote by div with an indent
        taking care to reduce nested blockquotes to a single
        div with the indent set to match the nesting depth
        */
        public virtual void BQ2Div(Node node)
        {
            int indent;
            string indent_buf;

            while (node != null)
            {
                if (node.Tag == _tt.TagBlockquote && node.Isimplicit)
                {
                    indent = 1;

                    while (node.HasOneChild() && node.Content.Tag == _tt.TagBlockquote && node.Isimplicit)
                    {
                        ++indent;
                        StripOnlyChild(node);
                    }

                    if (node.Content != null)
                    {
                        BQ2Div(node.Content);
                    }

                    indent_buf = "margin-left: " + (2 * indent).ToString() + "em";

                    node.Element = _tt.TagDiv.Name;
                    node.Tag = _tt.TagDiv;
                    node.AddAttribute("style", indent_buf);
                }
                else if (node.Content != null)
                {
                    BQ2Div(node.Content);
                }

                node = node.Next;
            }
        }
示例#26
0
文件: Clean.cs 项目: AlfieJ/TidyNet
        /*
        Applies all matching rules to a node.
        */
        private Node CleanNode(Lexer lexer, Node node)
        {
            Node next = null;
            MutableObject o = new MutableObject();
            bool b = false;

            for (next = node; node.IsElement; node = next)
            {
                o.Object = next;

                b = Dir2Div(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = NestedList(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = Center2Div(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = MergeDivs(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = BlockStyle(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = InlineStyle(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                b = Font2Span(lexer, node, o);
                next = (Node) o.Object;
                if (b)
                {
                    continue;
                }

                break;
            }

            return next;
        }
示例#27
0
 protected internal DomNodeListImpl(Node parent)
 {
     _parent = parent;
 }
示例#28
0
        public static void ReportVersion(Lexer lexer, Node doctype)
        {
            int i, c;
            int state = 0;
            string vers = lexer.HtmlVersionName();
            MutableInteger cc = new MutableInteger();
            StringBuilder message = new StringBuilder();

            if (doctype != null)
            {
                StringBuilder docTypeStr = new StringBuilder();

                for (i = doctype.Start; i < doctype.End; ++i)
                {
                    c = (int) doctype.Textarray[i];

                    /* look for UTF-8 multibyte character */
                    if (c < 0)
                    {
                        i += PPrint.GetUTF8(doctype.Textarray, i, cc);
                        c = cc.Val;
                    }

                    if (c == (char) '"')
                    {
                        ++state;
                    }
                    else if (state == 1)
                    {
                        docTypeStr.Append((char)c);
                    }
                }

                lexer.messages.Add(new TidyMessage(lexer, String.Format(GetMessage("doctype_given"), docTypeStr), MessageLevel.Info));
            }

            lexer.messages.Add(new TidyMessage(lexer, String.Format(GetMessage("report_version"), (vers != null ? vers : "HTML proprietary")), MessageLevel.Info));
        }
示例#29
0
文件: Clean.cs 项目: AlfieJ/TidyNet
        /*
        Symptom: <center>
        Action: replace <center> by <div style="text-align: center">
        */
        private bool Center2Div(Lexer lexer, Node node, MutableObject pnode)
        {
            if (node.Tag == _tt.TagCenter)
            {
                if (lexer.Options.DropFontTags)
                {
                    if (node.Content != null)
                    {
                        Node last = node.Last;
                        Node parent = node.Parent;

                        DiscardContainer(node, pnode);

                        node = lexer.InferredTag("br");

                        if (last.Next != null)
                        {
                            last.Next.Prev = node;
                        }

                        node.Next = last.Next;
                        last.Next = node;
                        node.Prev = last;

                        if (parent.Last == last)
                        {
                            parent.Last = node;
                        }

                        node.Parent = parent;
                    }
                    else
                    {
                        Node prev = node.Prev;
                        Node next = node.Next;
                        Node parent = node.Parent;
                        DiscardContainer(node, pnode);

                        node = lexer.InferredTag("br");
                        node.Next = next;
                        node.Prev = prev;
                        node.Parent = parent;

                        if (next != null)
                        {
                            next.Prev = node;
                        }
                        else
                        {
                            parent.Last = node;
                        }

                        if (prev != null)
                        {
                            prev.Next = node;
                        }
                        else
                        {
                            parent.Content = node;
                        }
                    }

                    return true;
                }
                node.Tag = _tt.TagDiv;
                node.Element = "div";
                AddStyleProperty(node, "text-align: center");
                return true;
            }

            return false;
        }
示例#30
0
 private static string Tag(Lexer lexer, Node tag)
 {
     if (tag != null)
     {
         if (tag.Type == Node.StartTag)
         {
             return "<" + tag.Element + ">";
         }
         else if (tag.Type == Node.EndTag)
         {
             return "</" + tag.Element + ">";
         }
         else if (tag.Type == Node.DocTypeTag)
         {
             return "<!DOCTYPE>";
         }
         else if (tag.Type == Node.TextNode)
         {
             return "plain text";
         }
         else
         {
             return tag.Element;
         }
     }
     else
     {
         return String.Empty;
     }
 }
示例#31
0
文件: Clean.cs 项目: AlfieJ/TidyNet
        /*
        move presentation attribs from body to style element

        background="foo" ->  body { background-image: url(foo) }
        bgcolor="foo"    ->  body { background-color: foo }
        text="foo"       ->  body { color: foo }
        link="foo"       ->  :link { color: foo }
        vlink="foo"      ->  :visited { color: foo }
        alink="foo"      ->  :active { color: foo }
        */
        private void CleanBodyAttrs(Lexer lexer, Node body)
        {
            AttVal attr;
            string bgurl = null;
            string bgcolor = null;
            string color = null;

            attr = body.GetAttrByName("background");

            if (attr != null)
            {
                bgurl = attr.Val;
                attr.Val = null;
                body.RemoveAttribute(attr);
            }

            attr = body.GetAttrByName("bgcolor");

            if (attr != null)
            {
                bgcolor = attr.Val;
                attr.Val = null;
                body.RemoveAttribute(attr);
            }

            attr = body.GetAttrByName("text");

            if (attr != null)
            {
                color = attr.Val;
                attr.Val = null;
                body.RemoveAttribute(attr);
            }

            if (bgurl != null || bgcolor != null || color != null)
            {
                lexer.AddStringLiteral(" body {\n");

                if (bgurl != null)
                {
                    lexer.AddStringLiteral("  background-image: url(");
                    lexer.AddStringLiteral(bgurl);
                    lexer.AddStringLiteral(");\n");
                }

                if (bgcolor != null)
                {
                    lexer.AddStringLiteral("  background-color: ");
                    lexer.AddStringLiteral(bgcolor);
                    lexer.AddStringLiteral(";\n");
                }

                if (color != null)
                {
                    lexer.AddStringLiteral("  color: ");
                    lexer.AddStringLiteral(color);
                    lexer.AddStringLiteral(";\n");
                }

                lexer.AddStringLiteral(" }\n");
            }

            attr = body.GetAttrByName("link");

            if (attr != null)
            {
                AddColorRule(lexer, " :link", attr.Val);
                body.RemoveAttribute(attr);
            }

            attr = body.GetAttrByName("vlink");

            if (attr != null)
            {
                AddColorRule(lexer, " :visited", attr.Val);
                body.RemoveAttribute(attr);
            }

            attr = body.GetAttrByName("alink");

            if (attr != null)
            {
                AddColorRule(lexer, " :active", attr.Val);
                body.RemoveAttribute(attr);
            }
        }