1<?php
2
3namespace Dokuwiki\Plugin\Commonmark;
4
5use League\CommonMark\Environment;
6use League\CommonMark\DocParser;
7use Dokuwiki\Plugin\Commonmark\Extension\CommonmarkToDokuwikiExtension;
8use Dokuwiki\Plugin\Commonmark\Extension\FootnoteToDokuwikiExtension;
9use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
10use Dokuwiki\Plugin\Commonmark\Extension\TableExtension;
11
12class Commonmark {
13    public static function RendtoDW($markdown): string {
14        # create environment
15        $environment = self::createDWEnvironment();
16
17        # create parser
18        $parser = new DocParser($environment);
19        # create Dokuwiki Renderer
20        $DWRenderer = new DWRenderer($environment);
21
22        $document = $parser->parse($markdown);
23        return $DWRenderer->renderBlock($document);
24    }
25
26    public static function createDWEnvironment(): Environment {
27        $environment = new Environment();
28        $environment->addExtension(new CommonMarkToDokuWikiExtension());
29        $environment->addExtension(new FootnoteToDokuwikiExtension());
30        $environment->addExtension(new StrikethroughExtension());
31        $environment->addExtension(new TableExtension());
32
33        $environment->mergeConfig([
34            'html_input' => 'strip',
35        ]);
36
37        return $environment;
38    }
39}
40
41?>