#markdown here
if(isset($args['@attrib']) && isset($args['@attrib']['inline']) &&
$args['@attrib']['inline'] === 'true'){
return self::instance()->inline($args);
}
# href
if(isset($args['@attrib']) && isset($args['@attrib']['href']))
{
return self::instance()->load_href($args);
}
# token {@variable}
$content = $args[0];
$content_token = \Template::instance()->token($content);
return '
build('.$content_token.'); ?>
';
}
function build($content){
return \ParsedownTableExtension::instance()->text($content);
}
static private function inline($args){
$return = \Parsedown::instance()->text($args[0]);
return '
';
}
static private function load_href($args){
$href= $args['@attrib']['href'] ?? '';
if(!$href){
return '';
}
$ui = Base::instance()->get('UI');
$dirs = preg_split('#[;]+#', $ui, -1, PREG_SPLIT_NO_EMPTY);
// look for the file in each UI dir
$file = '';
foreach ($dirs as $dir) {
// normalize trailing slash
$base = rtrim($dir, '/').'/';
// resolve relative paths
$candidate = realpath($base . $href) ?: $base . $href;
// print_r("".$candidate . "
");
if (is_readable($candidate)) {
$file = $candidate;
break;
}
}
if(!$file) {
return "File not found: {$href}
";
}
$text = file_get_contents($file);
$md = \Parsedown::instance()->text($text);
return '
'.$md.'
';
}
}
\Template::instance()->extend('parsedown', 'ParsedownHelper::render');