1ad615f37SSungbin Jeon<?php 273971cfeSSungbin Jeon/* 373971cfeSSungbin Jeon * This file is part of the clockoon/dokuwiki-commonmark-plugin package. 473971cfeSSungbin Jeon * 573971cfeSSungbin Jeon * (c) Sungbin Jeon <clockoon@gmail.com> 673971cfeSSungbin Jeon * 773971cfeSSungbin Jeon * Original code based on the followings: 873971cfeSSungbin Jeon * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane 973971cfeSSungbin Jeon * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com> 1073971cfeSSungbin Jeon * 1173971cfeSSungbin Jeon * For the full copyright and license information, please view the LICENSE 1273971cfeSSungbin 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 public function _commonmarkparse(Doku_Event $event, $param) { 31532432a2SSungbin Jeon // check force_commonmark option; if 1, ignore doctype 32532432a2SSungbin Jeon if ($this->getConf('force_commonmark')) { 33*7569cca4SSungbin Jeon $markdown = ltrim($event->data); 34*7569cca4SSungbin Jeon $event->data = Commonmark::RendtoDW($markdown, $this->getConf('frontmatter_tag')); 35532432a2SSungbin Jeon } 36532432a2SSungbin Jeon elseif (preg_match('/\A<!DOCTYPE markdown>/',$event->data)) { 374384789bSSungbin Jeon $markdown = preg_replace('/\A<!DOCTYPE markdown>\n/','',$event->data); 38*7569cca4SSungbin Jeon $markdown = ltrim($markdown); 39*7569cca4SSungbin Jeon $event->data = Commonmark::RendtoDW($markdown, $this->getConf('frontmatter_tag')); 40ad615f37SSungbin Jeon } 41ad615f37SSungbin Jeon } 42ad615f37SSungbin Jeon} 43