fix markdown in descriptions
[mdref/mdref] / mdref / Markdown.php
1 <?php
2
3 namespace mdref;
4
5 class Markdown
6 {
7 /**
8 * @var \mdref\Path
9 */
10 protected $path;
11
12 /**
13 * @param \mdref\Path $path
14 */
15 function __construct(Path $path = null) {
16 $this->path = $path;
17 }
18
19 /**
20 * @return string
21 */
22 function __toString() {
23 if (!$this->path) {
24 return "";
25 }
26 try {
27 $r = fopen($this->path->getFullPath(".md"), "r");
28 $md = \MarkdownDocument::createFromStream($r);
29 $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC);
30 $html = $md->getHtml();
31 fclose($r);
32 } catch (\Exception $e) {
33 $html = ExceptionHandler::html($e);
34 }
35 return $html;
36 }
37
38 function quick($string) {
39 $md = \MarkdownDocument::createFromString($string);
40 $md->compile(\MarkdownDocument::AUTOLINK);
41 return $md->getHtml();
42 }
43 }