예제 #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
        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;
            }
            if (att != null)
            {
                return(att.Val);
            }
            else
            {
                return(String.Empty);
            }
        }
예제 #3
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;
                }
            }
        }
예제 #4
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.Compare(str, "javascript") == 0) || (String.Compare(str, "jscript") == 0))
                    {
                        node.AddAttribute("type", "text/javascript");
                    }
                }
                else
                {
                    node.AddAttribute("type", "text/javascript");
                }
            }
        }
예제 #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.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);
            }
        }
예제 #6
0
파일: AttVal.cs 프로젝트: r-win/TidyNet
        public object Clone()
        {
            AttVal 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);
        }
예제 #7
0
        private Dict _tag; /* tag's dictionary definition */

        #endregion Fields

        #region Constructors

        /*
        Mosaic handles inlines via a separate stack from other elements
        We duplicate this to recover from inline markup errors such as:

        <i>italic text
        <p>more italic text</b> normal text

        which for compatibility with Mosaic is mapped to:

        <i>italic text</i>
        <p><i>more italic text</i> normal text

        Note that any inline end tag pop's the effect of the current
        inline start tag, so that </b> pop's <i> in the above example.
        */
        public InlineStack()
        {
            _next = null;
            _tag = null;
            _element = null;
            _attributes = null;
        }
예제 #8
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);
            }
        }
예제 #9
0
 public AttVal()
 {
     _next = null;
     _dict = null;
     _asp = null;
     _php = null;
     _delim = 0;
     _attribute = null;
     _val = null;
 }
예제 #10
0
파일: AttVal.cs 프로젝트: r-win/TidyNet
 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 프로젝트: r-win/TidyNet
 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 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;
 }
예제 #13
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;
 }
예제 #14
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('\\', '/');
     }
 }
예제 #15
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('\\', '/');
     }
 }
예제 #16
0
        /* public method for finding attribute definition by name */
        public virtual Attribute FindAttribute(AttVal attval)
        {
            Attribute np;

            if (attval.Attribute != null)
            {
                np = Lookup(attval.Attribute);
                return(np);
            }

            return(null);
        }
        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");
            }
        }
예제 #18
0
        public virtual IAttr CreateAttribute(string name)
        {
            AttVal av = new AttVal(null, null, (int)'"', name, null);

            if (av != null)
            {
                av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
                return((IAttr)av.Adapter);
            }
            else
            {
                return(null);
            }
        }
예제 #19
0
        public virtual IAttr SetAttributeNode(IAttr newAttr)
        {
            if (newAttr == null)
            {
                return(null);
            }

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

            DomAttrImpl 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);
        }
        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");
                }
            }
        }
예제 #21
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);
            }
        }
예제 #22
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);
            }
        }
예제 #23
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);
            }
        }
예제 #24
0
        public virtual INode GetNamedItem(string name)
        {
            AttVal att = _first;

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

            if (att != null)
            {
                return(att.Adapter);
            }
            else
            {
                return(null);
            }
        }
예제 #25
0
        public virtual IAttr RemoveAttributeNode(IAttr oldAttr)
        {
            if (oldAttr == null)
            {
                return(null);
            }

            IAttr  result = null;
            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.NotFound, "oldAttr not found");
            }
            return(result);
        }
예제 #26
0
        public virtual void AddAttribute(string name, string val)
        {
            AttVal 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;
            }
        }
예제 #27
0
        public virtual INode Item(int index)
        {
            int    i   = 0;
            AttVal att = _first;

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

            if (att != null)
            {
                return(att.Adapter);
            }
            else
            {
                return(null);
            }
        }
예제 #28
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, (int)'"', name, val);
                att.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(att);
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = att;
                }
                else
                {
                    att.Next           = Adaptee.Attributes;
                    Adaptee.Attributes = att;
                }
            }
        }
예제 #29
0
 public virtual void Check(Lexer lexer, Node node, AttVal attval)
 {
 }
예제 #30
0
 public object Clone()
 {
     AttVal 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;
 }
예제 #31
0
파일: Clean.cs 프로젝트: AlfieJ/TidyNet
        /*
        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;
            }
        }
예제 #32
0
파일: Clean.cs 프로젝트: AlfieJ/TidyNet
        /*
        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;

                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;
            }
        }
예제 #33
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, (int) '"', name, val);
                att.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(att);
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = att;
                }
                else
                {
                    att.Next = Adaptee.Attributes;
                    Adaptee.Attributes = att;
                }
            }
        }
예제 #34
0
파일: Node.cs 프로젝트: AlfieJ/TidyNet
        /* 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;
                }
            }
        }
예제 #35
0
 protected internal DomAttrMapImpl(AttVal first)
 {
     _first = first;
 }
예제 #36
0
        /* public method for finding attribute definition by name */
        public virtual Attribute FindAttribute(AttVal attval)
        {
            Attribute np;

            if (attval.Attribute != null)
            {
                np = Lookup(attval.Attribute);
                return np;
            }

            return null;
        }
