Exemple #1
0
        /// <summary>
        /// Write a token to the output stream.
        /// </summary>
        /// <remarks>
        /// Writes a token that was emitted by the <see cref="HtmlTokenizer"/>
        /// to the output stream.
        /// </remarks>
        /// <param name="token">The HTML token.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="token"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="HtmlWriter"/> has been disposed.
        /// </exception>
        public void WriteToken(HtmlToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            CheckDisposed();

            if (WriterState != HtmlWriterState.Default)
            {
                WriterState = HtmlWriterState.Default;
                html.Write(empty ? "/>" : ">");
                empty = false;
            }

            token.WriteTo(html);
        }
		/// <summary>
		/// Reads the next token.
		/// </summary>
		/// <remarks>
		/// Reads the next token.
		/// </remarks>
		/// <returns><c>true</c> if the next token was read; otherwise, <c>false</c>.</returns>
		/// <param name="token">THe token that was read.</param>
		public bool ReadNextToken (out HtmlToken token)
		{
			do {
				switch (TokenizerState) {
				case HtmlTokenizerState.Data:
					token = ReadData ();
					break;
				case HtmlTokenizerState.CharacterReferenceInData:
					token = ReadCharacterReferenceInData ();
					break;
				case HtmlTokenizerState.RcData:
					token = ReadRcData ();
					break;
				case HtmlTokenizerState.CharacterReferenceInRcData:
					token = ReadCharacterReferenceInRcData ();
					break;
				case HtmlTokenizerState.RawText:
					token = ReadRawText ();
					break;
				case HtmlTokenizerState.ScriptData:
					token = ReadScriptData ();
					break;
				case HtmlTokenizerState.PlainText:
					token = ReadPlainText ();
					break;
				case HtmlTokenizerState.TagOpen:
					token = ReadTagOpen ();
					break;
				case HtmlTokenizerState.EndTagOpen:
					token = ReadEndTagOpen ();
					break;
				case HtmlTokenizerState.TagName:
					token = ReadTagName ();
					break;
				case HtmlTokenizerState.RcDataLessThan:
					token = ReadRcDataLessThan ();
					break;
				case HtmlTokenizerState.RcDataEndTagOpen:
					token = ReadRcDataEndTagOpen ();
					break;
				case HtmlTokenizerState.RcDataEndTagName:
					token = ReadRcDataEndTagName ();
					break;
				case HtmlTokenizerState.RawTextLessThan:
					token = ReadRawTextLessThan ();
					break;
				case HtmlTokenizerState.RawTextEndTagOpen:
					token = ReadRawTextEndTagOpen ();
					break;
				case HtmlTokenizerState.RawTextEndTagName:
					token = ReadRawTextEndTagName ();
					break;
				case HtmlTokenizerState.ScriptDataLessThan:
					token = ReadScriptDataLessThan ();
					break;
				case HtmlTokenizerState.ScriptDataEndTagOpen:
					token = ReadScriptDataEndTagOpen ();
					break;
				case HtmlTokenizerState.ScriptDataEndTagName:
					token = ReadScriptDataEndTagName ();
					break;
				case HtmlTokenizerState.ScriptDataEscapeStart:
					token = ReadScriptDataEscapeStart ();
					break;
				case HtmlTokenizerState.ScriptDataEscapeStartDash:
					token = ReadScriptDataEscapeStartDash ();
					break;
				case HtmlTokenizerState.ScriptDataEscaped:
					token = ReadScriptDataEscaped ();
					break;
				case HtmlTokenizerState.ScriptDataEscapedDash:
					token = ReadScriptDataEscapedDash ();
					break;
				case HtmlTokenizerState.ScriptDataEscapedDashDash:
					token = ReadScriptDataEscapedDashDash ();
					break;
				case HtmlTokenizerState.ScriptDataEscapedLessThan:
					token = ReadScriptDataEscapedLessThan ();
					break;
				case HtmlTokenizerState.ScriptDataEscapedEndTagOpen:
					token = ReadScriptDataEscapedEndTagOpen ();
					break;
				case HtmlTokenizerState.ScriptDataEscapedEndTagName:
					token = ReadScriptDataEscapedEndTagName ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscapeStart:
					token = ReadScriptDataDoubleEscapeStart ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscaped:
					token = ReadScriptDataDoubleEscaped ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscapedDash:
					token = ReadScriptDataDoubleEscapedDash ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscapedDashDash:
					token = ReadScriptDataDoubleEscapedDashDash ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscapedLessThan:
					token = ReadScriptDataDoubleEscapedLessThan ();
					break;
				case HtmlTokenizerState.ScriptDataDoubleEscapeEnd:
					token = ReadScriptDataDoubleEscapeEnd ();
					break;
				case HtmlTokenizerState.BeforeAttributeName:
					token = ReadBeforeAttributeName ();
					break;
				case HtmlTokenizerState.AttributeName:
					token = ReadAttributeName ();
					break;
				case HtmlTokenizerState.AfterAttributeName:
					token = ReadAfterAttributeName ();
					break;
				case HtmlTokenizerState.BeforeAttributeValue:
					token = ReadBeforeAttributeValue ();
					break;
				case HtmlTokenizerState.AttributeValueQuoted:
					token = ReadAttributeValueQuoted ();
					break;
				case HtmlTokenizerState.AttributeValueUnquoted:
					token = ReadAttributeValueUnquoted ();
					break;
				case HtmlTokenizerState.CharacterReferenceInAttributeValue:
					token = ReadCharacterReferenceInAttributeValue ();
					break;
				case HtmlTokenizerState.AfterAttributeValueQuoted:
					token = ReadAfterAttributeValueQuoted ();
					break;
				case HtmlTokenizerState.SelfClosingStartTag:
					token = ReadSelfClosingStartTag ();
					break;
				case HtmlTokenizerState.BogusComment:
					token = ReadBogusComment ();
					break;
				case HtmlTokenizerState.MarkupDeclarationOpen:
					token = ReadMarkupDeclarationOpen ();
					break;
				case HtmlTokenizerState.CommentStart:
					token = ReadCommentStart ();
					break;
				case HtmlTokenizerState.CommentStartDash:
					token = ReadCommentStartDash ();
					break;
				case HtmlTokenizerState.Comment:
					token = ReadComment ();
					break;
				case HtmlTokenizerState.CommentEndDash:
					token = ReadCommentEndDash ();
					break;
				case HtmlTokenizerState.CommentEnd:
					token = ReadCommentEnd ();
					break;
				case HtmlTokenizerState.CommentEndBang:
					token = ReadCommentEndBang ();
					break;
				case HtmlTokenizerState.DocType:
					token = ReadDocType ();
					break;
				case HtmlTokenizerState.BeforeDocTypeName:
					token = ReadBeforeDocTypeName ();
					break;
				case HtmlTokenizerState.DocTypeName:
					token = ReadDocTypeName ();
					break;
				case HtmlTokenizerState.AfterDocTypeName:
					token = ReadAfterDocTypeName ();
					break;
				case HtmlTokenizerState.AfterDocTypePublicKeyword:
					token = ReadAfterDocTypePublicKeyword ();
					break;
				case HtmlTokenizerState.BeforeDocTypePublicIdentifier:
					token = ReadBeforeDocTypePublicIdentifier ();
					break;
				case HtmlTokenizerState.DocTypePublicIdentifierQuoted:
					token = ReadDocTypePublicIdentifierQuoted ();
					break;
				case HtmlTokenizerState.AfterDocTypePublicIdentifier:
					token = ReadAfterDocTypePublicIdentifier ();
					break;
				case HtmlTokenizerState.BetweenDocTypePublicAndSystemIdentifiers:
					token = ReadBetweenDocTypePublicAndSystemIdentifiers ();
					break;
				case HtmlTokenizerState.AfterDocTypeSystemKeyword:
					token = ReadAfterDocTypeSystemKeyword ();
					break;
				case HtmlTokenizerState.BeforeDocTypeSystemIdentifier:
					token = ReadBeforeDocTypeSystemIdentifier ();
					break;
				case HtmlTokenizerState.DocTypeSystemIdentifierQuoted:
					token = ReadDocTypeSystemIdentifierQuoted ();
					break;
				case HtmlTokenizerState.AfterDocTypeSystemIdentifier:
					token = ReadAfterDocTypeSystemIdentifier ();
					break;
				case HtmlTokenizerState.BogusDocType:
					token = ReadBogusDocType ();
					break;
				case HtmlTokenizerState.CDataSection:
					token = ReadCDataSection ();
					break;
				case HtmlTokenizerState.EndOfFile:
				default:
					token = null;
					return false;
				}
			} while (token == null);

			return true;
		}
Exemple #3
0
		/// <summary>
		/// Write a token to the output stream.
		/// </summary>
		/// <remarks>
		/// Writes a token that was emitted by the <see cref="HtmlTokenizer"/>
		/// to the output stream.
		/// </remarks>
		/// <param name="token">The HTML token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="token"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteToken (HtmlToken token)
		{
			if (token == null)
				throw new ArgumentNullException ("token");

			CheckDisposed ();

			if (WriterState != HtmlWriterState.Default) {
				WriterState = HtmlWriterState.Default;
				html.Write (empty ? "/>" : ">");
				empty = false;
			}

			token.WriteTo (html);
		}