stub2ref do not generate <ns>.md
[mdref/mdref] / mdref / Formatter / Discount.php
1 <?php
2
3 namespace mdref\Formatter;
4
5 use mdref\Exception;
6 use mdref\Formatter;
7
8 use MarkdownDocument;
9
10 class Discount extends Formatter {
11
12 function formatString(string $string) : string {
13 $md = \MarkdownDocument::createFromString($string);
14 $md->compile(\MarkdownDocument::AUTOLINK);
15 return $md->getHtml();
16 }
17
18 function formatFile(string $file) : string {
19 $fd = fopen($file, "r");
20 if (!$fd) {
21 throw Exception::fromLastError();
22 }
23
24 $md = \MarkdownDocument::createFromStream($fd);
25 $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC);
26 $html = $md->getHtml();
27
28 fclose($fd);
29
30 return $html;
31 }
32 }