예제 #37
0
 protected internal DomAttrImpl(AttVal adaptee)
     : base(null)
 {
     _attValAdaptee = adaptee;
 }
예제 #38
0
 public virtual void Check(Lexer lexer, Node node, AttVal attval)
 {
 }
예제 #39
0
        private void PrintAttribute(Out fout, int indent, Node node, AttVal attr)
        {
            string name;
            bool wrappable = false;

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

            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((int) 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);
            }
        }
예제 #40
0
        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.tt) && node.GetAttrByName("xml:space") == null)
            {
                PrintString(fout, indent, " xml:space=\"preserve\"");
            }
        }
예제 #41
0
파일: Node.cs 프로젝트: AlfieJ/TidyNet
 public Node(short type, byte[] textarray, int start, int end, string element, TagTable tt)
 {
     _parent = null;
     _prev = null;
     _next = null;
     _last = null;
     _start = start;
     _end = end;
     _textarray = textarray;
     _type = type;
     _closed = false;
     _isimplicit = false;
     _linebreak = false;
     _was = null;
     _tag = null;
     _element = element;
     _attributes = null;
     _content = null;
     if (type == StartTag || type == StartEndTag || type == EndTag)
     {
         tt.FindTag(this);
     }
 }
예제 #42
0
 public virtual IAttr CreateAttribute(string name)
 {
     AttVal av = new AttVal(null, null, (int) '"', name, null);
     if (av != null)
     {
         av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
         return (IAttr) av.Adapter;
     }
     else
     {
         return null;
     }
 }
예제 #43
0
파일: Node.cs 프로젝트: AlfieJ/TidyNet
 public Node(short type, byte[] textarray, int start, int end)
 {
     _parent = null;
     _prev = null;
     _next = null;
     _last = null;
     _start = start;
     _end = end;
     _textarray = textarray;
     _type = type;
     _closed = false;
     _isimplicit = false;
     _linebreak = false;
     _was = null;
     _tag = null;
     _element = null;
     _attributes = null;
     _content = null;
 }
예제 #44
0
 protected internal DomAttrMapImpl(AttVal first)
 {
     _first = first;
 }
예제 #45
0
파일: Clean.cs 프로젝트: AlfieJ/TidyNet
        private void MergeStyles(Node node, Node child)
        {
            AttVal av;
            string s1, s2, style;

            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 */
                    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;
            }
        }
예제 #46
0
파일: Clean.cs 프로젝트: AlfieJ/TidyNet
        /* create style element using rules from dictionary */
        private void CreateStyleElement(Lexer lexer, Node doc)
        {
            Node node, head, body;
            Style style;
            AttVal av;

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

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

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

            body = doc.FindBody(lexer.Options.tt);

            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.TextNode, 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
            */

            head = doc.FindHead(lexer.Options.tt);

            if (head != null)
            {
                Node.InsertNodeAtEnd(head, node);
            }
        }
예제 #47
0
파일: Node.cs 프로젝트: AlfieJ/TidyNet
        public virtual void AddAttribute(string name, string val)
        {
            AttVal 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;
            }
        }
		/* swallows closing '>' */
		
		public virtual AttVal ParseAttrs(MutableBoolean isempty)
		{
			AttVal av, list;
			string attribute, val;
			MutableInteger delim = new MutableInteger();
			MutableObject asp = new MutableObject();
			MutableObject php = new MutableObject();
			
			list = null;
			
			while (!EndOfInput())
			{
				attribute = ParseAttribute(isempty, asp, php);
				
				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;
				}
				
				val = ParseValue(attribute, false, isempty, delim);
				
				if (attribute != null && 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;
		}
		public virtual AttVal CloneAttributes(AttVal attrs)
		{
			AttVal 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;
		}
예제 #50
0
 protected internal DomAttrImpl(AttVal adaptee) : base(null)
 {
     _attValAdaptee = adaptee;
 }
		public virtual void FixHtmlNameSpace(Node root, string profile)
		{
			Node node;
			AttVal prev, attr;
			
			for (node = root.Content; node != null && node.Tag != Options.tt.TagHtml; node = node.Next)
			{
				;
			}
			
			if (node != null)
			{
				prev = null;
				
				for (attr = node.Attributes; attr != null; attr = attr.Next)
				{
					if (attr.Attribute.Equals("xmlns"))
					{
						break;
					}
					
					prev = attr;
				}
				
				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, (int) '"', "xmlns", profile);
					attr.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(attr);
					node.Attributes = attr;
				}
			}
		}