Tidy.Core.Lexer.NewLineNode C# (CSharp) Method

NewLineNode() public method

public NewLineNode ( ) : Node
return Node
        public virtual Node NewLineNode()
        {
            Node node = NewNode();

            node.Textarray = Lexbuf;
            node.Start = Lexsize;
            AddCharToLexer('\n');
            node.End = Lexsize;
            return node;
        }

Usage Example

Beispiel #1
0
        /*
        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);
                        node = list.Next;
                    }
                    else
                    {
                        list = null;
                    }
                }
                else
                {
                    list = null;
                }

                /* strip out style and class attributes */
                if (node.Type == Node.START_TAG || node.Type == Node.START_END_TAG)
                {
                    PurgeAttributes(node);
                }

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

                node = node.Next;
            }
        }