Attribute/Value linked list node (c) 1998-2000 (W3C) MIT, INRIA, Keio University See Tidy.cs for the copyright notice. Derived from HTML Tidy Release 4 Aug 2000
コード例 #1
0
        public virtual void RemoveAttribute(string name)
        {
            if (Adaptee == null)
            {
                return;
            }

            AttVal att = Adaptee.Attributes;
            AttVal pre = null;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                pre = att;
                att = att.Next;
            }
            if (att != null)
            {
                if (pre == null)
                {
                    Adaptee.Attributes = att.Next;
                }
                else
                {
                    pre.Next = att.Next;
                }
            }
        }
コード例 #2
0
ファイル: AttVal.cs プロジェクト: zeit200/TidyNetstandard
        public object Clone()
        {
            var av = new AttVal();

            if (Next != null)
            {
                av.Next = (AttVal)Next.Clone();
            }
            if (Attribute != null)
            {
                av.Attribute = Attribute;
            }
            if (Val != null)
            {
                av.Val = Val;
            }
            av.Delim = Delim;
            if (Asp != null)
            {
                av.Asp = (Node)Asp.Clone();
            }
            if (Php != null)
            {
                av.Php = (Node)Php.Clone();
            }
            av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(this);
            return(av);
        }
コード例 #3
0
        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.CompareOrdinal(str, "javascript") == 0) || (String.CompareOrdinal(str, "jscript") == 0))
                    {
                        node.AddAttribute("type", "text/javascript");
                    }
                }
                else
                {
                    node.AddAttribute("type", "text/javascript");
                }
            }
        }
コード例 #4
0
        public virtual IAttr CreateAttribute(string name)
        {
            var av = new AttVal(null, null, '"', name, null);

            av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
            return(av.Adapter);
        }
コード例 #5
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.CompareOrdinal(val, "top") == 0 || String.CompareOrdinal(val, "middle") == 0 ||
                     String.CompareOrdinal(val, "bottom") == 0 || String.CompareOrdinal(val, "baseline") == 0)
            {
                /* all is fine */
            }
            else if (String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(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.CompareOrdinal(val, "texttop") == 0 || String.CompareOrdinal(val, "absmiddle") == 0 ||
                     String.CompareOrdinal(val, "absbottom") == 0 || String.CompareOrdinal(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);
            }
        }
コード例 #6
0
        /* remove attribute from node then free it */

        public virtual void RemoveAttribute(AttVal attr)
        {
            AttVal av;
            AttVal prev = null;
            AttVal next;

            for (av = Attributes; av != null; av = next)
            {
                next = av.Next;

                if (av == attr)
                {
                    if (prev != null)
                    {
                        prev.Next = next;
                    }
                    else
                    {
                        Attributes = next;
                    }
                }
                else
                {
                    prev = av;
                }
            }
        }
コード例 #7
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.CompareOrdinal(val, "top") == 0 || String.CompareOrdinal(val, "middle") == 0 ||
                     String.CompareOrdinal(val, "bottom") == 0 || String.CompareOrdinal(val, "baseline") == 0)
            {
                /* all is fine */
            }
            else if (String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(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.CompareOrdinal(val, "texttop") == 0 || String.CompareOrdinal(val, "absmiddle") == 0 ||
                     String.CompareOrdinal(val, "absbottom") == 0 || String.CompareOrdinal(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);
            }
        }
コード例 #8
0
ファイル: AttVal.cs プロジェクト: zeit200/TidyNetstandard
 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;
 }
コード例 #9
0
ファイル: AttVal.cs プロジェクト: zeit200/TidyNetstandard
 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;
 }
コード例 #10
0
ファイル: AttVal.cs プロジェクト: r1pper/TidyNetPortable
 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;
 }
コード例 #11
0
ファイル: AttVal.cs プロジェクト: r1pper/TidyNetPortable
 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;
 }
コード例 #12
0
        public virtual Attribute FindAttribute(AttVal attval)
        {
            if (attval.Attribute != null)
            {
                Attribute np = Lookup(attval.Attribute);
                return(np);
            }

            return(null);
        }
コード例 #13
0
        public virtual INode GetNamedItem(string name)
        {
            AttVal att = _first;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }

            return(att != null ? att.Adapter : null);
        }
コード例 #14
0
        public virtual INode Item(int index)
        {
            int    i   = 0;
            AttVal att = _first;

            while (att != null)
            {
                if (i >= index)
                {
                    break;
                }
                i++;
                att = att.Next;
            }

            return(att != null ? att.Adapter : null);
        }
