aboutsummaryrefslogtreecommitdiff
path: root/app/class/Modelrender.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/Modelrender.php')
-rw-r--r--app/class/Modelrender.php68
1 files changed, 56 insertions, 12 deletions
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index 778b327..5a86d0b 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, 5);
+ return $text;
+
+ }
+
+
public function upage($id)
{
return $this->router->generate('pageread/', ['page' => $id]);
@@ -308,7 +323,7 @@ class Modelrender extends Modelpage
$text = $this->headerid($text);
- $text = str_replace(self::SUMMARY, $this->sumparser($text), $text);
+ $text = str_replace(self::SUMMARY, $this->sumparser(), $text);
$text = $this->wurl($text);
$text = $this->wikiurl($text);
@@ -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])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-6]>/mU',
+ '/<h([1-' . $maxdeepness . '])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-' . $maxdeepness . ']>/mU',
function ($matches) use (&$sum) {
$cleanid = idclean($matches[4]);
$sum[$cleanid][$matches[1]] = $matches[4];
@@ -437,34 +466,49 @@ class Modelrender extends Modelpage
*/
public function automedialist(string $text)
{
- preg_match_all('~\%MEDIA\?([a-zA-Z0-9\&=\-\/\%]*)\%~', $text, $out);
+ preg_match_all('~\%MEDIA\?([a-zA-Z0-9\[\]\&=\-\/\%]*)\%~', $text, $out);
foreach ($out[0] as $key => $match) {
- $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]];
+ $matches[$key] = ['fullmatch' => $match, 'filter' => $out[1][$key]];
}
if(isset($matches)) {
foreach ($matches as $match) {
$medialist = new Medialist($match);
- $text = str_replace($medialist->fullmatch(), $medialist->content(), $text);
+ $medialist->readfilter();
+ $text = str_replace($medialist->fullmatch(), $medialist->generatecontent(), $text);
}
}
return $text;
}
-
- function sumparser($text)
+ /**
+ * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text
+ *
+ * @param int $min Minimum header deepness to start the summary : Between 1 and 6.
+ * @param int $max Maximum header deepness to start the summary : Between 1 and 6.
+ *
+ * @return string html list with anchor link
+ */
+ function sumparser(int $min = 1, int $max = 6) : string
{
- preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out);
-
+ $min = $min >= 1 && $min <= 6 && $min <= $max ? $min : 1;
+ $end = $max >=1 && $max <= 6 && $max >= $min ? $max : 6;
$sum = $this->sum;
+ $filteredsum = [];
+ foreach ($sum as $key => $menu) {
+ $deepness = array_keys($menu)[0];
+ if($deepness >= $min && $deepness <= $max) {
+ $filteredsum[$key] = $menu;
+ }
+ }
$sumstring = '';
$last = 0;
- foreach ($sum as $title => $list) {
+ foreach ($filteredsum as $title => $list) {
foreach ($list as $h => $link) {
if ($h > $last) {
for ($i = 1; $i <= ($h - $last); $i++) {
@@ -633,7 +677,7 @@ class Modelrender extends Modelpage
$optlist->parsehydrate($match['options']);
$table2 = $modelhome->table2($this->pagelist, $optlist);
- $content = '<ul>' . PHP_EOL ;
+ $content = '<ul class="pagelist">' . PHP_EOL ;
foreach ($table2 as $page ) {
$content .= '<li>' . PHP_EOL;
$content .= '<a href="' . $this->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL;