From c47b78e13afb092aa1a30296b885b2911444fe3c Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 21 Jan 2020 01:28:04 +0100 Subject: new user manual in markdown --- app/class/Modelrender.php | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'app/class/Modelrender.php') diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 593a420..fe491f1 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -36,6 +36,21 @@ class Modelrender extends Modelpage } } + /** + * Used to convert the markdown user manual to html document + * + * @param string $text Input text in markdown + * @return string html formated text + */ + public function rendermanual(string $text) : string + { + $text = $this->markdown($text); + $text = $this->headerid($text, 3); + return $text; + + } + + public function upage($id) { return $this->router->generate('pageread/', ['page' => $id]); @@ -384,11 +399,25 @@ class Modelrender extends Modelpage return $text; } - public function headerid($text) + /** + * Add Id to hrml header elements and store the titles in the `sum` parameter + * + * @param string $text Input html document to scan + * @param int $maxdeepness Maximum header deepness to look for. Min = 1 Max = 6 Default = 6 + * + * @return string text with id in header + */ + + public function headerid($text, int $maxdeepness = 6) { + if($maxdeepness > 6 || $maxdeepness < 1) { + $maxdeepness = 6; + } + + $sum = []; $text = preg_replace_callback( - '/(.+)<\/h[1-6]>/mU', + '/(.+)<\/h[1-' . $maxdeepness . ']>/mU', function ($matches) use (&$sum) { $cleanid = idclean($matches[4]); $sum[$cleanid][$matches[1]] = $matches[4]; @@ -453,16 +482,15 @@ class Modelrender extends Modelpage return $text; } - - function sumparser($text) + /** + * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text + * + * @return string html list with anchor link + */ + function sumparser() : string { - preg_match_all('#(.+)#iU', $text, $out); - - $sum = $this->sum; - - $sumstring = ''; $last = 0; foreach ($sum as $title => $list) { -- cgit v1.2.3