コード例 #15
0
        public virtual IAttr SetAttributeNode(IAttr newAttr)
        {
            if (newAttr == null)
            {
                return(null);
            }

            if (!(newAttr is DomAttrImpl))
            {
                throw new DomException(DomException.WRONG_DOCUMENT, "newAttr not instanceof DomAttrImpl");
            }

            var    newatt = (DomAttrImpl)newAttr;
            string name   = newatt.AttValAdaptee.Attribute;
            IAttr  result = null;

            AttVal att = Adaptee.Attributes;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            if (att != null)
            {
                result      = att.Adapter;
                att.Adapter = newAttr;
            }
            else
            {
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = newatt.AttValAdaptee;
                }
                else
                {
                    newatt.AttValAdaptee.Next = Adaptee.Attributes;
                    Adaptee.Attributes        = newatt.AttValAdaptee;
                }
            }
            return(result);
        }
コード例 #16
0
        public static void AddClass(Node node, string classname)
        {
            AttVal classattr = node.GetAttrByName("class");

            /*
             *          if there already is a class attribute
             *          then append class name after a space
             */
            if (classattr != null)
            {
                classattr.Val = classattr.Val + " " + classname;
            }
            /* create new class attribute */
            else
            {
                node.AddAttribute("class", classname);
            }
        }
コード例 #17
0
        public virtual IAttr GetAttributeNode(string name)
        {
            if (Adaptee == null)
            {
                return(null);
            }

            AttVal att = Adaptee.Attributes;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            return(att != null ? att.Adapter : null);
        }
コード例 #18
0
        public virtual string GetAttribute(string name)
        {
            if (Adaptee == null)
            {
                return(null);
            }

            AttVal att = Adaptee.Attributes;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            return(att != null ? att.Val : String.Empty);
        }
コード例 #19
0
        public virtual void Check(Lexer lexer, Node node, AttVal attval)
        {
            /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
            if (node.Tag != null && ((node.Tag.Model & ContentModel.IMG) != 0))
            {
                AttrCheckImpl.CheckValign.Check(lexer, node, attval);
                return;
            }

            string val = attval.Val;

            if (val == null)
            {
                Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE);
            }
            else if (
                !(String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(val, "center") == 0 ||
                  String.CompareOrdinal(val, "right") == 0 || String.CompareOrdinal(val, "justify") == 0))
            {
                Report.AttrError(lexer, node, attval.Val, Report.BAD_ATTRIBUTE_VALUE);
            }
        }
コード例 #20
0
        public virtual void Check(Lexer lexer, Node node, AttVal attval)
        {
            /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
            if (node.Tag != null && ((node.Tag.Model & ContentModel.IMG) != 0))
            {
                AttrCheckImpl.CheckValign.Check(lexer, node, attval);
                return;
            }

            string val = attval.Val;

            if (val == null)
            {
                Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE);
            }
            else if (
                !(String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(val, "center") == 0 ||
                  String.CompareOrdinal(val, "right") == 0 || String.CompareOrdinal(val, "justify") == 0))
            {
                Report.AttrError(lexer, node, attval.Val, Report.BAD_ATTRIBUTE_VALUE);
            }
        }
コード例 #21
0
        public virtual IAttr RemoveAttributeNode(IAttr oldAttr)
        {
            if (oldAttr == null)
            {
                return(null);
            }

            IAttr  result;
            AttVal att = Adaptee.Attributes;
            AttVal pre = null;

            while (att != null)
            {
                if (att.Adapter == oldAttr)
                {
                    break;
                }
                pre = att;
                att = att.Next;
            }
            if (att != null)
            {
                if (pre == null)
                {
                    Adaptee.Attributes = att.Next;
                }
                else
                {
                    pre.Next = att.Next;
                }
                result = oldAttr;
            }
            else
            {
                throw new DomException(DomException.NOT_FOUND, "oldAttr not found");
            }
            return(result);
        }
コード例 #22
0
        public virtual void AddAttribute(string name, string val)
        {
            var av = new AttVal(null, null, null, null, '"', name, val);

            av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);

            if (Attributes == null)
            {
                Attributes = av;
                /* append to end of attributes */
            }
            else
            {
                AttVal here = Attributes;

                while (here.Next != null)
                {
                    here = here.Next;
                }

                here.Next = av;
            }
        }
