updated parsedown helper to include href
This commit is contained in:
parent
bc21598ba9
commit
67a35cdf3e
@ -2,22 +2,25 @@
|
||||
|
||||
class ParsedownHelper extends \Prefab {
|
||||
|
||||
static public function render($args) {
|
||||
static public function render($args)
|
||||
{
|
||||
|
||||
if(isset($args['@attrib']) && $args['@attrib']['inline'] === 'true'){
|
||||
# inline <parsedown inline="true">#markdown here</parsedown>
|
||||
if(isset($args['@attrib']) && isset($args['@attrib']['inline']) &&
|
||||
$args['@attrib']['inline'] === 'true'){
|
||||
|
||||
$return = \Parsedown::instance()->text($args[0]);
|
||||
|
||||
return '<!-- tableextension -->
|
||||
<div class="content">
|
||||
<parsedown_rendered>'.$return.'</parsedown_rendered>
|
||||
</div>
|
||||
';
|
||||
return self::instance()->inline($args);
|
||||
|
||||
}
|
||||
|
||||
// return '<pre>'.print_r($args,1).'</pre>';
|
||||
# href <parsedown href="filename"></parsedown>
|
||||
if(isset($args['@attrib']) && isset($args['@attrib']['href']))
|
||||
{
|
||||
return self::instance()->load_href($args);
|
||||
}
|
||||
|
||||
|
||||
# token <parsedown>{@variable}</parsedown>
|
||||
$content = $args[0];
|
||||
$content_token = \Template::instance()->token($content);
|
||||
|
||||
@ -30,6 +33,52 @@ class ParsedownHelper extends \Prefab {
|
||||
function build($content){
|
||||
return \ParsedownTableExtension::instance()->text($content);
|
||||
}
|
||||
|
||||
|
||||
static private function inline($args){
|
||||
$return = \Parsedown::instance()->text($args[0]);
|
||||
|
||||
return '<!-- tableextension -->
|
||||
<div class="content">
|
||||
<parsedown_rendered>'.$return.'</parsedown_rendered>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
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("<p>".$candidate . "</p>");
|
||||
if (is_readable($candidate)) {
|
||||
$file = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$file) {
|
||||
return "<p><em>File not found: {$href}</em></p>";
|
||||
}
|
||||
|
||||
$text = file_get_contents($file);
|
||||
$md = \Parsedown::instance()->text($text);
|
||||
|
||||
return '
|
||||
<parsedown_rendered class="content">
|
||||
'.$md.'
|
||||
</parsedown_rendered>';
|
||||
}
|
||||
}
|
||||
|
||||
\Template::instance()->extend('parsedown', 'ParsedownHelper::render');
|
||||
Loading…
x
Reference in New Issue
Block a user