1<?php 2/** 3 * DokuWiki Plugin Mizar Verifiable Docs (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Yamada, M. <yamadam@mizar.work> 7 */ 8class syntax_plugin_mizarverifiabledocs extends \dokuwiki\Extension\SyntaxPlugin { 9 /** @inheritDoc */ 10 public function getType() { 11 return 'substition'; 12 } 13 14 /** @inheritDoc */ 15 public function getPType() { 16 return 'block'; 17 } 18 19 /** @inheritDoc */ 20 public function getSort() { 21 return 195; 22 } 23 24 /** @inheritDoc */ 25 public function connectTo($mode) { 26 $this->Lexer->addSpecialPattern('<mizar\s+[^>]+>.*?</mizar>', $mode, 'plugin_mizarverifiabledocs'); 27 } 28 29 public function handle($match, $state, $pos, Doku_Handler $handler) { 30 preg_match('/<mizar\s+([^>]+)>(.*?)<\/mizar>/s', $match, $matches); 31 $filename = htmlspecialchars(trim($matches[1])); 32 $content = htmlspecialchars(trim($matches[2])); 33 return array($state, $filename, $content); 34 } 35 36 public function render($mode, Doku_Renderer $renderer, $data) { 37 static $mizarCounter = 0; // 一意のカウンターを追加 38 list($state,$filename, $content) = $data; 39 $mizarId = 'mizarBlock' . $mizarCounter++; // 一意のIDを生成 40 41 if ($mode == 'xhtml') { 42 // ボタンやエディタのHTMLを生成 43 $renderer->doc .= '<div class="mizarWrapper" id="' . $mizarId . '">'; 44 $renderer->doc .= '<dl class="file">'; 45 $renderer->doc .= '<button class="copy-button" data-mizarid="' . $mizarId . '">Copy</button>'; 46 $renderer->doc .= '<button id="resetButton' . $mizarId . '" class="reset-button">Reset</button>'; 47 $renderer->doc .= '<button id="editButton' . $mizarId . '" class="edit-button">Edit</button>'; 48 $renderer->doc .= '<button id="compileButton' . $mizarId . '" class="compile-button">Compile</button>'; 49 50 $renderer->doc .= '<dt><a href="#" onclick="createMizarFile(\'' . $filename . '\'); return false;" title="クリックしてコンテンツをダウンロード" class="file-download">' . $filename . '</a></dt>'; 51 $renderer->doc .= '<dd><div class="editor-container" data-content="' . htmlspecialchars($content) . '"></div></dd>'; 52 $renderer->doc .= '</dl>'; 53 $renderer->doc .= '<div id="output' . $mizarId . '" class="output"></div>'; 54 $renderer->doc .= '<script type="text/javascript" src="' . DOKU_BASE . 'lib/plugins/mizarverifiabledocs/dist/script.js"></script>'; 55 $renderer->doc .= '</div>'; 56 } else { 57 $renderer->doc .= "<mizar $filename>$content</mizar>"; 58 } 59 return true; 60 } 61}