urls["readme"]))
return;
/*
* Configuration for common mark for converting markdown
* into html
*/
$config = [
'html_input' => 'escape',
'allow_unsafe_links' => false,
'max_nesting_level' => 5
];
$readmefilepath = $explorer->dir . DIRECTORY_SEPARATOR . $explorer->urls["readme"];
$fileHandle = fopen($readmefilepath, 'r');
if ($fileHandle === false) {
$content = '
Could not open README file
';
} else {
$size = filesize($readmefilepath);
// if the size is zero or cannot be determined
// $content will be empty and nothing will be rendered
if (!empty($size) && $size > 0) {
$text = fread($fileHandle, $size);
if ($text === false) {
$content = 'Could not read README
';
} else {
try {
// convert markdown into html
$converter = new CommonMarkConverter($config);
$content = $converter->convert($text);
} catch (CommonMarkException) {
$content = 'Could not render README
';
}
}
}
fclose($fileHandle);
}
if (!empty($content)) {
echo 'Readme
' . $content . '
';
}
}
render_readme();