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 // check force_commonmark option; if 1, ignore doctype 32 if ($this->getConf('force_commonmark')) { 33 $markdown = <<<MD 34 $event->data 35 MD; 36 $event->data = Commonmark::RendtoDW($markdown); 37 } 38 elseif (preg_match('/\A<!DOCTYPE markdown>/',$event->data)) { 39 $markdown = preg_replace('/\A<!DOCTYPE markdown>\n/','',$event->data); 40 $markdown = <<<MD 41 $markdown 42 MD; 43 $event->data = Commonmark::RendtoDW($markdown); 44 } 45 46 } 47} 48