1<?php 2/** 3 * Mikio Syntax Plugin: TabGroup 4 * 5 * @link http://github.com/nomadjimbob/mikioplugin 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author James Collins <james.collins@outlook.com.au> 8 */ 9 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(__DIR__.'/core.php'); 13 14class syntax_plugin_mikioplugin_tabgroup extends syntax_plugin_mikioplugin_core { 15 public $tag = 'tab-group'; 16 public $hasEndTag = true; 17 public $options = array( 18 'pills' => array('type' => 'boolean', 'default' => 'false'), 19 ); 20 21 public function getAllowedTypes() { return array(); } 22 23 public function render_lexer_enter(Doku_Renderer $renderer, $data) { 24 $classes = $this->buildClass($data, array('pills')); 25 26 $renderer->doc .= '<ul class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-group' . $classes . '">'; 27 } 28 29 30 public function render_lexer_exit(Doku_Renderer $renderer, $data) { 31 32 } 33 34 35 public function render_lexer_unmatched(Doku_Renderer $renderer, $data) { 36 $items = []; 37 $bar = ''; 38 $content = ''; 39 $first = true; 40 41 $tabOptions = array( 42 'title' => array('type' => 'text', 'default' => ''), 43 'disabled' => array('type' => 'boolean', 'default' => 'false'), 44 ); 45 46 $tabs = $this->findTags($this->tagPrefix . 'tab', $data, $tabOptions, true, array($this, 'normalizeTabContent')); 47 48 foreach($tabs as $tab) { 49 $classes = $this->buildClass($tab['options'], array('disabled')); 50 51 $bar .= '<li class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-item' . $classes . '"><a class="' . $this->elemClass . ($first ? ' mikiop-active' : '') . '" data-toggle="tab" href="#">' . $tab['options']['title'] . '</a></li>'; 52 $content .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-pane' . ($first ? ' mikiop-show' : '') . '"><p>' . $tab['content'] . '</p></div>'; 53 54 $first = false; 55 } 56 57 $renderer->doc .= $bar . '</ul><div class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-content">' . $content . '</div>'; 58 } 59 60 /** 61 * Remove the indentation that matches the opening <tab> line. 62 * 63 * This keeps source formatting aligned with the surrounding markup while 64 * preserving any extra indentation inside the tab body. 65 */ 66 protected function normalizeTabContent($content, $openingIndent = '') 67 { 68 $content = str_replace(array("\r\n", "\r"), "\n", (string)$content); 69 70 if ($content === '') { 71 return $content; 72 } 73 74 $lines = explode("\n", $content); 75 76 while (count($lines) > 0 && trim($lines[0]) === '') { 77 array_shift($lines); 78 } 79 80 while (count($lines) > 0 && trim($lines[count($lines) - 1]) === '') { 81 array_pop($lines); 82 } 83 84 if (count($lines) === 0) { 85 return ''; 86 } 87 88 if ($openingIndent !== '') { 89 $indentLength = strlen($openingIndent); 90 91 foreach ($lines as &$line) { 92 if ($line !== '' && strncmp($line, $openingIndent, $indentLength) === 0) { 93 $line = substr($line, $indentLength); 94 } 95 } 96 unset($line); 97 } 98 99 return implode("\n", $lines); 100 } 101} 102?> 103