From f77eb26910e01deb2f4ce8fa0d5241d6bb8239bf Mon Sep 17 00:00:00 2001 From: Jakob Wandel Date: Tue, 29 May 2018 15:18:10 +0200 Subject: [PATCH 1/2] Added the possibility to give a table cell a border: Old syntax: |@#00ff00: cellcontent | -> would format the tablecell background green New syntax: |@#00ff00[]: cellcontent | -> adding a [] would draw a border around the cell --- syntax.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/syntax.php b/syntax.php index 7cfd30d..63a7a11 100644 --- a/syntax.php +++ b/syntax.php @@ -49,7 +49,7 @@ function getSort(){ return 200; } // Connect pattern to lexer function connectTo($mode) { - $this->Lexer->addSpecialPattern('^@#?[0-9a-zA-Z]*:(?=[^\n]*\|[[:space:]]*\n)',$mode,'plugin_cellbg'); + $this->Lexer->addSpecialPattern('^@#?[0-9a-zA-Z[\]]*:(?=[^\n]*\|[[:space:]]*\n)',$mode,'plugin_cellbg'); } function postConnect() { //$this->Lexer->addExitPattern(':','plugin_cellbg'); @@ -69,11 +69,24 @@ function handle($match, $state, $pos, &$handler){ case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : - preg_match("/@([^:]*)/", $match, $color); // get the color - if ( $this->_isValid($color[1]) ) return array($state, $color[1], $match); + preg_match("/@([^:]*)/", $match, $color); // get the color + $color[2] = str_replace("[]","",$color[1]); + if($color[2] == $color[1]){//kein border + if ( $this->_isValid($color[2]) ){ + return array($state, $color[2], $match); + }else{ + return array($state, "transparent", $match); + } + }else{ //with border + if ( $this->_isValid($color[1]) ){ + return array($state, "|".$color[2], $match); + }else{ + return array($state, "|transparent", $match); + } + } break; } - return array($state, "yellow", $match); + return array($state, "transparent", $match); } // Create output @@ -92,7 +105,13 @@ function render($mode, &$renderer, $data) { break; case DOKU_LEXER_SPECIAL : if (preg_match('/(]*)>[[:space:]]*$/', $renderer->doc) != 0) { - $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 bgcolor='.$color.'>', $renderer->doc); + $htmlBorder = ''; + $color_withoutBorder = str_replace("|","",$color); + if($color_withoutBorder != $color){ + $htmlBorder = ' style="border: 2px solid black;"'; + } + + $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 bgcolor='.$color_withoutBorder.$htmlBorder.'>', $renderer->doc); } else { $renderer->doc .= $text; } From 34a61b6c5fac6f3b7faebcdecd2b0e9ecd47d665 Mon Sep 17 00:00:00 2001 From: Jakob Wandel Date: Tue, 29 May 2018 15:28:47 +0200 Subject: [PATCH 2/2] Updated README --- README | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README b/README index 27dcfcb..c81f8a7 100644 --- a/README +++ b/README @@ -1,2 +1,13 @@ This is a plugin for dokuwiki. It will enable syntax to set cell background in tables. +It also can create borders around a cell: +Examples: + +| @#0000ff: cellcontent | -> blue cell background +| @transparent: cellcontent | -> transparent cell background +| @#00ff00[]: cellcontent | ->green cell background AND Border around cell + +To install this plugin: +1. Download this repro as zip +2. Go into Dokuwiki as admin +3. Install plugin manually -> select downloaded zip file