Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php	(revision 10589)
+++ wp-includes/script-loader.php	(working copy)
@@ -377,7 +377,8 @@
 
 		$scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable', 'jquery-ui-resizable' ), '20090113' );
 		$scripts->add_data( 'media', 'group', 1 );
-
+		
+		$scripts->add( 'codepress', '/wp-includes/js/codepress/codepress.js', false, '0.9.6' );
 	}
 }
 
Index: wp-admin/includes/misc.php
===================================================================
--- wp-admin/includes/misc.php	(revision 10589)
+++ wp-admin/includes/misc.php	(working copy)
@@ -238,4 +238,46 @@
 	echo "<p>$message</p>\n";
 }
 
+/**
+ * Determines the language to use for CodePress syntax highlighting,
+ * based only on a filename.
+ * 
+ * @since 2.8
+ * 
+ * @param string $filename The name of the file to be highlighting
+**/
+function codepress_get_lang( $filename ) {
+	$codepress_supported_langs = apply_filters( 'codepress_supported_langs', 
+									array( 'css' => 'css',
+											'js' => 'javascript', 
+											'php' => 'php', 
+											'html' => 'html', 
+											'htm' => 'html', 
+											'txt' => 'text' 
+											) );
+	$extension = mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 );
+	return isset( $codepress_supported_langs[$extension] ) ? $codepress_supported_langs[$extension] : 'generic';
+}
+
+/**
+ * Adds Javascript required to make CodePress work on the theme/plugin editors.
+ * 
+ * This code is attached to the action admin_print_footer_scripts.
+ * 
+ * @since 2.8
+**/
+function codepress_footer_js() {
+	// Script-loader breaks CP's automatic path-detection, thus CodePress.path
+	// CP edits in an iframe, so we need to grab content back into normal form
+	?><script type="text/javascript">
+/* <![CDATA[ */
+CodePress.path = '<?php echo get_option('siteurl') ?>/wp-includes/js/codepress/';
+jQuery('#template').submit(function(){
+	jQuery('#newcontent_cp').val(newcontent.getCode()).removeAttr('disabled');
+});
+/* ]]> */
+</script>
+<?php
+}
+
 ?>
Index: wp-admin/theme-editor.php
===================================================================
--- wp-admin/theme-editor.php	(revision 10589)
+++ wp-admin/theme-editor.php	(working copy)
@@ -77,6 +77,8 @@
 	if ( !current_user_can('edit_themes') )
 		wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
 
+	wp_enqueue_script( 'codepress' );
+	add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
 	require_once('admin-header.php');
 
 	update_recently_edited($file);
@@ -88,6 +90,7 @@
 		$f = fopen($real_file, 'r');
 		$content = fread($f, filesize($real_file));
 		$content = htmlspecialchars($content);
+		$codepress_lang = codepress_get_lang($real_file);
 	}
 
 	?>
@@ -182,7 +185,7 @@
 	?>
 	<form name="template" id="template" action="theme-editor.php" method="post">
 	<?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
-		 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
+		 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
 		 <input type="hidden" name="action" value="update" />
 		 <input type="hidden" name="file" value="<?php echo $file ?>" />
 		 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
Index: wp-admin/plugin-editor.php
===================================================================
--- wp-admin/plugin-editor.php	(revision 10589)
+++ wp-admin/plugin-editor.php	(working copy)
@@ -74,6 +74,8 @@
 		exit;
 	}
 
+	wp_enqueue_script( 'codepress' );
+	add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
 	require_once('admin-header.php');
 
 	update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
@@ -81,8 +83,10 @@
 	if ( ! is_file($real_file) )
 		$error = 1;
 
-	if ( ! $error )
+	if ( ! $error ) {
 		$content = htmlspecialchars(file_get_contents($real_file));
+		$codepress_lang = codepress_get_lang($real_file);
+	}
 
 	?>
 <?php if (isset($_GET['a'])) : ?>
@@ -131,7 +135,7 @@
 <?php	if ( ! $error ) { ?>
 	<form name="template" id="template" action="plugin-editor.php" method="post">
 	<?php wp_nonce_field('edit-plugin_' . $file) ?>
-		<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
+		<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
 		<input type="hidden" name="action" value="update" />
 		<input type="hidden" name="file" value="<?php echo $file ?>" />
 		</div>

