Ejemplo n.º 1
0
		/// <summary>
		/// Finds and encode codes within "script" tag.
		/// </summary>
		public static void ReplaceScriptTagCodes(ref string htmlCode)
		{
			const string scriptStart = "<script";
			const string scriptEnd = "</script>";
			const string htmlTagEnd = ">";
			TextRange position;
			int index = 0;

			do
			{
				string scriptContent = "";

				// Find script tag position start
				position.Start = StringCompare.IndexOfIgnoreCase(ref htmlCode, scriptStart, index);
				if (position.Start == -1)
					break;

				// locate tag end
                position.Start = StringCompare.IndexOfMatchCase(ref htmlCode, htmlTagEnd, position.Start);
				if (position.Start == -1)
					break;
				position.Start++;

				// Locate end tag
                position.End = StringCompare.IndexOfIgnoreCase(ref htmlCode, scriptEnd, position.Start);
				if (position.End == -1)
					break;

				// Set next searching start position
				index = position.End;

				// Get the content
				scriptContent = htmlCode.Substring(position.Start, position.End - position.Start);

				// If there is nothing, go to next tag
				if (scriptContent.Trim().Length == 0)
					continue;


				// Very bad use of processor, But there is no other way to do!
				// Create a new instance of processor
				JSProcessor processor = new JSProcessor();

				// Process the script content
				processor.Execute(ref scriptContent,
                    null, null, null, null);


				// Replace the new style
				htmlCode = htmlCode.Remove(position.Start, position.End - position.Start);
				htmlCode = htmlCode.Insert(position.Start, scriptContent);

			} while (index != -1);

		}
Ejemplo n.º 2
0
        /// <summary>
        /// Finds and encode codes within "script" tag.
        /// </summary>
        public static void ReplaceScriptTagCodes(ref string htmlCode)
        {
            const string scriptStart = "<script";
            const string scriptEnd   = "</script>";
            const string htmlTagEnd  = ">";
            TextRange    position;
            int          index = 0;

            do
            {
                string scriptContent = "";

                // Find script tag position start
                position.Start = StringCompare.IndexOfIgnoreCase(ref htmlCode, scriptStart, index);
                if (position.Start == -1)
                {
                    break;
                }

                // locate tag end
                position.Start = StringCompare.IndexOfMatchCase(ref htmlCode, htmlTagEnd, position.Start);
                if (position.Start == -1)
                {
                    break;
                }
                position.Start++;

                // Locate end tag
                position.End = StringCompare.IndexOfIgnoreCase(ref htmlCode, scriptEnd, position.Start);
                if (position.End == -1)
                {
                    break;
                }

                // Set next searching start position
                index = position.End;

                // Get the content
                scriptContent = htmlCode.Substring(position.Start, position.End - position.Start);

                // If there is nothing, go to next tag
                if (scriptContent.Trim().Length == 0)
                {
                    continue;
                }


                // Very bad use of processor, But there is no other way to do!
                // Create a new instance of processor
                JSProcessor processor = new JSProcessor();

                // Process the script content
                processor.Execute(ref scriptContent,
                                  null, null, null, null);


                // Replace the new style
                htmlCode = htmlCode.Remove(position.Start, position.End - position.Start);
                htmlCode = htmlCode.Insert(position.Start, scriptContent);
            } while (index != -1);
        }