xref: /plugin/commonmark/src/Dokuwiki/Plugin/Commonmark/Commonmark.php (revision 656793f4f4cb30e58bac0947cd075702e4171396)
18ec9a8f2SSungbin Jeon<?php
28ec9a8f2SSungbin Jeon
38ec9a8f2SSungbin Jeonnamespace Dokuwiki\Plugin\Commonmark;
48ec9a8f2SSungbin Jeon
58ec9a8f2SSungbin Jeonuse League\CommonMark\Environment;
68ec9a8f2SSungbin Jeonuse League\CommonMark\DocParser;
71e536badSSungbin Jeonuse Dokuwiki\Plugin\Commonmark\Extension\CommonmarkToDokuwikiExtension;
8f46768a8SSungbin Jeonuse Dokuwiki\Plugin\Commonmark\Extension\FootnoteToDokuwikiExtension;
978c882e7SSungbin Jeonuse League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
10*656793f4SSungbin Jeonuse Dokuwiki\Plugin\Commonmark\Extension\TableExtension;
118ec9a8f2SSungbin Jeon
128ec9a8f2SSungbin Jeonclass Commonmark {
138ec9a8f2SSungbin Jeon    public static function RendtoDW($markdown): string {
148ec9a8f2SSungbin Jeon        # create environment
158ec9a8f2SSungbin Jeon        $environment = self::createDWEnvironment();
168ec9a8f2SSungbin Jeon
178ec9a8f2SSungbin Jeon        # create parser
188ec9a8f2SSungbin Jeon        $parser = new DocParser($environment);
198ec9a8f2SSungbin Jeon        # create Dokuwiki Renderer
208ec9a8f2SSungbin Jeon        $DWRenderer = new DWRenderer($environment);
218ec9a8f2SSungbin Jeon
228ec9a8f2SSungbin Jeon        $document = $parser->parse($markdown);
238ec9a8f2SSungbin Jeon        return $DWRenderer->renderBlock($document);
248ec9a8f2SSungbin Jeon    }
258ec9a8f2SSungbin Jeon
268ec9a8f2SSungbin Jeon    public static function createDWEnvironment(): Environment {
278ec9a8f2SSungbin Jeon        $environment = new Environment();
288ec9a8f2SSungbin Jeon        $environment->addExtension(new CommonMarkToDokuWikiExtension());
29f46768a8SSungbin Jeon        $environment->addExtension(new FootnoteToDokuwikiExtension());
3078c882e7SSungbin Jeon        $environment->addExtension(new StrikethroughExtension());
31*656793f4SSungbin Jeon        $environment->addExtension(new TableExtension());
32f46768a8SSungbin Jeon
33f46768a8SSungbin Jeon        $environment->mergeConfig([
34f46768a8SSungbin Jeon            'html_input' => 'strip',
35f46768a8SSungbin Jeon        ]);
368ec9a8f2SSungbin Jeon
378ec9a8f2SSungbin Jeon        return $environment;
388ec9a8f2SSungbin Jeon    }
398ec9a8f2SSungbin Jeon}
408ec9a8f2SSungbin Jeon
418ec9a8f2SSungbin Jeon?>