Index: trunk/lib/SpellCheck.inc.php
===================================================================
--- trunk/lib/SpellCheck.inc.php	(revision 502)
+++ trunk/lib/SpellCheck.inc.php	(revision 503)
@@ -4,5 +4,5 @@
  * For details visit the project site: <http://trac.strangecode.com/codebase/>
  * Copyright 2001-2012 Strangecode, LLC
- * 
+ *
  * This file is part of The Strangecode Codebase.
  *
@@ -11,10 +11,10 @@
  * Free Software Foundation, either version 3 of the License, or (at your option)
  * any later version.
- * 
+ *
  * The Strangecode Codebase is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
@@ -141,5 +141,5 @@
     {
         $app =& App::getInstance();
-    
+
         if (array_key_exists($param, $this->_params)) {
             return $this->_params[$param];
@@ -267,11 +267,11 @@
     {
         $corrections = array();
-        // Split words on punctuation except apostrophes
+        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
         // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
-        $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}-ââ]+|(\+|(\p{P}+$))/", $string);
-        // Remove non-word elements.
-        $words = preg_grep('/\w+/', $words);
-
+        $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
         if (is_array($words) && !empty($words)) {
+            // Remove non-word elements.
+            $words = preg_grep('/\w+/', $words);
+            $words = array_map('strip_tags', $words);
             foreach ($words as $i => $word) {
                 if (!$this->check($word)) {
@@ -303,10 +303,12 @@
     {
         $errors = array();
-        $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
-        // Remove non-word elements.
-        $check_words = preg_grep('/\w+/', $words);
-
-        if (is_array($check_words) && !empty($check_words)) {
-            foreach ($check_words as $i => $word) {
+        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
+        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
+        $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
+        if (is_array($words) && !empty($words)) {
+            // Remove non-word elements.
+            $words = preg_grep('/\w+/', $words);
+            $words = array_map('strip_tags', $words);
+            foreach ($words as $i => $word) {
                 if (!$this->check($word)) {
                     $errors[] = $word;
@@ -334,16 +336,20 @@
     public function getStringHighlighted($string, $show_footnote=false)
     {
-        $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
-        $check_words = preg_grep('/\w+/', $words);
+        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
+        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
+        $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
         $cnt = 0;
-        if (is_array($check_words) && !empty($check_words)) {
-            foreach ($check_words as $i => $word) {
+        if (is_array($words) && !empty($words)) {
+            $words = preg_grep('/\w+/', $words);
+            $words = array_map('strip_tags', $words);
+            foreach ($words as $i => $word) {
                 if (!$this->check($word)) {
-                    $footnote = $show_footnote ? '<sup>' . ++$cnt . '</sup>' : '';
-                    $words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote;
+                    $footnote = $show_footnote ? '<sup style="color:#999;">' . ++$cnt . '</sup>' : '';
+                	$words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote;
+                    $string = preg_replace(sprintf('/\b%s\b/', preg_quote($word, '/')), $words[$i], $string);
                 }
             }
         }
-        return join('', $words);
+        return $string;
     }
 
@@ -361,5 +367,5 @@
     {
         ?>
-        <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo getFormData($form_name) ?>" />
+        <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo oTxt(getFormData($form_name)) ?>" />
         <?php
 
@@ -370,5 +376,6 @@
                 ?>
                 <li>
-                <select name="spelling_suggestions[<?php echo $form_name ?>][<?php echo $i ?>]" onchange"document.forms[0].elements['spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]'].value = this.value;">
+                <label style="color:#999;"><sub style="vertical-align:text-top;"><?php echo $j++; ?></sub></label>
+                <select name="spelling_suggestions[<?php echo $form_name ?>][<?php echo $i ?>]" onchange="document.forms[0].elements['spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]'].value = this.value;">
                 <?php $original_word = array_shift($words); ?>
                 <option value="<?php echo $original_word ?>">(<?php echo $original_word ?>)</option>
@@ -383,5 +390,5 @@
                 ?>
                 </select>
-                <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo $original_word ?>" class="sc-small" />
+                <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo oTxt($original_word) ?>" size="20">
                 <?php if ($this->_use_personal_wordlist) { ?>
                 <input name="save_to_personal_wordlist[]" type="checkbox" value="<?php echo $i ?>" /><?php echo _("Learn spelling") ?>
@@ -420,5 +427,7 @@
     public function applyFormCorrections($form_name)
     {
-        $form_words = preg_split('/([\W]+?)/', getFormData($form_name), -1, PREG_SPLIT_DELIM_CAPTURE);
+        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
+        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
+        $form_words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", getFormData($form_name), -1, PREG_SPLIT_DELIM_CAPTURE);
         $suggestions = getFormData('spelling_suggestions');
         $corrections = getFormData('spelling_corrections');
