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 // xhtml以外のモードはスキップ 38 if ($mode != 'xhtml') { 39 return false; 40 } 41 static $mizarCounter = 0; // 一意のカウンターを追加 42 list($state,$filename, $content) = $data; 43 $mizarId = 'mizarBlock' . $mizarCounter; 44 $blockNumber = $mizarCounter + 1; // 表示用の番号 (1, 2, 3,...) 45 $mizarCounter++; // カウンターをインクリメント 46 47 if ($mode == 'xhtml') { 48 // ボタンやエディタのHTMLを生成 49 $renderer->doc .= '<div class="mizarWrapper" id="' . $mizarId . '">'; 50 $renderer->doc .= '<dl class="file">'; 51 $renderer->doc .= '<button class="copy-button" data-mizarid="' . $mizarId . '">Copy</button>'; 52 $renderer->doc .= '<button id="resetButton' . $mizarId . '" class="reset-button">Reset</button>'; 53 $renderer->doc .= '<button id="editButton' . $mizarId . '" class="edit-button">Edit</button>'; 54 $renderer->doc .= '<button id="compileButton' . $mizarId . '" class="compile-button">Compile</button>'; 55 $renderer->doc .= '<button id="hideButton' . $mizarId . '" class="hide-button">Hide</button>'; 56 $renderer->doc .= '<button id="graphButton' . $mizarId . '" class="graph-button">Graph</button>'; // ★追加 57 $renderer->doc .= '<button id="showButton' . $mizarId . '" class="show-button">Show</button>'; 58 59 $renderer->doc .= '<dt>' 60 . '<a href="#" onclick="createMizarFile(\'' . $filename . '\'); return false;" ' 61 . ' title="クリックしてコンテンツをダウンロード" class="file-download">' 62 . $filename. '(' . $blockNumber . ') ' 63 . '</a>' 64 . '</dt>'; 65 66 $renderer->doc .= '<dd><div class="editor-container" data-content="' . htmlspecialchars($content) . '"></div></dd>'; 67 $renderer->doc .= '</dl>'; 68 $renderer->doc .= '<div id="output' . $mizarId . '" class="output"></div>'; 69 $renderer->doc .= '<script type="module" src="' . DOKU_BASE . 'lib/plugins/mizarverifiabledocs/dist/script.js"></script>'; 70 $renderer->doc .= '</div>'; 71 } else { 72 $renderer->doc .= "<mizar $filename>$content</mizar>"; 73 } 74 return true; 75 } 76}