1<?php 2/** 3 * Bootstrap Wrapper Plugin: Text 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 7 * @copyright (C) 2015-2020, Giuseppe Di Terlizzi 8 */ 9 10class syntax_plugin_bootswrapper_text extends syntax_plugin_bootswrapper_bootstrap 11{ 12 13 public $p_type = 'normal'; 14 public $pattern_start = '<(?:TEXT|text).*?>(?=.*?</(?:TEXT|text)>)'; 15 public $pattern_end = '</(?:TEXT|text)>'; 16 public $tag_name = 'text'; 17 public $tag_attributes = array( 18 19 'type' => array( 20 'type' => 'string', 21 'values' => array('muted', 'primary', 'success', 'info', 'warning', 'danger'), 22 'required' => false, 23 'default' => null), 24 25 'size' => array( 26 'type' => 'string', 27 'values' => null, 28 'required' => false, 29 'default' => null), 30 31 'background' => array( 32 'type' => 'string', 33 'values' => array('primary', 'success', 'info', 'warning', 'danger'), 34 'required' => false, 35 'default' => null), 36 37 'align' => array( 38 'type' => 'string', 39 'values' => array('left', 'center', 'right', 'justify', 'nowrap'), 40 'required' => false, 41 'default' => null), 42 43 'transform' => array( 44 'type' => 'string', 45 'values' => array('lowercase', 'uppercase', 'capitalize'), 46 'required' => false, 47 'default' => null), 48 49 ); 50 51 public function render($mode, Doku_Renderer $renderer, $data) 52 { 53 54 if (empty($data)) { 55 return false; 56 } 57 58 if ($mode !== 'xhtml') { 59 return false; 60 } 61 62 /** @var Doku_Renderer_xhtml $renderer */ 63 list($state, $match, $pos, $attributes, $is_block) = $data; 64 65 global $text_tag; 66 67 if ($state == DOKU_LEXER_ENTER) { 68 $text_tag = (($is_block) ? 'div' : 'span'); 69 $color = (isset($attributes['type']) ? $attributes['type'] : null); 70 $size = (isset($attributes['size']) ? $attributes['size'] : null); 71 $background = (isset($attributes['background']) ? $attributes['background'] : null); 72 $align = (isset($attributes['align']) ? $attributes['align'] : null); 73 $transform = (isset($attributes['transform']) ? $attributes['transform'] : null); 74 75 $classes = array(); 76 $styles = array(); 77 78 $classes[] = 'bs-wrap'; 79 $classes[] = 'bs-wrap-text'; 80 $classes[] = 'text'; 81 82 if ($align && $is_block) { 83 $classes[] = "text-$align"; 84 } 85 86 if ($color) { 87 $classes[] = "text-$color"; 88 } 89 90 if ($transform) { 91 $classes[] = "text-$transform"; 92 } 93 94 if ($background) { 95 $classes[] = "bg-$background"; 96 } 97 98 if ($size) { 99 if (strtolower($size) == 'small') { 100 $classes[] = 'small'; 101 } else { 102 $styles['font-size'] = $size; 103 } 104 } 105 106 $text_attributes = $this->buildAttributes(array( 107 'class' => $classes, 108 'style' => $styles 109 )); 110 111 $markup = "<$text_tag $text_attributes>"; 112 113 $renderer->doc .= $markup; 114 return true; 115 } 116 117 if ($state == DOKU_LEXER_EXIT) { 118 $renderer->doc .= "</$text_tag>"; 119 return true; 120 } 121 122 return true; 123 } 124} 125