Example #1
0
        /// <summary>
        /// Write text to the output stream, escaping special characters.
        /// </summary>
        /// <remarks>
        /// Writes text to the output stream, escaping special characters.
        /// </remarks>
        /// <param name="buffer">The text buffer.</param>
        /// <param name="index">The index of the first character to write.</param>
        /// <param name="count">The number of characters to write.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="buffer"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero or greater than the length of
        /// <paramref name="buffer"/>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> and <paramref name="count"/> do not specify
        /// a valid range in the <paramref name="buffer"/>.</para>
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="HtmlWriter"/> has been disposed.
        /// </exception>
        public void WriteText(char[] buffer, int index, int count)
        {
            ValidateArguments(buffer, index, count);
            CheckDisposed();

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

            if (count > 0)
            {
                HtmlUtils.HtmlEncode(html, buffer, index, count);
            }
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// Write a start tag.
        /// </summary>
        /// <remarks>
        /// Writes a start tag.
        /// </remarks>
        /// <example>
        /// <code language="c#" source="Examples\MimeVisitorExamples.cs" region="HtmlPreviewVisitor" />
        /// </example>
        /// <param name="id">The HTML tag identifier.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="id"/> is not a valid HTML tag identifier.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="HtmlWriter"/> has been disposed.
        /// </exception>
        public void WriteStartTag(HtmlTagId id)
        {
            if (id == HtmlTagId.Unknown)
            {
                throw new ArgumentException("Invalid tag.", nameof(id));
            }

            CheckDisposed();

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

            html.Write(string.Format("<{0}", id.ToHtmlTagName()));
            WriterState = HtmlWriterState.Tag;
        }
Example #4
0
        /// <summary>
        /// Write a string containing HTML markup directly to the output, without escaping special characters.
        /// </summary>
        /// <remarks>
        /// Writes a string containing HTML markup directly to the output, without escaping special characters.
        /// </remarks>
        /// <param name="value">The string containing HTML markup.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="value"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="HtmlWriter"/> has been disposed.
        /// </exception>
        public void WriteMarkupText(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            CheckDisposed();

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

            html.Write(value);
        }
Example #5
0
        /// <summary>
        /// Write text to the output stream, escaping special characters.
        /// </summary>
        /// <remarks>
        /// Writes text to the output stream, escaping special characters.
        /// </remarks>
        /// <example>
        /// <code language="c#" source="Examples\MimeVisitorExamples.cs" region="HtmlPreviewVisitor" />
        /// </example>
        /// <param name="value">The text.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="value"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="HtmlWriter"/> has been disposed.
        /// </exception>
        public void WriteText(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            CheckDisposed();

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

            if (value.Length > 0)
            {
                HtmlUtils.HtmlEncode(html, value.ToCharArray(), 0, value.Length);
            }
        }
Example #6
0
		/// <summary>
		/// Write a start tag.
		/// </summary>
		/// <remarks>
		/// Writes a start tag.
		/// </remarks>
		/// <param name="name">The name of the HTML tag.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="name"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="name"/> is not a valid HTML tag.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteStartTag (string name)
		{
			ValidateTagName (name);
			CheckDisposed ();

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

			html.Write (string.Format ("<{0}", name));
			WriterState = HtmlWriterState.Tag;
		}
Example #7
0
		/// <summary>
		/// Flush any remaining state to the output stream.
		/// </summary>
		/// <remarks>
		/// Flushes any remaining state to the output stream.
		/// </remarks>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void Flush ()
		{
			CheckDisposed ();

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

			html.Flush ();
		}
Example #8
0
		/// <summary>
		/// Write text to the output stream, escaping special characters.
		/// </summary>
		/// <remarks>
		/// Writes text to the output stream, escaping special characters.
		/// </remarks>
		/// <param name="value">The text.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="value"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteText (string value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");

			CheckDisposed ();

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

			if (value.Length > 0)
				HtmlUtils.HtmlEncode (html, value.ToCharArray (), 0, value.Length);
		}
Example #9
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);
		}
Example #10
0
		void EncodeAttributeName (string name)
		{
			if (WriterState == HtmlWriterState.Default)
				throw new InvalidOperationException ("Cannot write attributes in the Default state.");

			html.Write (' ');
			html.Write (name);
			WriterState = HtmlWriterState.Attribute;
		}
