Ejemplo n.º 1
0
        private List <HtmlChunk> ParseBml(string bml)
        {
            //loop thru bml

            ////find tag
            /////if reg'd tag save position found. Take all above bml and move to a string. Find end tag

            int currentIndex = 0;
            //int lastChunkStartIndex = 0;
            int lastChunkEndIndex = 0;

            List <HtmlChunk> _chunks   = new List <HtmlChunk>();
            Match            lastmatch = null;

            while (currentIndex < bml.Length)
            {
                Match m = null;

                // Find next opening tags
                TagRegex bmlTag = new TagRegex();
                m = bmlTag.Match(bml, currentIndex);

                //Check to see if we have a match
                if (m.Success)
                {
                    string tagName = HtmlParserHelper.GetTagName(m);
                    if (HtmlParserHelper.IsRegisteredPrefix(tagName))
                    {
                        lastmatch = m;
                        if (HtmlParserHelper.IsSelfClosingTag(m))
                        {
                            //Self closing
                            //Add the in between bml as a chunk
                            //Add chunks to list
                            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex)));
                            //Check to see if its a Region
                            if (HtmlParserHelper.GetTagName(m) == "base:Region")
                            {
                                _chunks.Add(new BmlRegion(m));
                            }
                            else
                            {
                                _chunks.Add(new HtmlTag(m));
                            }

                            //SET last chunk index

                            //increment the index by the length of the tag
                            currentIndex      = m.Index + m.Length;
                            lastChunkEndIndex = currentIndex;
                            continue;
                        }
                        else
                        {
                            //Not self closing, find end tag
                            string outter = HtmlParserHelper.GetOutterText(bml, m);

                            //add the chunks to the list
                            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex)));
                            //Check to see if its a Region
                            if (HtmlParserHelper.GetTagName(m) == "base:Region")
                            {
                                _chunks.Add(new BmlRegion(m, outter));
                            }
                            else
                            {
                                _chunks.Add(new HtmlTag(m, outter));
                            }

                            //SET last chunk index
                            //increment index the amount of outtertext.
                            currentIndex      = m.Index + outter.Length;
                            lastChunkEndIndex = currentIndex;
                            continue;
                        }
                    }
                }
                currentIndex++;
            }

            //add final chunk
            _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, bml.Length - lastChunkEndIndex)));

            return(_chunks);
        }