xref: /plugin/mizarverifiabledocs/syntax.php (revision 5cbf3a5300a651c7fd7958742a36e6290b0f78b2)
1<?php
2/**
3 * DokuWiki Plugin Mizar proof checker (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_mizarproofchecker 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_mizarproofchecker');
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 . '">'; // ラッパーdivを追加
44            $renderer->doc .= '<div id="copyMessage" class="copy-message">コンテンツがクリップボードにコピーされました。</div>';
45            $renderer->doc .= '<dl class="file">';
46            $renderer->doc .= '<button id="myEditorButton' . $mizarId . '" class="editor-button">Editor</button>';
47            $renderer->doc .= '<button id="verifyButton' . $mizarId . '" class="verify-button">mizf</button>';
48            $renderer->doc .= '<button id="clearButton' . $mizarId . '" class="clear-button">clear</button>';
49            $renderer->doc .= '<dt><a href="#" onclick="return copyToClipboard(\'' . $mizarId . '\');" title="クリックしてコンテンツをコピー" class="mediafile mf_miz clipboard-icon">' . $filename . '</a></dt>';
50            // エディタ用のコンテナを準備
51            $renderer->doc .= '<dd><div id="editorContainer' . $mizarId . '" 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/mizarproofchecker/dist/script.js"></script>';
55            $renderer->doc .= '</div>'; // ラッパーdivを閉じる
56        } else {
57            $renderer->doc .= "<mizar $filename>$content</mizar>";
58        }
59        return true;
60    }
61}