Example #11
0
		/// <summary>
		/// Write text to the output stream, escaping special characters.
		/// </summary>
		/// <remarks>
		/// Writes text to the output stream, escaping special characters.
		/// </remarks>
		/// <param name="buffer">The text buffer.</param>
		/// <param name="index">The index of the first character to write.</param>
		/// <param name="count">The number of characters to write.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="buffer"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero or greater than the length of
		/// <paramref name="buffer"/>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> and <paramref name="count"/> do not specify
		/// a valid range in the <paramref name="buffer"/>.</para>
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteText (char[] buffer, int index, int count)
		{
			ValidateArguments (buffer, index, count);
			CheckDisposed ();

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

			if (count > 0)
				HtmlUtils.HtmlEncode (html, buffer, index, count);
		}
Example #12
0
		/// <summary>
		/// Write a string containing HTML markup directly to the output, without escaping special characters.
		/// </summary>
		/// <remarks>
		/// Writes a string containing HTML markup directly to the output, without escaping special characters.
		/// </remarks>
		/// <param name="value">The string containing HTML markup.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="value"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteMarkupText (string value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");

			CheckDisposed ();

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

			html.Write (value);
		}
Example #13
0
		/// <summary>
		/// Write a start tag.
		/// </summary>
		/// <remarks>
		/// Writes a start tag.
		/// </remarks>
		/// <param name="id">The HTML tag identifier.</param>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="id"/> is not a valid HTML tag identifier.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteStartTag (HtmlTagId id)
		{
			if (id == HtmlTagId.Unknown)
				throw new ArgumentException ("Invalid tag.", "id");

			CheckDisposed ();

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

			html.Write (string.Format ("<{0}", id.ToHtmlTagName ()));
			WriterState = HtmlWriterState.Tag;
		}
Example #14
0
		/// <summary>
		/// Write a buffer containing HTML markup directly to the output, without escaping special characters.
		/// </summary>
		/// <remarks>
		/// Writes a buffer containing HTML markup directly to the output, without escaping special characters.
		/// </remarks>
		/// <param name="buffer">The buffer containing HTML markup.</param>
		/// <param name="index">The index of the first character to write.</param>
		/// <param name="count">The number of characters to write.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="buffer"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero or greater than the length of
		/// <paramref name="buffer"/>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> and <paramref name="count"/> do not specify
		/// a valid range in the <paramref name="buffer"/>.</para>
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteMarkupText (char[] buffer, int index, int count)
		{
			ValidateArguments (buffer, index, count);
			CheckDisposed ();

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

			html.Write (buffer, index, count);
		}
Example #15
0
		/// <summary>
		/// Write an end tag.
		/// </summary>
		/// <remarks>
		/// Writes an end tag.
		/// </remarks>
		/// <param name="name">The name of the HTML tag.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="name"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="name"/> is not a valid HTML tag.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteEndTag (string name)
		{
			ValidateTagName (name);
			CheckDisposed ();

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

			html.Write (string.Format ("</{0}>", name));
		}
Example #16
0
		/// <summary>
		/// Write an empty element tag.
		/// </summary>
		/// <remarks>
		/// Writes an empty element tag.
		/// </remarks>
		/// <param name="name">The name of the HTML tag.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="name"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="name"/> is not a valid HTML tag.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="HtmlWriter"/> has been disposed.
		/// </exception>
		public void WriteEmptyElementTag (string name)
		{
			ValidateTagName (name);
			CheckDisposed ();

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

			html.Write (string.Format ("<{0}", name));
			WriterState = HtmlWriterState.Tag;
			empty = true;
		}
Example #17
0
		void EncodeAttributeValue (string value)
		{
			if (WriterState != HtmlWriterState.Attribute)
				throw new InvalidOperationException ("Attribute values can only be written in the Attribute state.");

			html.Write ('=');
			HtmlUtils.HtmlEncodeAttribute (html, value);
			WriterState = HtmlWriterState.Tag;
		}
Example #18
0
		void EncodeAttributeValue (char[] value, int startIndex, int count)
		{
			if (WriterState != HtmlWriterState.Attribute)
				throw new InvalidOperationException ("Attribute values can only be written in the Attribute state.");

			html.Write ('=');
			HtmlUtils.HtmlEncodeAttribute (html, value, startIndex, count);
			WriterState = HtmlWriterState.Tag;
		}