summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-06-11 11:29:16 +0200
committerandi <andi@splitbrain.org>2005-06-11 11:29:16 +0200
commitea2eed85b6afedcf37443a4953bade0186b9aef2 (patch)
tree7f602365221428bfe8aee8a08e5cd0be367ade88 /lib
parent9af6e647b56056230f069dbb99935ae7402210fd (diff)
downloadrpg-ea2eed85b6afedcf37443a4953bade0186b9aef2.tar.gz
rpg-ea2eed85b6afedcf37443a4953bade0186b9aef2.tar.bz2
spellchecker fixes for Konqeror
Konqeror seems to ignore the charset darcs-hash:20050611092916-9977f-311b99e63b66a83c9f9022c468ba61d0687822c2.gz
Diffstat (limited to 'lib')
-rw-r--r--lib/exe/spellcheck.php24
-rw-r--r--lib/scripts/spellcheck.js16
2 files changed, 37 insertions, 3 deletions
diff --git a/lib/exe/spellcheck.php b/lib/exe/spellcheck.php
index ffa0e2886..6fa382a9c 100644
--- a/lib/exe/spellcheck.php
+++ b/lib/exe/spellcheck.php
@@ -104,12 +104,13 @@ function spell_check() {
$line = trim($lines[$i]);
if($line[0] == '@') continue; // comment
if($line[0] == '*') continue; // no mistake in this word
+ if($line[0] == '+') continue; // root of word was found
if(empty($line)){
// empty line -> new source line
$lcnt--;
continue;
}
- if(preg_match('/^& ([^ ]+) (\d+) (\d+): (.*)/',$line,$match)){
+ if(preg_match('/^[&\?] ([^ ]+) (\d+) (\d+): (.*)/',$line,$match)){
// match with suggestions
$word = $match[1];
$off = $match[3]-1;
@@ -131,6 +132,11 @@ function spell_check() {
$data[$lcnt] = utf8_substr_replace($data[$lcnt], spell_formatword($word) , $off, $len);
continue;
}
+ //still here - couldn't parse output
+ print '2';
+ print "The spellchecker output couldn't be parsed.\n";
+ print "Line $i:".$line;
+ return;
}
// the first char returns the spell info
@@ -140,7 +146,10 @@ function spell_check() {
$string = '0'.join('<br />',$data);
}
- //output
+ // encode multibyte chars as entities for broken Konqueror
+ $string = utf8_tohtml($string);
+
+ //output
print $string;
}
@@ -151,6 +160,11 @@ function spell_formatword($word,$suggestions=null){
//restrict to maximum of 7 elements
$suggestions = array_slice($suggestions,0,7);
$suggestions = array_map('htmlspecialchars',$suggestions);
+
+ //konqueror's broken UTF-8 handling needs this
+ $suggestions = array_map('utf8_tohtml',$suggestions);
+ $suggestions = array_map('urlencode',$suggestions);
+
$suggestions = array_map('addslashes',$suggestions);
$sug = ",'".join("','",$suggestions)."'"; //build javascript args
}else{
@@ -176,6 +190,12 @@ function spell_resume(){
// restore quoted special chars
$text = unhtmlspecialchars($text);
+ // but protect '&' (gets removed in JS later)
+ $text = str_replace('&','&amp;',$text);
+ // encode multibyte chars as entities for broken Konqueror
+ $text = utf8_tohtml($text);
+
+
// output
print $text;
}
diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js
index b5fa35e60..03ca9c364 100644
--- a/lib/scripts/spellcheck.js
+++ b/lib/scripts/spellcheck.js
@@ -262,7 +262,7 @@ function ajax_spell_class(){
}else{
for(var i=1; i<args.length; i++){
text += '<a href="javascript:ajax_spell.correct('+id+',\''+
- qquote(encodeURIComponent(args[i]))+'\')">';
+ qquote(args[i])+'\')">';
text += args[i];
text += '</a><br />';
}
@@ -290,6 +290,11 @@ function ajax_spell_class(){
data = data.substring(1);
if(error == '1'){
ajax_spell.setState('stop');
+ // convert numeric entities back to UTF-8
+ data = data.replace(/&#(\d+);/g,
+ function(whole,match1) {
+ return String.fromCharCode(+match1);
+ });
// replace textbox through div
ajax_spell.showboxObj.innerHTML = data;
ajax_spell.showboxObj.style.width = ajax_spell.textboxObj.style.width;
@@ -315,6 +320,15 @@ function ajax_spell_class(){
*/
this.stop = function(){
var data = this.response;
+
+ // convert numeric entities back to UTF-8
+ data = data.replace(/&#(\d+);/g,
+ function(whole,match1) {
+ return String.fromCharCode(+match1);
+ });
+ // now remove &amp; protection
+ data = data.replace(/&amp;/g,'&');
+
ajax_spell.setState('start');
// replace div with textbox again
ajax_spell.textboxObj.value = data;