Esempio n. 1
0
 private HtmlNodeEndTag CreateHtmlNodeEndTag(HtmlReaderTag tag)
 {
     return new HtmlNodeEndTag
     {
         Index = _htmlNodeIndex++,
         Line = _disableLineColumn ? 0 : tag.Line,
         Column = _disableLineColumn ? 0 : tag.Column,
         Name = tag.Name
     };
 }
Esempio n. 2
0
 private HtmlNodeOpenTag CreateHtmlNodeOpenTag(HtmlReaderTag tag)
 {
     return new HtmlNodeOpenTag
     {
         Index = _htmlNodeIndex++,
         Line = _disableLineColumn ? 0 : tag.Line,
         Column = _disableLineColumn ? 0 : tag.Column,
         Name = tag.Name,
         IsScript = tag.ScriptTag
     };
 }
Esempio n. 3
0
 private HtmlNodeDocType CreateHtmlNodeDocType(HtmlReaderTag tag)
 {
     return new HtmlNodeDocType
     {
         Index = _htmlNodeIndex++,
         Line = _disableLineColumn ? 0 : tag.Line,
         Column = _disableLineColumn ? 0 : tag.Column,
         DocType = tag.DocType
     };
 }
Esempio n. 4
0
        private IEnumerable<HtmlNode> ReadPropertiesNodes(HtmlReaderTag tag)
        {
            while (true)
            {
                HtmlReaderProperty property = ReadProperty();
                if (property != null)
                {
                    yield return CreateHtmlNodeProperty(property);

                    if (property.CloseTag)
                    {
                        if (property.EndTag)
                            yield return CreateHtmlNodeEndTag(tag);
                        else if (_generateCloseTag)
                            yield return CreateHtmlNodeCloseTag(tag);
                        break;
                    }
                }
                else
                {
                    if (_generateCloseTag)
                        yield return CreateHtmlNodeCloseTag(tag);
                    break;
                }
            }
        }
Esempio n. 5
0
        private IEnumerable<HtmlNode> ReadTagNodes(HtmlReaderTag tag)
        {
            // <div>           : BeginTag = true,  EndTag = false, CloseTag = true,  DocTypeTag = false
            // <div ... >      : BeginTag = true,  EndTag = false, CloseTag = false, DocTypeTag = false, ready to read properties
            // <div ... />     : BeginTag = true,  EndTag = false, CloseTag = false, DocTypeTag = false, ready to read properties
            // <div />         : BeginTag = true,  EndTag = true,  CloseTag = true,  DocTypeTag = false
            // </div>          : BeginTag = false, EndTag = true,  CloseTag = true,  DocTypeTag = false
            // <!DOCTYPE ... > : BeginTag = false, EndTag = false, CloseTag = true,  DocTypeTag = true

            // <div>           : OpenTag div, CloseTag div EndTag = false
            // <div ... >      : OpenTag div, Property ..., CloseTag div EndTag = false
            // <div ... />     : OpenTag div, Property ..., CloseTag div EndTag = true
            // <div />         : OpenTag div, CloseTag div EndTag = true
            // </div>          : EndTag div
            // <!DOCTYPE ... > : DocumentType

            if (tag.DocTypeTag)
            {
                yield return CreateHtmlNodeDocType(tag);
            }
            else if (tag.BeginTag)
            {
                yield return CreateHtmlNodeOpenTag(tag);

                if (tag.EndTag)
                {
                    yield return CreateHtmlNodeEndTag(tag);
                }

                // read properties
                if (!tag.CloseTag)
                {
                    foreach (HtmlNode node in ReadPropertiesNodes(tag))
                        yield return node;
                }

                // read script
                if (tag.ScriptTag)
                {
                    HtmlReaderScript script = ReadScript();
                    if (script != null)
                        yield return CreateHtmlNodeScript(script);
                }
            }
            else if (tag.EndTag)
            {
                yield return CreateHtmlNodeEndTag(tag);
            }
        }
Esempio n. 6
0
        //private bool BeginTag()
        //{
        //    // $$pb modif le 11/01/2015 pour gérer <!DOCTYPE ...
        //    return (char)PeekChar() == '<' && (char.IsLetter((char)PeekChar(1)) || (PeekChar(1) == '/' && char.IsLetter((char)PeekChar(2))) || (PeekChar(1) == '!' && PeekChar(2) == 'D'));
        //}

        //private void ReadMarkName()
        private HtmlReaderTag ReadTag()
        {
            // <div>           : BeginTag = true,  EndTag = false, CloseTag = true,  DocTypeTag = false
            // <div ... >      : BeginTag = true,  EndTag = false, CloseTag = false, DocTypeTag = false, ready to read properties
            // <div ... />     : BeginTag = true,  EndTag = false, CloseTag = false, DocTypeTag = false, ready to read properties
            // <div />         : BeginTag = true,  EndTag = true,  CloseTag = true,  DocTypeTag = false
            // </div>          : BeginTag = false, EndTag = true,  CloseTag = true,  DocTypeTag = false
            // <!DOCTYPE ... > : BeginTag = false, EndTag = false, CloseTag = true,  DocTypeTag = true
            HtmlReaderTag tag = null;
            if ((char)PeekChar() == '<' && (char.IsLetter((char)PeekChar(1)) || (PeekChar(1) == '/' && char.IsLetter((char)PeekChar(2))) || (PeekChar(1) == '!' && PeekChar(2) == 'D')))
            {
                tag = new HtmlReaderTag();
                tag.Line = _line;
                tag.Column = _column;

                // read '<'
                GetChar();

                if (PeekChar() == '/')
                {
                    //_isMarkEnd = true;
                    tag.EndTag = true;
                    GetChar();
                }
                else
                    //_isMarkBegin = true;
                    tag.BeginTag = true;

                // read tag name
                _stringBuilder.Remove(0, _stringBuilder.Length);
                GetChar();
                while (_charInt != -1 && _char != '<' && _char != '/' && _char != '>' && _char != ' ' && _char != '\t' && _char != '\r' && _char != '\n')
                {
                    _stringBuilder.Append(_char);
                    GetChar();
                }
                //_markName = _stringBuilder.ToString();
                tag.Name = _stringBuilder.ToString();

                //_scriptMarkInProgress = false;
                //if (string.Compare(_markName, "!doctype", true) == 0 && _isMarkBegin)
                if (string.Compare(tag.Name, "!doctype", true) == 0 && tag.BeginTag)
                {
                    HtmlReaderTag tag2 = ReadDocType();
                    tag2.Line = tag.Line;
                    tag2.Column = tag.Column;
                    tag = tag2;
                    //return;
                }
                else
                {
                    //if (string.Compare(_markName, "script", true) == 0 && _isMarkBegin)
                    if (string.Compare(tag.Name, "script", true) == 0 && tag.BeginTag)
                        //_scriptMarkInProgress = true;
                        tag.ScriptTag = true;
                    if (_char == ' ' || _char == '\t' || _char == '\r' || _char == '\n')
                        ReadSeparator();
                    if (_char == '/')
                    {
                        //_isMarkBegin = false;
                        //_isMarkEnd = false;
                        //_isMarkBeginEnd = true;
                        tag.BeginTag = true;
                        tag.EndTag = true;
                        //tag.Tag = true;
                        GetChar();
                    }

                    if (_char == '>')
                        tag.CloseTag = true;
                    else
                        UnreadChar();

                }
            }
            return tag;
        }