Index: src/wp-includes/formatting.php
===================================================================
--- src/wp-includes/formatting.php	(revision 27803)
+++ src/wp-includes/formatting.php	(working copy)
@@ -200,38 +200,23 @@
  * @return string Text which has been converted into correct paragraph tags.
  */
 function wpautop($pee, $br = true) {
-	$pre_tags = array();
-
 	if ( trim($pee) === '' )
 		return '';
 
 	$pee = $pee . "\n"; // just to make things a little easier, pad the end
 
-	if ( strpos($pee, '<pre') !== false ) {
-		$pee_parts = explode( '</pre>', $pee );
-		$last_pee = array_pop($pee_parts);
-		$pee = '';
-		$i = 0;
+	// Pull out pre tags and add placeholders
+	$pre_result = _wpautop_add_tag_placeholders( $pee, 'pre' );
+	$pee = $pre_result['pee'];
+	$pre_tags = $pre_result['tags'];
+	unset( $pre_result );
 
-		foreach ( $pee_parts as $pee_part ) {
-			$start = strpos($pee_part, '<pre');
+	// Pull out script tags and add placeholders
+	$script_result = _wpautop_add_tag_placeholders( $pee, 'script' );
+	$pee = $script_result['pee'];
+	$script_tags = $script_result['tags'];
+	unset( $script_result );
 
-			// Malformed html?
-			if ( $start === false ) {
-				$pee .= $pee_part;
-				continue;
-			}
-
-			$name = "<pre wp-pre-tag-$i></pre>";
-			$pre_tags[$name] = substr( $pee_part, $start ) . '</pre>';
-
-			$pee .= substr( $pee_part, 0, $start ) . $name;
-			$i++;
-		}
-
-		$pee .= $last_pee;
-	}
-
 	$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
 	// Space things out a little
 	$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
@@ -281,13 +266,78 @@
 	$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
 	$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
 
-	if ( !empty($pre_tags) )
-		$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
+	$pee = _wpautop_replace_tag_placeholders( $pee, $pre_tags );
+	$pee = _wpautop_replace_tag_placeholders( $pee, $script_tags );
 
 	return $pee;
 }
 
 /**
+ * Searches the provided text for the specified tags and adds placeholders in their place.
+ *
+ * Example: If 'pre' is provided as tag, anything between <pre> and </pre>, including the tags themselves would be
+ * replaced with a placeholder. The placeholder and the original value will then be added to the $tags array.
+ *
+ * The function returns an array with two keys, 'pee' and 'tags'. 'pee' contains the original $pee text, except with
+ * placeholders in place of the tags. 'tags' is an array where the array key is the placeholder and the array value is
+ * what was replaced by the placeholder.
+ *
+ * @param string $pee The text which has to be formatted.
+ * @param string $tag The tag to replace with placeholders.
+ *
+ * @return array Returns an array containing 'pee' and 'tags'
+ */
+function _wpautop_add_tag_placeholders( $pee, $tag ) {
+	$tags = array();
+
+	if ( false !== strpos( $pee, "<{$tag}" ) ) {
+		$pee_parts = explode( "</{$tag}>", $pee );
+		$last_pee = array_pop( $pee_parts );
+		$pee = '';
+		$i = 0;
+
+		foreach ( $pee_parts as $pee_part ) {
+			$start = strpos( $pee_part, "<{$tag}" );
+
+			// Malformed html?
+			if ( false === $start ) {
+				$pee .= $pee_part;
+				continue;
+			}
+
+			$name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
+			$tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
+
+			$pee .= substr( $pee_part, 0, $start ) . $name;
+			$i++;
+		}
+
+		$pee .= $last_pee;
+	}
+
+	return array( 'pee' => $pee, 'tags' => $tags );
+}
+
+/**
+ * Replaces placeholders in $pee with their original values as specified in $tags.
+ *
+ * Designed to be used with _wpautop_add_tag_placeholders, this function replaces text in $pee by replacing each of the
+ * array keys in $tags with the corresponding array values.
+ *
+ * @param string $pee The text which has to be formatted.
+ * @param array $tags Values to search for and replace.
+ *
+ * @return string Text which has had all the placeholders specified in tags replaced with their original values.
+ */
+function _wpautop_replace_tag_placeholders( $pee, $tags ) {
+	if ( ! empty( $tags ) ) {
+		$pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
+	}
+
+	return $pee;
+}
+
+/**
  * Newline preservation help function for wpautop
  *
  * @since 3.1.0
Index: tests/phpunit/tests/formatting/Autop.php
===================================================================
--- tests/phpunit/tests/formatting/Autop.php	(revision 27803)
+++ tests/phpunit/tests/formatting/Autop.php	(working copy)
@@ -90,6 +90,28 @@
 	}
 
 	/**
+	 * wpautop() Should not alter the contents of "<script>" elements
+	 *
+	 * @ticket 2833
+	 */
+	public function test_skip_script_elements() {
+		$code = file_get_contents( DIR_TESTDATA . '/formatting/sizzle.js' );
+		$code = str_replace( "\r", '', $code );
+		$code = htmlentities( $code );
+
+		// Not wrapped in <p> tags
+		$str = "<p><script>$code</script></p>";
+		$this->assertEquals( $str, trim( wpautop( $str ) ) );
+
+		// Text before/after is wrapped in <p> tags
+		$str = "Look at this code\n\n<script>$code</script>\n\nIsn't that cool?";
+
+		// Expected text after wpautop
+		$expected = '<p>Look at this code</p>' . "\n<p><script>" . $code . "</script></p>\n" . '<p>Isn\'t that cool?</p>';
+		$this->assertEquals( $expected, trim( wpautop( $str ) ) );
+	}
+
+	/**
 	 * wpautop() Should not add <br/> to "<input>" elements
 	 *
 	 * @ticket 16456
