このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
dokuwiki:plugin:color [2011/05/05 06:08] – 作成 matsui | dokuwiki:plugin:color [2014/12/08 06:40] (現在) – matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== color plugin ====== | ||
+ | colorタグでテキストをカラーにできる。 | ||
+ | <color red> | ||
+ | <color red> | ||
+ | |||
+ | ===== インストール ===== | ||
+ | pluginフォルダ内にsyntax.phpとcolornames.phpを作成 | ||
+ | # cd dokuwiki/ | ||
+ | # mkdir color | ||
+ | # vi color/ | ||
+ | |||
+ | * syntax.phpの中身 | ||
+ | |||
+ | <?php | ||
+ | /** | ||
+ | * Plugin Color: Sets new colors for text and background. | ||
+ | | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | // must be run within DokuWiki | ||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_color extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | var $odt_styles = array(); | ||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | function getType(){ return ' | ||
+ | function getAllowedTypes() { return array(' | ||
+ | function getSort(){ return 158; } | ||
+ | function connectTo($mode) { $this-> | ||
+ | function postConnect() { $this-> | ||
+ | |||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | switch ($state) { | ||
+ | case DOKU_LEXER_ENTER : | ||
+ | list($color, | ||
+ | $color = $this-> | ||
+ | $background = $this-> | ||
+ | return array($state, | ||
+ | |||
+ | case DOKU_LEXER_UNMATCHED : return array($state, | ||
+ | case DOKU_LEXER_EXIT : | ||
+ | } | ||
+ | return array(); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | */ | ||
+ | function render($mode, | ||
+ | if($mode == ' | ||
+ | list($state, | ||
+ | switch ($state) { | ||
+ | case DOKU_LEXER_ENTER : | ||
+ | list($color, | ||
+ | $color = $color?" | ||
+ | $background = $background?" | ||
+ | $renderer-> | ||
+ | break; | ||
+ | |||
+ | case DOKU_LEXER_UNMATCHED : $renderer-> | ||
+ | case DOKU_LEXER_EXIT : | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | if($mode == ' | ||
+ | list($state, | ||
+ | switch ($state) { | ||
+ | case DOKU_LEXER_ENTER : | ||
+ | list($color, | ||
+ | $style_index = $color.'/' | ||
+ | if(empty($this-> | ||
+ | { | ||
+ | $stylename = " | ||
+ | $this-> | ||
+ | $color = $color?' | ||
+ | $background = $background?' | ||
+ | $renderer-> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | } | ||
+ | $renderer-> | ||
+ | break; | ||
+ | |||
+ | case DOKU_LEXER_UNMATCHED : $renderer-> | ||
+ | case DOKU_LEXER_EXIT : | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | // validate color value $c | ||
+ | // this is cut price validation - only to ensure the basic format is correct and there is nothing harmful | ||
+ | // three basic formats | ||
+ | function _isValid($c) { | ||
+ | $c = trim($c); | ||
+ | |||
+ | $pattern = "/ | ||
+ | ([a-zA-z]+)| | ||
+ | (\# | ||
+ | (rgb\(([0-9]{1, | ||
+ | )\s*$/ | ||
+ | |||
+ | if (preg_match($pattern, | ||
+ | |||
+ | return ""; | ||
+ | } | ||
+ | /** | ||
+ | * Translate color names and RGB to hex values | ||
+ | */ | ||
+ | function _color2hex($name) | ||
+ | { | ||
+ | static $colornames = null; | ||
+ | if(is_null($colornames)) | ||
+ | { | ||
+ | include dirname(__FILE__).'/ | ||
+ | } | ||
+ | if(!preg_match('/ | ||
+ | return $colornames[$name]; | ||
+ | elseif(preg_match('/ | ||
+ | { | ||
+ | $colors = array(); | ||
+ | for($i=1; | ||
+ | { | ||
+ | $percent = substr($matches[$i], | ||
+ | $colors[$i] = $percent? | ||
+ | } | ||
+ | return sprintf('# | ||
+ | } | ||
+ | else | ||
+ | return $name; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | ?> | ||
+ | |||
+ | * colornames.phpの中身 | ||
+ | |||
+ | <?php | ||
+ | |||
+ | // HTML 4.01 color names | ||
+ | $colornames = array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | ?> | ||
+ | |||
+ | {{tag> |