1<?php 2// SPDX-License-Identifier: GPL-2.0-or-later 3// SPDX-FileCopyrightText: 2024-2025 Yamada, M. 4// DokuWiki Plugin Mizar Verifiable Docs (Syntax Component) 5 6class syntax_plugin_mizarverifiabledocs extends \dokuwiki\Extension\SyntaxPlugin { 7 /** @inheritDoc */ 8 public function getType() { 9 return 'substition'; 10 } 11 12 /** @inheritDoc */ 13 public function getPType() { 14 return 'block'; 15 } 16 17 /** @inheritDoc */ 18 public function getSort() { 19 return 195; 20 } 21 22 /** @inheritDoc */ 23 public function connectTo($mode) { 24 $this->Lexer->addSpecialPattern('<mizar\s+[^>]+>.*?</mizar>', $mode, 'plugin_mizarverifiabledocs'); 25 } 26 27 public function handle($match, $state, $pos, Doku_Handler $handler) { 28 preg_match('/<mizar\s+([^>]+)>(.*?)<\/mizar>/s', $match, $matches); 29 $filename = htmlspecialchars(trim($matches[1])); 30 $content = htmlspecialchars(trim($matches[2])); 31 return array($state, $filename, $content); 32 } 33 34 public function render($mode, Doku_Renderer $renderer, $data) { 35 // xhtml以外のモードはスキップ 36 if ($mode != 'xhtml') { 37 return false; 38 } 39 static $mizarCounter = 0; // 一意のカウンターを追加 40 list($state,$filename, $content) = $data; 41 $mizarId = 'mizarBlock' . $mizarCounter; 42 $blockNumber = $mizarCounter + 1; // 表示用の番号 (1, 2, 3,...) 43 $mizarCounter++; // カウンターをインクリメント 44 45 if ($mode == 'xhtml') { 46 // ボタンやエディタのHTMLを生成 47 $renderer->doc .= '<div class="mizarWrapper" id="' . $mizarId . '">'; 48 $renderer->doc .= '<dl class="file">'; 49 $renderer->doc .= '<button class="copy-button" data-mizarid="' . $mizarId . '">Copy</button>'; 50 $renderer->doc .= '<button id="resetButton' . $mizarId . '" class="reset-button">Reset</button>'; 51 $renderer->doc .= '<button id="editButton' . $mizarId . '" class="edit-button">Edit</button>'; 52 $renderer->doc .= '<button id="compileButton' . $mizarId . '" class="compile-button">Compile</button>'; 53 $renderer->doc .= '<button id="hideButton' . $mizarId . '" class="hide-button">Hide</button>'; 54 $renderer->doc .= '<button id="graphButton' . $mizarId . '" class="graph-button">Graph</button>'; // ★追加 55 $renderer->doc .= '<button id="showButton' . $mizarId . '" class="show-button">Show</button>'; 56 57 $renderer->doc .= '<dt>' 58 . '<a href="#" onclick="createMizarFile(\'' . $filename . '\'); return false;" ' 59 . ' title="クリックしてコンテンツをダウンロード" class="file-download">' 60 . $filename. '(' . $blockNumber . ') ' 61 . '</a>' 62 . '</dt>'; 63 64 $renderer->doc .= '<dd><div class="editor-container" data-content="' . htmlspecialchars($content) . '"></div></dd>'; 65 $renderer->doc .= '</dl>'; 66 $renderer->doc .= '<div id="output' . $mizarId . '" class="output"></div>'; 67 $renderer->doc .= '<script type="module" src="' . DOKU_BASE . 'lib/plugins/mizarverifiabledocs/dist/script.js"></script>'; 68 $renderer->doc .= '</div>'; 69 } else { 70 $renderer->doc .= "<mizar $filename>$content</mizar>"; 71 } 72 return true; 73 } 74} 75