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