1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_markdown_info() { 9 return [ 10 'name' => tra('Markdown'), 11 'documentation' => 'PluginMarkdown', 12 'description' => tra('Parse the body of the plugin using a Markdown parser.'), 13 'prefs' => ['wikiplugin_markdown'], 14 'body' => tra('Markdown syntax to be parsed'), 15 'iconname' => 'code', 16 'introduced' => 20, 17 'filter' => 'rawhtml_unsafe', 18 'format' => 'html', 19 'tags' => [ 'advanced' ], 20 'params' => [ 21 // TODO: add some useful params here 22 ], 23 ]; 24} 25 26//use League\CommonMark\CommonMarkConverter; 27use League\CommonMark\Converter; 28 29// common requirement for extension packages 30use League\CommonMark\Environment; 31 32// requirement for league/commonmark-extras extension 33use League\CommonMark\Extras\CommonMarkExtrasExtension; 34 35// requirements for webuni/commonmark-attributes-extension 36use League\CommonMark\DocParser; 37use League\CommonMark\HtmlRenderer; 38use Webuni\CommonMark\AttributesExtension\AttributesExtension; 39 40function wikiplugin_markdown($data, $params) { 41 42 global $prefs; 43 44 extract($params, EXTR_SKIP); 45 46 $md = trim($data); 47 48 $md = str_replace('<x>', '', $md); 49 $md = str_replace('<x>', '', $md); 50 51 $environment = Environment::createCommonMarkEnvironment(); 52 53 // add commonmark-extras extension 54 $environment->addExtension(new CommonMarkExtrasExtension()); 55 56 // add commonmark-attributes-extension 57 $environment->addExtension(new AttributesExtension()); 58 59 // let's define our configuration 60 $environment->setConfig(['html_input' => 'escape', 'allow_unsafe_links' => false]); 61 62 $converter = new Converter(new DocParser($environment), new HtmlRenderer($environment)); 63 64 $md = $converter->convertToHtml($md); 65 66 # TODO: "if param wiki then" $md = TikiLib::lib('parser')->parse_data($md, ['is_html' => true, 'parse_wiki' => true]); 67 return $md; 68} 69