コード例 #23
0
        public virtual void SetAttribute(string name, string val)
        {
            if (Adaptee == null)
            {
                return;
            }

            AttVal att = Adaptee.Attributes;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            if (att != null)
            {
                att.Val = val;
            }
            else
            {
                att      = new AttVal(null, null, '"', name, val);
                att.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(att);
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = att;
                }
                else
                {
                    att.Next           = Adaptee.Attributes;
                    Adaptee.Attributes = att;
                }
            }
        }
コード例 #24
0
ファイル: DomAttrImpl.cs プロジェクト: r1pper/TidyNetPortable
 protected internal DomAttrImpl(AttVal adaptee)
     : base(null)
 {
     _attValAdaptee = adaptee;
 }
コード例 #25
0
 public virtual IAttr CreateAttribute(string name)
 {
     var av = new AttVal(null, null, '"', name, null);
     av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
     return av.Adapter;
 }
コード例 #26
0
ファイル: Lexer.cs プロジェクト: r1pper/TidyNetPortable
 public virtual AttVal CloneAttributes(AttVal attrs)
 {
     var cattrs = (AttVal) attrs.Clone();
     for (AttVal att = cattrs; att != null; att = att.Next)
     {
         if (att.Asp != null)
             _nodeList.Add(att.Asp);
         if (att.Php != null)
             _nodeList.Add(att.Php);
     }
     return cattrs;
 }
コード例 #27
0
ファイル: Lexer.cs プロジェクト: r1pper/TidyNetPortable
        public virtual void FixHtmlNameSpace(Node root, string profile)
        {
            Node node;

            //TODO:odd!
            for (node = root.Content; node != null && node.Tag != Options.TagTable.TagHtml; node = node.Next)
            {
            }

            if (node != null)
            {
                AttVal attr;
                for (attr = node.Attributes; attr != null; attr = attr.Next)
                {
                    if (attr.Attribute.Equals("xmlns"))
                    {
                        break;
                    }
                }

                if (attr != null)
                {
                    if (!attr.Val.Equals(profile))
                    {
                        Report.Warning(this, node, null, Report.INCONSISTENT_NAMESPACE);
                        attr.Val = profile;
                    }
                }
                else
                {
                    attr = new AttVal(node.Attributes, null, '"', "xmlns", profile);
                    attr.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(attr);
                    node.Attributes = attr;
                }
            }
        }
コード例 #28
0
        public virtual Attribute FindAttribute(AttVal attval)
        {
            if (attval.Attribute != null)
            {
                Attribute np = Lookup(attval.Attribute);
                return np;
            }

            return null;
        }
コード例 #29
0
ファイル: AttVal.cs プロジェクト: r1pper/TidyNetPortable
 public object Clone()
 {
     var av = new AttVal();
     if (Next != null)
     {
         av.Next = (AttVal) Next.Clone();
     }
     if (Attribute != null)
     {
         av.Attribute = Attribute;
     }
     if (Val != null)
     {
         av.Val = Val;
     }
     av.Delim = Delim;
     if (Asp != null)
     {
         av.Asp = (Node) Asp.Clone();
     }
     if (Php != null)
     {
         av.Php = (Node) Php.Clone();
     }
     av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(this);
     return av;
 }
コード例 #30
0
 protected internal DomAttrMapImpl(AttVal first)
 {
     _first = first;
 }
コード例 #31
0
ファイル: Clean.cs プロジェクト: r1pper/TidyNetPortable
        private void MergeStyles(Node node, Node child)
        {
            AttVal av;
            string s1, s2;

            for (s2 = null, av = child.Attributes; av != null; av = av.Next)
            {
                if (av.Attribute.Equals("style"))
                {
                    s2 = av.Val;
                    break;
                }
            }

            for (s1 = null, av = node.Attributes; av != null; av = av.Next)
            {
                if (av.Attribute.Equals("style"))
                {
                    s1 = av.Val;
                    break;
                }
            }

            if (s1 != null)
            {
                if (s2 != null)
                {
                    /* merge styles from both */
                    string style = MergeProperties(s1, s2);
                    av.Val = style;
                }
            }
            else if (s2 != null)
            {
                /* copy style of child */
                av = new AttVal(node.Attributes, null, '"', "style", s2);
                av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
                node.Attributes = av;
            }
        }
コード例 #32
0
ファイル: Clean.cs プロジェクト: r1pper/TidyNetPortable
        /*
        add style properties to node corresponding to
        the font face, size and color attributes
        */
        private void AddFontStyles(Node node, AttVal av)
        {
            while (av != null)
            {
                if (av.Attribute.Equals("face"))
                {
                    AddFontFace(node, av.Val);
                }
                else if (av.Attribute.Equals("size"))
                {
                    AddFontSize(node, av.Val);
                }
                else if (av.Attribute.Equals("color"))
                {
                    AddFontColor(node, av.Val);
                }

                av = av.Next;
            }
        }
