aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Renderer/Markdown.php
blob: 65cb29c0469c062a9a253cc7b955538c0ffc87eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace phorkie;

class Renderer_Markdown
{
    /**
     * Converts the code to HTML
     *
     * @param File        $file File to render
     * @param Tool_Result $res  Tool result to integrate
     *
     * @return string HTML
     */
    public function toHtml(File $file, Tool_Result $res = null)
    {
        if (class_exists('\\Michelf\\Markdown', true)) {
            //composer-installed version 1.4+
            $markdown = \Michelf\Markdown::defaultTransform(
                $file->getContent()
            );
        } else {
            //PEAR-installed version 1.0.2 has a different API
            require_once 'markdown.php';
            $markdown = \markdown($file->getContent());
        }

        return '<div class="markdown">'
            . $markdown
            . '</div>';
    }
}

?>