Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature cell border, fixed default cell color #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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
29 changes: 24 additions & 5 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -92,7 +105,13 @@ function render($mode, &$renderer, $data) {
break;
case DOKU_LEXER_SPECIAL :
if (preg_match('/(<td[^<>]*)>[[:space:]]*$/', $renderer->doc) != 0) {
$renderer->doc = preg_replace('/(<td[^<>]*)>[[: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('/(<td[^<>]*)>[[:space:]]*$/', '\1 bgcolor='.$color_withoutBorder.$htmlBorder.'>', $renderer->doc);
} else {
$renderer->doc .= $text;
}
Expand Down