コード例 #33
0
ファイル: Clean.cs プロジェクト: r1pper/TidyNetPortable
        /*
        Add style property to element, creating style
        attribute as needed and adding ; delimiter
        */
        private void AddStyleProperty(Node node, string property)
        {
            AttVal av;

            for (av = node.Attributes; av != null; av = av.Next)
            {
                if (av.Attribute.Equals("style"))
                {
                    break;
                }
            }

            /* if style attribute already exists then insert property */

            if (av != null)
            {
                string s = AddProperty(av.Val, property);
                av.Val = s;
            }
            else
            {
                /* else create new style attribute */
                av = new AttVal(node.Attributes, null, '"', "style", property);
                av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
                node.Attributes = av;
            }
        }
コード例 #34
0
        public virtual void SetAttribute(string name, string val)
        {
            if (Adaptee == null)
            {
                return;
            }

            AttVal att = Adaptee.Attributes;
            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            if (att != null)
            {
                att.Val = val;
            }
            else
            {
                att = new AttVal(null, null, '"', name, val);
                att.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(att);
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = att;
                }
                else
                {
                    att.Next = Adaptee.Attributes;
                    Adaptee.Attributes = att;
                }
            }
        }
コード例 #35
0
 protected internal DomAttrImpl(AttVal adaptee) : base(null)
 {
     _attValAdaptee = adaptee;
 }
コード例 #36
0
ファイル: PPrint.cs プロジェクト: r1pper/TidyNetPortable
        private void PrintAttrs(Out fout, int indent, Node node, AttVal attr)
        {
            if (attr != null)
            {
                if (attr.Next != null)
                {
                    PrintAttrs(fout, indent, node, attr.Next);
                }

                if (attr.Attribute != null)
                {
                    PrintAttribute(fout, indent, node, attr);
                }
                else if (attr.Asp != null)
                {
                    AddC(' ', _linelen++);
                    PrintAsp(fout, indent, attr.Asp);
                }
                else if (attr.Php != null)
                {
                    AddC(' ', _linelen++);
                    PrintPhp(fout, indent, attr.Php);
                }
            }

            /* add xml:space attribute to pre and other elements */
            if (_options.XmlOut && _options.XmlSpace && ParserImpl.XmlPreserveWhiteSpace(node, _options.TagTable) &&
                node.GetAttrByName("xml:space") == null)
            {
                PrintString(" xml:space=\"preserve\"");
            }
        }
コード例 #37
0
ファイル: PPrint.cs プロジェクト: r1pper/TidyNetPortable
        private void PrintAttribute(Out fout, int indent, Node node, AttVal attr)
        {
            bool wrappable = false;

            if (_options.IndentAttributes)
            {
                FlushLine(fout, indent);
                indent += _options.Spaces;
            }

            string name = attr.Attribute;

            if (indent + _linelen >= _options.WrapLen)
            {
                WrapLine(fout, indent);
            }

            if (!_options.XmlTags && !_options.XmlOut && attr.Dict != null)
            {
                if (AttributeTable.DefaultAttributeTable.IsScript(name))
                {
                    wrappable = _options.WrapScriptlets;
                }
                else if (!attr.Dict.Nowrap && _options.WrapAttVals)
                {
                    wrappable = true;
                }
            }

            if (indent + _linelen < _options.WrapLen)
            {
                _wraphere = _linelen;
                AddC(' ', _linelen++);
            }
            else
            {
                CondFlushLine(fout, indent);
                AddC(' ', _linelen++);
            }

            for (int i = 0; i < name.Length; i++)
            {
                AddC(Lexer.FoldCase(name[i], _options.UpperCaseAttrs, _options.XmlTags), _linelen++);
            }

            if (indent + _linelen >= _options.WrapLen)
            {
                WrapLine(fout, indent);
            }

            if (attr.Val == null)
            {
                if (_options.XmlTags || _options.XmlOut)
                {
                    PrintAttrValue(fout, indent, attr.Attribute, attr.Delim, true);
                }
                else if (!attr.BoolAttribute && !Node.IsNewNode(node))
                {
                    PrintAttrValue(fout, indent, "", attr.Delim, true);
                }
                else if (indent + _linelen < _options.WrapLen)
                {
                    _wraphere = _linelen;
                }
            }
            else
            {
                PrintAttrValue(fout, indent, attr.Val, attr.Delim, wrappable);
            }
        }
