var $block_state;\r
var $list_state;\r
var $list_depth;\r
+ var $spelling_on;\r
var $list_backtrack;\r
var $output; // output buffer\r
\r
$bodge = chr(1);\r
$line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line );\r
\r
- $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]])';\r
+ $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)';\r
$replace = '\\1<'.$tag.'>\\2</'.$tag.'>\\3';\r
$line = eregi_replace( $regex, $replace, $line );\r
\r
$line = str_replace( "(TM)", "™", $line );\r
$line = str_replace( "(tm)", "™", $line );\r
$line = str_replace( "(C)", "©", $line );\r
- $line = str_replace( "(c)", "©", $line );\r
+ // $line = str_replace( "(c)", "©", $line );\r
$line = str_replace( "1/4", "¼", $line );\r
$line = str_replace( "1/2", "½", $line );\r
$line = str_replace( "3/4", "¾", $line );\r
$line = $this->do_replace_sub( $line, "~", "sub" );\r
$line = $this->do_replace_sub( $line, "\^", "sup" );\r
$line = $this->do_replace( $line, "\"", "q" );\r
- $line = $this->do_replace( $line, "'", "q" );\r
+ // $line = $this->do_replace( $line, "'", "q" );\r
$line = $this->do_replace( $line, "%", "code" );\r
$line = $this->do_replace( $line, "@", "cite" );\r
\r
return $line;\r
}\r
\r
+\r
+ function spellcheck( $line,$pspell_link ) {\r
+\r
+ // split line into words\r
+ $words = preg_split( "/[\s,-.]/ ", $line );\r
+\r
+ // run through words\r
+ $newline = "";\r
+ foreach($words as $word) {\r
+ $check_word = eregi_replace( "[,;:./&()* ?\"]", "", $word );\r
+ $check_word = eregi_replace( "^'|'$","",$check_word );\r
+\r
+ // words not to check\r
+ $docheck = true;\r
+ if (eregi("[0-9]",$check_word)) { $docheck=false; }\r
+\r
+ if ( $docheck && (!pspell_check( $pspell_link, $check_word)) ) {\r
+ $suggests = pspell_suggest( $pspell_link,$check_word );\r
+ $suggest_line = "";\r
+ foreach($suggests as $suggest) {\r
+ $suggest_line = $suggest_line . " " . $suggest;\r
+ }\r
+ $word = "<span class=\"spellcheck\"><acronym title=\"$suggest_line\">$word</acronym></span>";\r
+ }\r
+ $newline = $newline . " " . $word;\r
+ }\r
+\r
+ return $newline;\r
+ }\r
+\r
+\r
function format( $content ) {\r
// main entry point for processing TikiText\r
// $content is string containing text with Tiki formatting\r
$this->list_state = LIST_NONE;\r
$this->list_depth = 0;\r
$this->list_backtrack = array();\r
+ $this->spelling_on = false;\r
\r
// split content into array of single lines\r
$lines = explode( "\n",$content );\r
$this->block_state = STATE_NONE;\r
continue;\r
}\r
+\r
+ // is this a spelling line\r
+ $spell_parms = array();\r
+ $spelling = eregi( "^!SPELL:([a-z]+):?(american|british|canadian)?(\r| |$)", $line,$spell_parms );\r
+ if ($spelling) {\r
+ $this->spelling_on = true;\r
+ $pspell_link = pspell_new( $spell_parms[1], $spell_parms[2] );\r
+ $line = "";\r
+ }\r
+\r
+ // spellcheck\r
+ if ($this->spelling_on) {\r
+ $line = $this->spellcheck( $line, $pspell_link );\r
+ }\r
\r
// act now depending on current block state\r
if ($this->block_state == STATE_NONE) {\r
$this->block_state = STATE_NOTIKI;\r
} \r
else\r
- if (eregi("^Q. ",$line) ) {\r
+ if (eregi("^Q\. ",$line) ) {\r
// Question - para with a question class\r
$buffer = $buffer . "<p class=\"question\">\n";\r
$buffer = $buffer . eregi_replace( "^Q. ","",$line) . "\n";\r
$this->block_state = STATE_PARAGRAPH;\r
}\r
else\r
- if (eregi("^A. ",$line) ) {\r
+ if (eregi("^A\. ",$line) ) {\r
// Answer - para with an answer class\r
$buffer = $buffer . "<p class=\"answer\">\n";\r
$buffer = $buffer . eregi_replace( "^A. ","",$line ) . "\n";\r