コード例 #1
0
        public override void Parse(bool useDefaultAnalyzers = false)
        {
            NextToken();
            Root = NodeFactory.CreateRootNode();

            while (CurrentToken.Keyword != KeywordToken.EOF)
            {
                NextToken();
                // only container elements can be processed here
                switch (CurrentToken.Keyword)
                {
                case KeywordToken.Paragraph:
                    var a = new ParagraphStatementParser(parser);
                    Root.SetRootNode(a.Parse(CurrentToken));
                    break;

                case KeywordToken.Body:
                    var b        = new GenericElementNode(this, KeywordToken.Body);
                    var bodyNode = b.Parse(CurrentToken);
                    Root.SetRootNode(bodyNode);
                    break;
                }
            }

            if (useDefaultAnalyzers)
            {
                if (_analyzers == null)
                {
                    _analyzers = new ChildrenAnalyzer();
                    _analyzers.Use(new ElementToAttributeAnalyzer())
                    .Use(new AttributeCopierAnalyzer())
                    .Use(new SiblingsAnalyzer())
                    ;
                }
                else
                {
                    var elementAnalyzer = new ChildrenAnalyzer();
                    elementAnalyzer.Use(new ElementToAttributeAnalyzer())
                    .Use(new AttributeCopierAnalyzer())
                    .Use(new SiblingsAnalyzer())
                    .Use(_analyzers);
                    _analyzers = elementAnalyzer;
                }
            }
            if (_analyzers == null)
            {
                return;
            }
            Root.SetRootNode(_analyzers.Analyze(Root.Root));
        }
コード例 #2
0
        public void ShouldNotMergeNodesOfTheSameTypeIfPropsConflict()
        {
            var node             = TestHelper.ParseString(@"<w:body>
                                                    <w:p test=""oldValue"">
                                                        <w:pPr><w:pStyle w:val = ""Title""/></w:pPr>
                                                        <w:p test=""newValue"">
                                                            <w:t>TestTItle</w:t>
                                                         </w:p>
                                                    </w:p>
                                                </w:body>");
            var childrenAnalyzer = new ChildrenAnalyzer();
            var result           = childrenAnalyzer.Analyze(node);
            var paragraphChild   = result.Children.First();

            Assert.AreEqual(2, paragraphChild.Children.Count);
            Assert.AreEqual(KeywordToken.Paragraph, paragraphChild.Children[1].Type);
        }
コード例 #3
0
        public void ShouldNotHaveImmediateChildOfSameType()
        {
            var node             = TestHelper.ParseString(@"<w:body>
                                                    <w:p w:rsidP=""001F0010"" w:rsidRDefault=""001F0010"" w:rsidR=""001F0010"">
                                                        <w:pPr><w:pStyle w:val = ""Title""/></w:pPr>
                                                        <w:p>
                                                            <w:t>TestTItle</w:t>
                                                         </w:p>
                                                    </w:p>
                                                </w:body>");
            var childrenAnalyzer = new ChildrenAnalyzer();
            var result           = childrenAnalyzer.Analyze(node);
            var paragraphChild   = result.Children.First();

            Assert.AreEqual(2, paragraphChild.Children.Count);
            Assert.AreEqual(KeywordToken.Text, paragraphChild.Children[1].Type);
        }