You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

99 lines
3.1 KiB

  1. <?php
  2. /**
  3. *
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Myron Turner <turnermm02@shaw.ca>
  7. */
  8. // Syntax: <color somecolour/somebackgroundcolour>
  9. // must be run within Dokuwiki
  10. if(!defined('DOKU_INC')) die();
  11. if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  12. require_once(DOKU_PLUGIN.'syntax.php');
  13. /**
  14. * All DokuWiki plugins to extend the parser/rendering mechanism
  15. * need to inherit from this class
  16. */
  17. class syntax_plugin_ckgedit_font extends DokuWiki_Syntax_Plugin {
  18. function getType(){ return 'formatting'; }
  19. function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
  20. function getSort(){ return 158; }
  21. function connectTo($mode) { $this->Lexer->addEntryPattern('<font.*?>(?=.*?</font>)',$mode,'plugin_ckgedit_font'); }
  22. function postConnect() { $this->Lexer->addExitPattern('</font>','plugin_ckgedit_font'); }
  23. /**
  24. * Handle the match
  25. */
  26. function handle($match, $state, $pos, Doku_Handler $handler){
  27. switch ($state) {
  28. case DOKU_LEXER_ENTER :
  29. list($size, $face) = preg_split("/\//u", substr($match, 6, -1), 2);
  30. if(isset($size) && strpos($size,':') !== false) {
  31. list($size,$weight) = explode(':',$size);
  32. $size = "font-size:$size;";
  33. if(isset($weight) && $weight) {
  34. list($weight,$fstyle) = explode(',',$weight);
  35. $size .= " font-weight:$weight; ";
  36. if($fstyle) $size .= " font-style:$fstyle; ";
  37. }
  38. }
  39. else $size = "font-size:$size;";
  40. return array($state, array($size, $face));
  41. case DOKU_LEXER_UNMATCHED : return array($state, $match);
  42. case DOKU_LEXER_EXIT : return array($state, '');
  43. }
  44. return array();
  45. }
  46. /**
  47. * Create output
  48. */
  49. function render($mode, Doku_Renderer $renderer, $data) {
  50. if($mode == 'xhtml'){
  51. list($state, $match) = $data;
  52. switch ($state) {
  53. case DOKU_LEXER_ENTER :
  54. list($style, $face) = $match;
  55. if(isset($face)) {
  56. list($face,$fg,$bg) = explode(';;',$face);
  57. if(isset($fg)) {
  58. $color = " color: $fg; ";
  59. $style .= $color;
  60. }
  61. if(isset($bg)) {
  62. $color = " background-color: $bg ";
  63. $style .= $color;
  64. }
  65. }
  66. $style = "font-family: $face; $style";
  67. $renderer->doc .= "<span style='$style'>";
  68. break;
  69. case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break;
  70. case DOKU_LEXER_EXIT : $renderer->doc .= "</span>"; break;
  71. }
  72. return true;
  73. }
  74. return false;
  75. }
  76. }
  77. ?>