add contents
BIN
lib/plugins/color/images/picker_blue_gray.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_gold.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_green.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_lavender.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_light_gray.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_light_turquoise.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_light_yellow.png
Normal file
After Width: | Height: | Size: 134 B |
BIN
lib/plugins/color/images/picker_lime.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_orange.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_red.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_rose.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_turquoise.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
lib/plugins/color/images/picker_yellow.png
Normal file
After Width: | Height: | Size: 155 B |
BIN
lib/plugins/color/images/toolbar_icon.png
Normal file
After Width: | Height: | Size: 385 B |
7
lib/plugins/color/plugin.info.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
base color
|
||||
author Harald Hanche-Olsen
|
||||
email harald.hanche-olsen@ntnu.no
|
||||
date 2018-10-12
|
||||
name color syntax plugin
|
||||
desc Write colored text in DokuWiki.
|
||||
url https://www.dokuwiki.org/plugin:color
|
91
lib/plugins/color/script.js
Normal file
@@ -0,0 +1,91 @@
|
||||
/* JavaScript function to create color toolbar in Dokuwiki */
|
||||
/* see http://www.dokuwiki.org/plugin:color for more info */
|
||||
|
||||
color_icobase = "../../plugins/color/images/";
|
||||
|
||||
if(window.toolbar != undefined) {
|
||||
toolbar[toolbar.length] = {
|
||||
"type":"picker",
|
||||
"title":"Color Text",
|
||||
"icon":color_icobase+"toolbar_icon.png",
|
||||
"list":[{
|
||||
"type":"format",
|
||||
"title":"Gray Colored Text",
|
||||
"icon":color_icobase+"picker_light_gray.png",
|
||||
"open":"<color #c3c3c3>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Rose Highlighted Text",
|
||||
"icon":color_icobase+"picker_rose.png",
|
||||
"open":"<color #ffaec9>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Red Highlighted Text",
|
||||
"icon":color_icobase+"picker_red.png",
|
||||
"open":"<color #ed1c24>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Orange Highlighted Text",
|
||||
"icon":color_icobase+"picker_orange.png",
|
||||
"open":"<color #ff7f27>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Gold Highlighted Text",
|
||||
"icon":color_icobase+"picker_gold.png",
|
||||
"open":"<color #ffc90e>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Yellow Highlighted Text",
|
||||
"icon":color_icobase+"picker_yellow.png",
|
||||
"open":"<color #fff200>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Light Yellow Highlighted Text",
|
||||
"icon":color_icobase+"picker_light_yellow.png",
|
||||
"open":"<color #efe4B0>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Green Highlighted Text",
|
||||
"icon":color_icobase+"picker_green.png",
|
||||
"open":"<color #22b14c>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Lime Highlighted Text",
|
||||
"icon":color_icobase+"picker_lime.png",
|
||||
"open":"<color #b5e61d>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Turquoise Highlighted Text",
|
||||
"icon":color_icobase+"picker_turquoise.png",
|
||||
"open":"<color #00a2e8>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Light Turquoise Highlighted Text",
|
||||
"icon":color_icobase+"picker_light_turquoise.png",
|
||||
"open":"<color #99d9ea>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Blue-Gray Highlighted Text",
|
||||
"icon":color_icobase+"picker_blue_gray.png",
|
||||
"open":"<color #7092be>",
|
||||
"close":"</color>"
|
||||
}, {
|
||||
"type":"format",
|
||||
"title":"Lavender Highlighted Text",
|
||||
"icon":color_icobase+"picker_lavender.png",
|
||||
"open":"<color #c8bfe7>",
|
||||
"close":"</color>"
|
||||
}]
|
||||
};
|
||||
}
|
116
lib/plugins/color/syntax.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Color: Sets new colors for text and background.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Christopher Smith <chris@jalakai.co.uk>
|
||||
*/
|
||||
|
||||
// must be run within DokuWiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
|
||||
require_once(DOKU_PLUGIN.'syntax.php');
|
||||
|
||||
/**
|
||||
* All DokuWiki plugins to extend the parser/rendering mechanism
|
||||
* need to inherit from this class
|
||||
*/
|
||||
class syntax_plugin_color extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
function getType(){ return 'formatting'; }
|
||||
function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
|
||||
function getSort(){ return 158; }
|
||||
function connectTo($mode) { $this->Lexer->addEntryPattern('<color.*?>(?=.*?</color>)',$mode,'plugin_color'); }
|
||||
function postConnect() { $this->Lexer->addExitPattern('</color>','plugin_color'); }
|
||||
|
||||
|
||||
/**
|
||||
* Handle the match
|
||||
*/
|
||||
function handle($match, $state, $pos, Doku_Handler $handler){
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_ENTER :
|
||||
list($color, $background) = preg_split("/\//u", substr($match, 6, -1), 2);
|
||||
if ($color = $this->_isValid($color)) $color = "color:$color;";
|
||||
if ($background = $this->_isValid($background)) $background = "background-color:$background;";
|
||||
return array($state, array($color, $background));
|
||||
|
||||
case DOKU_LEXER_UNMATCHED : return array($state, $match);
|
||||
case DOKU_LEXER_EXIT : return array($state, '');
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create output
|
||||
*/
|
||||
function render($mode, Doku_Renderer $renderer, $data) {
|
||||
if($mode == 'xhtml'){
|
||||
list($state, $match) = $data;
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_ENTER :
|
||||
list($color, $background) = $match;
|
||||
$renderer->doc .= "<span style='$color $background'>";
|
||||
break;
|
||||
|
||||
case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break;
|
||||
case DOKU_LEXER_EXIT : $renderer->doc .= "</span>"; break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if($mode == 'odt'){
|
||||
list($state, $match) = $data;
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_ENTER :
|
||||
list($color, $background) = $match;
|
||||
if (class_exists('ODTDocument')) {
|
||||
$renderer->_odtSpanOpenUseCSS (NULL, 'style="'.$color.$background.'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case DOKU_LEXER_UNMATCHED :
|
||||
$renderer->cdata($match);
|
||||
break;
|
||||
|
||||
case DOKU_LEXER_EXIT :
|
||||
if (class_exists('ODTDocument')) {
|
||||
$renderer->_odtSpanClose();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if($mode == 'metadata'){
|
||||
list($state, $match) = $data;
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_UNMATCHED :
|
||||
if ($renderer->capture) $renderer->cdata($match);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// validate color value $c
|
||||
// this is cut price validation - only to ensure there is nothing harmful
|
||||
// recognize rgb, rgba, hsl, hsla but don't try to valiedate their arguments,
|
||||
// just ensure that no illegal characters are included therein
|
||||
// and that the number of characters is reasonable
|
||||
// leave it to the browsers to ignore a faulty colour specification
|
||||
function _isValid($c) {
|
||||
$c = trim($c);
|
||||
|
||||
$pattern = "/^\s*(
|
||||
([a-zA-Z]+)| #colorname - not verified
|
||||
(\#([0-9a-fA-F]{3,8}))| #colorvalue including possible alpha
|
||||
((rgba?|hsla?)\([0-9%., ]{5,40}\)) #rgb[a], hsl[a]
|
||||
)\s*$/x";
|
||||
|
||||
if (preg_match($pattern, $c)) return trim($c);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
?>
|