当前位置: 首页>>代码示例>>C#>>正文


C# Node.GetAttrByName方法代码示例

本文整理汇总了C#中Tidy.Core.Node.GetAttrByName方法的典型用法代码示例。如果您正苦于以下问题:C# Node.GetAttrByName方法的具体用法?C# Node.GetAttrByName怎么用?C# Node.GetAttrByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tidy.Core.Node的用法示例。


在下文中一共展示了Node.GetAttrByName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

        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");
                }
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:30,代码来源:ScriptCheckAttribs.cs

示例2: url

        /*
        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)
        {
            string bgurl = null;
            string bgcolor = null;
            string color = null;

            AttVal 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);
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:95,代码来源:Clean.cs

示例3: PrintAttrs

        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\"");
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:32,代码来源:PPrint.cs

示例4: Style2Rule

        /*
        Find style attribute in node, and replace it
        by corresponding class attribute. Search for
        class in style dictionary otherwise gensym
        new class and add to dictionary.

        Assumes that node doesn't have a class attribute
        */
        private void Style2Rule(Lexer lexer, Node node)
        {
            AttVal styleattr = node.GetAttrByName("style");

            if (styleattr == null) return;
            string classname = FindStyle(lexer, node.Element, styleattr.Val);
            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;
                node.RemoveAttribute(styleattr);
            }
            else
            {
                /* reuse style attribute for class attribute */
                styleattr.Attribute = "class";
                styleattr.Val = classname;
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:32,代码来源:Clean.cs

示例5: CleanWord2000

        /*
        This is a major clean up to strip out all the extra stuff you get
        when you save as web page from Word 2000. It doesn't yet know what
        to do with VML tags, but these will appear as errors unless you
        declare them as new tags, such as o:p which needs to be declared
        as inline.
        */
        public virtual void CleanWord2000(Lexer lexer, Node node)
        {
            /* used to a list from a sequence of bulletted p's */
            Node list = null;

            while (node != null)
            {
                /* discard Word's style verbiage */
                if (node.Tag == _tt.TagStyle || node.Tag == _tt.TagMeta || node.Type == Node.COMMENT_TAG)
                {
                    node = Node.DiscardElement(node);
                    continue;
                }

                /* strip out all span tags Word scatters so liberally! */
                if (node.Tag == _tt.TagSpan)
                {
                    node = StripSpan(lexer, node);
                    continue;
                }

                /* get rid of Word's xmlns attributes */
                if (node.Tag == _tt.TagHtml)
                {
                    /* check that it's a Word 2000 document */
                    if (node.GetAttrByName("xmlns:o") == null)
                    {
                        return;
                    }
                }

                if (node.Tag == _tt.TagLink)
                {
                    AttVal attr = node.GetAttrByName("rel");

                    if (attr != null && attr.Val != null && attr.Val.Equals("File-List"))
                    {
                        node = Node.DiscardElement(node);
                        continue;
                    }
                }

                /* discard empty paragraphs */
                if (node.Content == null && node.Tag == _tt.TagP)
                {
                    node = Node.DiscardElement(node);
                    continue;
                }

                if (node.Tag == _tt.TagP)
                {
                    AttVal attr = node.GetAttrByName("class");

                    /* map sequence of <p class="MsoListBullet"> to <ul>...</ul> */
                    if (attr != null && attr.Val != null && attr.Val.Equals("MsoListBullet"))
                    {
                        Node.CoerceNode(lexer, node, _tt.TagLi);

                        if (list == null || list.Tag != _tt.TagUl)
                        {
                            list = lexer.InferredTag("ul");
                            Node.InsertNodeBeforeElement(node, list);
                        }

                        PurgeAttributes(node);

                        if (node.Content != null)
                        {
                            CleanWord2000(lexer, node.Content);
                        }

                        /* remove node and append to contents of list */
                        Node.RemoveNode(node);
                        Node.InsertNodeAtEnd(list, node);
                        node = list.Next;
                    }
                    else if (attr != null && attr.Val != null && attr.Val.Equals("Code"))
                    {
                        /* map sequence of <p class="Code"> to <pre>...</pre> */
                        Node br = lexer.NewLineNode();
                        NormalizeSpaces(node);

                        if (list == null || list.Tag != _tt.TagPre)
                        {
                            list = lexer.InferredTag("pre");
                            Node.InsertNodeBeforeElement(node, list);
                        }

                        /* remove node and append to contents of list */
                        Node.RemoveNode(node);
                        Node.InsertNodeAtEnd(list, node);
                        StripSpan(lexer, node);
                        Node.InsertNodeAtEnd(list, br);
//.........这里部分代码省略.........
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:101,代码来源:Clean.cs

示例6: FixId

        /* duplicate name attribute as an id */
        public virtual void FixId(Node node)
        {
            AttVal name = node.GetAttrByName("name");
            AttVal id = node.GetAttrByName("id");

            if (name != null)
            {
                if (id != null)
                {
                    if (!id.Val.Equals(name.Val))
                    {
                        Report.AttrError(this, node, "name", Report.ID_NAME_MISMATCH);
                    }
                }
                else if (Options.XmlOut)
                {
                    node.AddAttribute("id", name.Val);
                }
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:21,代码来源:Lexer.cs

示例7: CanPrune

        public virtual bool CanPrune(Node element)
        {
            if (element.Type == Node.TEXT_NODE)
                return true;

            if (element.Content != null)
                return false;

            if (element.Tag == Options.TagTable.TagA && element.Attributes != null)
                return false;

            if (element.Tag == Options.TagTable.TagP && !Options.DropEmptyParas)
                return false;

            if (element.Tag == null)
                return false;

            if ((element.Tag.Model & ContentModel.ROW) != 0)
                return false;

            if (element.Tag == Options.TagTable.TagApplet)
                return false;

            if (element.Tag == Options.TagTable.TagObject)
                return false;

            if (element.Attributes != null &&
                (element.GetAttrByName("id") != null || element.GetAttrByName("name") != null))
                return false;

            return true;
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:32,代码来源:Lexer.cs

示例8: AddClass

        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);
            }
        }
开发者ID:r1pper,项目名称:TidyNetPortable,代码行数:18,代码来源:Node.cs


注:本文中的Tidy.Core.Node.GetAttrByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。