コード例 #38
0
ファイル: Lexer.cs プロジェクト: r1pper/TidyNetPortable
        /* swallows closing '>' */
        public virtual AttVal ParseAttrs(MutableBoolean isempty)
        {
            var delim = new MutableInteger();
            var asp = new MutableObject();
            var php = new MutableObject();

            AttVal list = null;

            while (!EndOfInput())
            {
                string attribute = ParseAttribute(isempty, asp, php);

                AttVal av;
                if (attribute == null)
                {
                    /* check if attributes are created by ASP markup */
                    if (asp.Object != null)
                    {
                        av = new AttVal(list, null, (Node) asp.Object, null, '\x0000', null, null);
                        list = av;
                        continue;
                    }

                    /* check if attributes are created by PHP markup */
                    if (php.Object != null)
                    {
                        av = new AttVal(list, null, null, (Node) php.Object, '\x0000', null, null);
                        list = av;
                        continue;
                    }

                    break;
                }

                string val = ParseValue(attribute, false, isempty, delim);

                if (IsValidAttrName(attribute))
                {
                    av = new AttVal(list, null, null, null, delim.Val, attribute, val);
                    av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
                    list = av;
                }
                else
                {
                    //av = new AttVal(null, null, null, null, 0, attribute, val);
                    Report.AttrError(this, Token, val, Report.BAD_ATTRIBUTE_VALUE);
                }
            }

            return list;
        }
コード例 #39
0
 protected internal DomAttrMapImpl(AttVal first)
 {
     _first = first;
 }
コード例 #40
0
ファイル: Clean.cs プロジェクト: r1pper/TidyNetPortable
        /* create style element using rules from dictionary */
        private void CreateStyleElement(Lexer lexer, Node doc)
        {
            Style style;

            if (lexer.Styles == null && NiceBody(lexer, doc))
            {
                return;
            }

            Node node = lexer.NewNode(Node.START_TAG, null, 0, 0, "style");
            node.Isimplicit = true;

            /* insert type attribute */
            var av = new AttVal(null, null, '"', "type", "text/css");
            av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
            node.Attributes = av;

            Node body = doc.FindBody(lexer.Options.TagTable);

            lexer.Txtstart = lexer.Lexsize;

            if (body != null)
            {
                CleanBodyAttrs(lexer, body);
            }

            for (style = lexer.Styles; style != null; style = style.Next)
            {
                lexer.AddCharToLexer(' ');
                lexer.AddStringLiteral(style.Tag);
                lexer.AddCharToLexer('.');
                lexer.AddStringLiteral(style.TagClass);
                lexer.AddCharToLexer(' ');
                lexer.AddCharToLexer('{');
                lexer.AddStringLiteral(style.Properties);
                lexer.AddCharToLexer('}');
                lexer.AddCharToLexer('\n');
            }

            lexer.Txtend = lexer.Lexsize;

            Node.InsertNodeAtEnd(node, lexer.NewNode(Node.TEXT_NODE, lexer.Lexbuf, lexer.Txtstart, lexer.Txtend));

            /*
            now insert style element into document head

            doc is root node. search its children for html node
            the head node should be first child of html node
            */

            Node head = doc.FindHead(lexer.Options.TagTable);

            if (head != null)
            {
                Node.InsertNodeAtEnd(head, node);
            }
        }
コード例 #41
0
ファイル: Node.cs プロジェクト: r1pper/TidyNetPortable
        public virtual void AddAttribute(string name, string val)
        {
            var av = new AttVal(null, null, null, null, '"', name, val);
            av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);

            if (Attributes == null)
            {
                Attributes = av;
                /* append to end of attributes */
            }
            else
            {
                AttVal here = Attributes;

                while (here.Next != null)
                {
                    here = here.Next;
                }

                here.Next = av;
            }
        }
コード例 #42
0
ファイル: Node.cs プロジェクト: r1pper/TidyNetPortable
        /* remove attribute from node then free it */
        public virtual void RemoveAttribute(AttVal attr)
        {
            AttVal av;
            AttVal prev = null;
            AttVal next;

            for (av = Attributes; av != null; av = next)
            {
                next = av.Next;

                if (av == attr)
                {
                    if (prev != null)
                    {
                        prev.Next = next;
                    }
                    else
                    {
                        Attributes = next;
                    }
                }
                else
                {
                    prev = av;
                }
            }
        }