lichen-md/cms/markdown.php
2024-08-10 10:34:12 +09:00

24 lines
514 B
PHP

<?php
require_once "vendor/php-markdown-lib-9.1/Michelf/MarkdownExtra.inc.php";
use Michelf\MarkdownExtra;
function markdown_to_html($file, $generate_headline_ids = true) {
$title = '';
$html = '';
$headings = null;
$source = "";
while(!feof($file)) {
$source = $source . fgets($file);
}
$html = MarkdownExtra::defaultTransform($source);
preg_match_all( '|<h[^>]+>(.*)</h[^>]+>|iU', $html, $headings );
$title = trim(implode($headings[1]));
return array("html" => $html, "title" => $title);
}