Index: misc/drupal.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/drupal.js,v
retrieving revision 1.58
diff -u -p -r1.58 drupal.js
--- misc/drupal.js	31 Aug 2009 05:51:07 -0000	1.58
+++ misc/drupal.js	23 Sep 2009 22:58:17 -0000
@@ -109,6 +109,29 @@ Drupal.checkPlain = function (str) {
 };
 
 /**
+ * Run input text through Drupal's text format system.
+ */
+Drupal.checkMarkup = function (input, format, langcode, cache) {
+  // Ajax POST request for autocompletion.
+  var url = Drupal.settings.basePath + 'js/filter/check-markup';
+  var output = '';
+  $.ajax({
+    type: 'POST',
+    url: location.protocol + '//' + location.host + url,
+    dataType: 'json',
+    async: false,
+    data: ({input : String(input), format : format, langcode : langcode, cache : cache}),
+    success: function (result) {
+      output = result;
+    },
+    error: function (xmlhttp) {
+      alert(Drupal.ajaxError(xmlhttp, url));
+    }
+  });
+  return output;
+};
+
+/**
  * Translate strings to the page language or a given language.
  *
  * See the documentation of the server-side t() function for further details.
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.291
diff -u -p -r1.291 filter.module
--- modules/filter/filter.module	20 Sep 2009 07:32:18 -0000	1.291
+++ modules/filter/filter.module	23 Sep 2009 22:58:17 -0000
@@ -130,10 +130,32 @@ function filter_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'filter.admin.inc',
   );
+  $items['js/filter/check-markup'] = array(
+    'page callback' => 'filter_js_check_markup',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
 /**
+ * AJAX callback for check_markup().
+ */
+function filter_js_check_markup() {
+  $input = $_POST['input'];
+  $format = isset($_POST['format']) ? $_POST['format'] : NULL;
+  $langcode = isset($_POST['langcode']) ? $_POST['langcode'] : '';
+  $cache = isset($_POST['cache']) ? $_POST['cache'] : TRUE;
+  
+  if (!filter_access($format)) {
+    return drupal_access_denied();
+  }
+  else {
+    drupal_json_output(check_markup($input, $format, $langcode, $cache));
+  }
+}
+
+/**
  * Access callback for deleting text formats.
  *
  * @param $format
