-
- public function formatFile($file) {
- $fd = fopen($file, "r");
- $md = \MarkdownDocument::createFromStream($fd);
- $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC);
- $html = $md->getHtml();
- fclose($fd);
- return $html;
+
+ /**
+ * @param string $file
+ * @return string
+ * @throws \Exception
+ */
+ public function formatFile(string $file) : string {
+ if (extension_loaded("discount")) {
+ $fd = fopen($file, "r");
+ $md = \MarkdownDocument::createFromStream($fd);
+ $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC);
+ $html = $md->getHtml();
+ fclose($fd);
+ return $html;
+ }
+ if (extension_loaded("cmark")) {
+ $node = \CommonMark\Parse(file_get_contents($file));
+ return \CommonMark\Render\HTML($node);
+ }
+ throw new \Exception("No Markdown implementation found");