setup same line logic in lists and fixed problems with a links inside those
authorEduardo <[email protected]>
Sat, 25 Nov 2023 14:12:38 +0000 (15:12 +0100)
committerEduardo <[email protected]>
Sat, 25 Nov 2023 14:12:38 +0000 (15:12 +0100)
page-generator/generator.php

index f5e1de22e0e2faa9e0c8a59e8f131b1ce12894ab..04d3675798d291e8c180c148257bcedef4fe17be 100644 (file)
@@ -328,7 +328,16 @@ class CodeGenerator
 
     private function form_list(string $text, array $class, string $url, string $title): string
     {
-        $html = "<li";
+        // if in class array is not "same-line" set flag
+        if (!in_array("same-line", $class))
+            $this->is_li_same_line = false;
+        else
+            $this->is_li_same_line = true;
+
+        if (isset($this->was_li_same_line) && !$this->was_li_same_line)
+            $html = "<li";
+        else
+            $html = "";
 
         // if class not empty add class
         $filtered_classes = $this->filter_meta_classes($class);
@@ -336,18 +345,27 @@ class CodeGenerator
             $html .= ' class="' . implode(' ', $filtered_classes) . '"';
 
         // if has title and url = a with title
-        if (!empty($title) && !empty($url)) {
-            $html .= '>';
-            $html .= $this->a($url, $text, $title, null);
+        if (!empty($url)) {
+            if (!$this->was_li_same_line)
+                $html .= '>';
+            $html .= $this->a($url, $text, $title, $filtered_classes);
+
+            if (in_array("no-space", $class))
+                $html = trim($html);
         }
         // if has only title = span with title
         elseif (!empty($title)) {
             $html .= " title='$title'>$text";
-        } else
-            $html .= ">$text";
+        } else {
+            if (isset($this->was_li_same_line) && !$this->was_li_same_line)
+                $html .= '>';
+            $html .= "$text";
+        }
 
-        $html .= "</li>";
+        if (!$this->is_li_same_line)
+            $html .= '</li>';
 
+        $this->was_li_same_line = $this->is_li_same_line;
         return $html;
     }