コード例 #1
0
        private HtmlElement.HtmlElementType ReadElementType(bool isEndElement)
        {
            this.m_sb.Length = 0;
            bool flag = true;
            char c    = default(char);

            while (flag && this.m_htmlReader.Peek(out c))
            {
                switch (c)
                {
                case ' ':
                    if (isEndElement && this.m_sb.Length == 0)
                    {
                        this.m_htmlReader.Advance();
                        break;
                    }
                    goto case '>';

                case '/':
                    if (isEndElement)
                    {
                        this.m_htmlReader.Advance();
                        break;
                    }
                    goto case '>';

                case '>':
                    if (this.m_sb.Length == 0)
                    {
                        return(HtmlElement.HtmlElementType.Unsupported);
                    }
                    return(HtmlLexer.GetElementType(this.m_sb.ToString()));

                default:
                    this.m_htmlReader.Advance();
                    this.m_sb.Append(c);
                    break;
                }
            }
            return(HtmlElement.HtmlElementType.Unsupported);
        }
コード例 #2
0
        protected override void InternalParse(string richText)
        {
            this.m_htmlLexer = new HtmlLexer(richText);
            int num = 0;
            FunctionalList <ListStyle> functionalList = FunctionalList <ListStyle> .Empty;

            HtmlElement.HtmlNodeType    htmlNodeType     = HtmlElement.HtmlNodeType.Element;
            HtmlElement.HtmlNodeType    htmlNodeType2    = HtmlElement.HtmlNodeType.Element;
            HtmlElement.HtmlElementType htmlElementType  = HtmlElement.HtmlElementType.None;
            HtmlElement.HtmlElementType htmlElementType2 = HtmlElement.HtmlElementType.None;
            while (this.m_htmlLexer.Read())
            {
                this.m_currentHtmlElement = this.m_htmlLexer.CurrentElement;
                htmlElementType2          = this.m_currentHtmlElement.ElementType;
                htmlNodeType2             = this.m_currentHtmlElement.NodeType;
                switch (htmlNodeType2)
                {
                case HtmlElement.HtmlNodeType.Element:
                    if (num != 0 && htmlElementType2 != HtmlElement.HtmlElementType.TITLE)
                    {
                        break;
                    }
                    switch (htmlElementType2)
                    {
                    case HtmlElement.HtmlElementType.TITLE:
                        if (!this.m_currentHtmlElement.IsEmptyElement)
                        {
                            num++;
                        }
                        htmlElementType2 = htmlElementType;
                        htmlNodeType2    = htmlNodeType;
                        break;

                    case HtmlElement.HtmlElementType.P:
                    case HtmlElement.HtmlElementType.DIV:
                    case HtmlElement.HtmlElementType.LI:
                    case HtmlElement.HtmlElementType.H1:
                    case HtmlElement.HtmlElementType.H2:
                    case HtmlElement.HtmlElementType.H3:
                    case HtmlElement.HtmlElementType.H4:
                    case HtmlElement.HtmlElementType.H5:
                    case HtmlElement.HtmlElementType.H6:
                        this.ParseParagraphElement(htmlElementType2, functionalList);
                        break;

                    case HtmlElement.HtmlElementType.UL:
                    case HtmlElement.HtmlElementType.OL:
                    {
                        this.FlushPendingLI();
                        this.CloseParagraph();
                        ListStyle listStyleForElement2 = this.GetListStyleForElement(htmlElementType2);
                        functionalList = functionalList.Add(listStyleForElement2);
                        base.m_currentParagraph.ListLevel = functionalList.Count;
                        break;
                    }

                    case HtmlElement.HtmlElementType.SPAN:
                    case HtmlElement.HtmlElementType.FONT:
                    case HtmlElement.HtmlElementType.STRONG:
                    case HtmlElement.HtmlElementType.STRIKE:
                    case HtmlElement.HtmlElementType.B:
                    case HtmlElement.HtmlElementType.I:
                    case HtmlElement.HtmlElementType.U:
                    case HtmlElement.HtmlElementType.S:
                    case HtmlElement.HtmlElementType.EM:
                        this.ParseTextRunElement(htmlElementType2);
                        break;

                    case HtmlElement.HtmlElementType.A:
                        this.ParseActionElement(functionalList.Count);
                        break;

                    case HtmlElement.HtmlElementType.BR:
                        if (htmlNodeType != HtmlElement.HtmlNodeType.EndElement)
                        {
                            this.AppendText(Environment.NewLine);
                        }
                        else
                        {
                            this.SetTextRunValue(Environment.NewLine);
                        }
                        break;

                    default:
                        htmlElementType2 = htmlElementType;
                        htmlNodeType2    = htmlNodeType;
                        break;
                    }
                    break;

                case HtmlElement.HtmlNodeType.Text:
                    if (num == 0)
                    {
                        string text = this.m_currentHtmlElement.Value;
                        if (htmlNodeType == HtmlElement.HtmlNodeType.Text)
                        {
                            this.AppendText(text);
                        }
                        else if (htmlElementType == HtmlElement.HtmlElementType.BR)
                        {
                            this.AppendText(this.HtmlTrimStart(text));
                        }
                        else
                        {
                            if (base.m_currentParagraphInstance == null)
                            {
                                text = this.HtmlTrimStart(text);
                            }
                            if (!string.IsNullOrEmpty(text))
                            {
                                this.SetTextRunValue(text);
                            }
                            else
                            {
                                htmlElementType2 = htmlElementType;
                                htmlNodeType2    = htmlNodeType;
                            }
                        }
                    }
                    break;

                case HtmlElement.HtmlNodeType.EndElement:
                    if (num != 0 && htmlElementType2 != HtmlElement.HtmlElementType.TITLE)
                    {
                        break;
                    }
                    switch (htmlElementType2)
                    {
                    case HtmlElement.HtmlElementType.TITLE:
                        if (num > 0)
                        {
                            num--;
                        }
                        htmlElementType2 = htmlElementType;
                        htmlNodeType2    = htmlNodeType;
                        break;

                    case HtmlElement.HtmlElementType.UL:
                    case HtmlElement.HtmlElementType.OL:
                        this.FlushPendingLI();
                        this.CloseParagraph();
                        if (functionalList.Count > 0)
                        {
                            ListStyle listStyleForElement = this.GetListStyleForElement(htmlElementType2);
                            bool      flag = false;
                            FunctionalList <ListStyle> functionalList2 = functionalList;
                            do
                            {
                                flag            = (functionalList2.First == listStyleForElement);
                                functionalList2 = functionalList2.Rest;
                            }while (!flag && functionalList2.Count > 0);
                            if (flag)
                            {
                                functionalList = functionalList2;
                                base.m_currentParagraph.ListLevel = functionalList.Count;
                            }
                        }
                        break;

                    case HtmlElement.HtmlElementType.LI:
                        this.CloseParagraph();
                        break;

                    case HtmlElement.HtmlElementType.P:
                    case HtmlElement.HtmlElementType.DIV:
                    case HtmlElement.HtmlElementType.H1:
                    case HtmlElement.HtmlElementType.H2:
                    case HtmlElement.HtmlElementType.H3:
                    case HtmlElement.HtmlElementType.H4:
                    case HtmlElement.HtmlElementType.H5:
                    case HtmlElement.HtmlElementType.H6:
                        this.CloseParagraph();
                        base.m_currentParagraph = base.m_currentParagraph.RemoveParagraph(htmlElementType2);
                        goto case HtmlElement.HtmlElementType.SPAN;

                    case HtmlElement.HtmlElementType.SPAN:
                    case HtmlElement.HtmlElementType.FONT:
                    case HtmlElement.HtmlElementType.STRONG:
                    case HtmlElement.HtmlElementType.STRIKE:
                    case HtmlElement.HtmlElementType.B:
                    case HtmlElement.HtmlElementType.I:
                    case HtmlElement.HtmlElementType.U:
                    case HtmlElement.HtmlElementType.S:
                    case HtmlElement.HtmlElementType.EM:
                        base.m_currentStyle = base.m_currentStyle.RemoveStyle(htmlElementType2);
                        break;

                    case HtmlElement.HtmlElementType.A:
                        this.RevertActionElement(htmlElementType2);
                        break;

                    default:
                        htmlElementType2 = htmlElementType;
                        htmlNodeType2    = htmlNodeType;
                        break;
                    }
                    break;
                }
                htmlNodeType    = htmlNodeType2;
                htmlElementType = htmlElementType2;
            }
            if (base.m_paragraphInstanceCollection.Count == 0)
            {
                this.CreateTextRunInstance();
            }
            base.m_currentParagraph = base.m_currentParagraph.RemoveAll();
        }