1ad615f37SSungbin Jeon<?php 2*73971cfeSSungbin Jeon/* 3*73971cfeSSungbin Jeon * This file is part of the clockoon/dokuwiki-commonmark-plugin package. 4*73971cfeSSungbin Jeon * 5*73971cfeSSungbin Jeon * (c) Sungbin Jeon <clockoon@gmail.com> 6*73971cfeSSungbin Jeon * 7*73971cfeSSungbin Jeon * Original code based on the followings: 8*73971cfeSSungbin Jeon * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane 9*73971cfeSSungbin Jeon * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com> 10*73971cfeSSungbin Jeon * 11*73971cfeSSungbin Jeon * For the full copyright and license information, please view the LICENSE 12*73971cfeSSungbin Jeon * file that was distributed with this source code. 13ad615f37SSungbin Jeon */ 148ec9a8f2SSungbin Jeon 158ec9a8f2SSungbin Jeon require_once __DIR__.'/src/bootstrap.php'; 168ec9a8f2SSungbin Jeon 178ec9a8f2SSungbin Jeon use Dokuwiki\Plugin\Commonmark\Commonmark; 18ad615f37SSungbin Jeon 19ad615f37SSungbin Jeon if(!defined('DOKU_INC')) die(); 20ad615f37SSungbin Jeon 21ad615f37SSungbin Jeon class action_plugin_commonmark extends DokuWiki_Action_Plugin { 22ad615f37SSungbin Jeon /** 23ad615f37SSungbin Jeon * pass text to Commonmark parser before DW parser 24ad615f37SSungbin Jeon */ 25ad615f37SSungbin Jeon public function register(Doku_Event_Handler $controller) { 26ad615f37SSungbin Jeon $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'BEFORE', $this, 27ad615f37SSungbin Jeon '_commonmarkparse'); 28ad615f37SSungbin Jeon } 29ad615f37SSungbin Jeon 30ad615f37SSungbin Jeon /** 31ad615f37SSungbin Jeon * Parse commonmark text 32ad615f37SSungbin Jeon * TEST: <!DOCTYPE markdown> to "PASSED!!" 33ad615f37SSungbin Jeon */ 34ad615f37SSungbin Jeon public function _commonmarkparse(Doku_Event $event, $param) { 35ad615f37SSungbin Jeon if (preg_match('/\A<!DOCTYPE markdown>/',$event->data)) { 368ec9a8f2SSungbin Jeon $event->data = Commonmark::RendtoDW(preg_replace('/\A<!DOCTYPE markdown>/','',$event->data)); 378ec9a8f2SSungbin Jeon #$event->data = "PASSED"; 38ad615f37SSungbin Jeon } 39ad615f37SSungbin Jeon 40ad615f37SSungbin Jeon } 41ad615f37SSungbin Jeon 42ad615f37SSungbin Jeon}