xref: /plugin/commonmark/src/Dokuwiki/Plugin/Commonmark/Commonmark.php (revision 8ec9a8f2fa8d03e80395a040a2626880092b4ddf)
1*8ec9a8f2SSungbin Jeon<?php
2*8ec9a8f2SSungbin Jeon
3*8ec9a8f2SSungbin Jeonnamespace Dokuwiki\Plugin\Commonmark;
4*8ec9a8f2SSungbin Jeon
5*8ec9a8f2SSungbin Jeonuse League\CommonMark\Environment;
6*8ec9a8f2SSungbin Jeonuse League\CommonMark\DocParser;
7*8ec9a8f2SSungbin Jeonuse Dokuwiki\Plugin\Commonmark\Extension\CommonMarkToDokuWikiExtension;
8*8ec9a8f2SSungbin Jeon
9*8ec9a8f2SSungbin Jeonclass Commonmark {
10*8ec9a8f2SSungbin Jeon    public static function RendtoDW($markdown): string {
11*8ec9a8f2SSungbin Jeon        # create environment
12*8ec9a8f2SSungbin Jeon        $environment = self::createDWEnvironment();
13*8ec9a8f2SSungbin Jeon
14*8ec9a8f2SSungbin Jeon        # create parser
15*8ec9a8f2SSungbin Jeon        $parser = new DocParser($environment);
16*8ec9a8f2SSungbin Jeon        # create Dokuwiki Renderer
17*8ec9a8f2SSungbin Jeon        $DWRenderer = new DWRenderer($environment);
18*8ec9a8f2SSungbin Jeon
19*8ec9a8f2SSungbin Jeon        $document = $parser->parse($markdown);
20*8ec9a8f2SSungbin Jeon        return $DWRenderer->renderBlock($document);
21*8ec9a8f2SSungbin Jeon    }
22*8ec9a8f2SSungbin Jeon
23*8ec9a8f2SSungbin Jeon    public static function createDWEnvironment(): Environment {
24*8ec9a8f2SSungbin Jeon        $environment = new Environment();
25*8ec9a8f2SSungbin Jeon        $environment->addExtension(new CommonMarkToDokuWikiExtension());
26*8ec9a8f2SSungbin Jeon
27*8ec9a8f2SSungbin Jeon        return $environment;
28*8ec9a8f2SSungbin Jeon    }
29*8ec9a8f2SSungbin Jeon}
30*8ec9a8f2SSungbin Jeon
31*8ec9a8f2SSungbin Jeon?>