diff --git a/app/extensions/ParsedownHelper.php b/app/extensions/ParsedownHelper.php
index ef6ee8c..85cca6b 100644
--- a/app/extensions/ParsedownHelper.php
+++ b/app/extensions/ParsedownHelper.php
@@ -2,22 +2,25 @@
class ParsedownHelper extends \Prefab {
- static public function render($args) {
+ static public function render($args)
+ {
+
+ # inline #markdown here
+ if(isset($args['@attrib']) && isset($args['@attrib']['inline']) &&
+ $args['@attrib']['inline'] === 'true'){
- if(isset($args['@attrib']) && $args['@attrib']['inline'] === 'true'){
-
- $return = \Parsedown::instance()->text($args[0]);
-
- return '
-
- ';
+ return self::instance()->inline($args);
}
- // return ''.print_r($args,1).'
';
+ # 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);
@@ -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 '
+
+ ';
+ }
+
+ 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');
\ No newline at end of file