From eb6a7c6639f804b30a32730e4b27609c09f20bd8 Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 15 Feb 2024 10:55:43 +0100 Subject: [PATCH] Move formatting into separate methods --- phpdotnet/phd/Package/Generic/XHTML.php | 94 ++++++++++++------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 77bdf9fb..ebfe896c 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -2057,75 +2057,71 @@ public function format_simplelist($open, $name, $attrs, $props) { if ($this->cchunk["simplelist"]["type"] === "inline") { return ''; - } else if ($this->cchunk["simplelist"]["type"] === "vert" || $this->cchunk["simplelist"]["type"] === "horiz") { + } + + if ($this->cchunk["simplelist"]["type"] === "vert" + || $this->cchunk["simplelist"]["type"] === "horiz") { return '' . "\n" . str_repeat(" ", $props["depth"] + 1) . "\n"; } return '", + }; - $this->cchunk["simplelist"] = $this->dchunk["simplelist"]; - return $list . ''; + $this->cchunk["simplelist"] = $this->dchunk["simplelist"]; - } + return $list; + } - if ($this->cchunk["simplelist"]["type"] === "horiz") { + private function format_inline_simplelist() { + return implode(", ", $this->cchunk["simplelist"]["members"]) . ''; + } - $table = ""; - for ($i = 0; $i < count($this->cchunk["simplelist"]["members"]); $i++) { - if ($i % $this->cchunk["simplelist"]["columns"] === 0) { - $table .= str_repeat(" ", $props["depth"] + 2) . "\n"; - } + private function format_horizontal_simplelist($props) { + $this->cchunk["simplelist"]["members"] = array_merge($this->cchunk["simplelist"]["members"], $this->get_simplelist_members_padding()); - $table .= str_repeat(" ", $props["depth"] + 3) . "\n"; + $table = ""; + $trPadding = str_repeat(" ", $props["depth"] + 2); + $tdPadding = str_repeat(" ", $props["depth"] + 3); + for ($i = 0; $i < count($this->cchunk["simplelist"]["members"]); $i++) { + $trOpen = ($i % $this->cchunk["simplelist"]["columns"] === 0) ? ($trPadding . "\n") : ""; + $trClose = ($i % $this->cchunk["simplelist"]["columns"] === $this->cchunk["simplelist"]["columns"] - 1) ? ($trPadding . "\n") : ""; - if ($i % $this->cchunk["simplelist"]["columns"] === $this->cchunk["simplelist"]["columns"] - 1) { - $table .= str_repeat(" ", $props["depth"] + 2) . "\n"; - } - } - if ($i % $this->cchunk["simplelist"]["columns"] !== 0) { - $numOfMissingCells = $this->cchunk["simplelist"]["columns"] - ($i % $this->cchunk["simplelist"]["columns"]); - $oneRow = str_repeat(" ", $props["depth"] + 3) . "\n"; - $table .= str_repeat($oneRow, $numOfMissingCells); - $table .= str_repeat(" ", $props["depth"] + 2) . "\n"; - } + $table .= $trOpen . $tdPadding . "\n" . $trClose; + } - $this->cchunk["simplelist"] = $this->dchunk["simplelist"]; + return $table . str_repeat(" ", $props["depth"] + 1) . "\n" . str_repeat(" ", $props["depth"]) . "
" . $this->cchunk["simplelist"]["members"][$i] . "
" . $this->cchunk["simplelist"]["members"][$i] . "
"; + } - return $table . str_repeat(" ", $props["depth"] + 1) . "\n" . str_repeat(" ", $props["depth"]) . ""; + private function get_simplelist_members_padding() { + $numOfRows = ceil(count($this->cchunk["simplelist"]["members"]) / $this->cchunk["simplelist"]["columns"]); - } + return array_fill(0, ($this->cchunk["simplelist"]["columns"] * $numOfRows) - count($this->cchunk["simplelist"]["members"]), ""); + } - if ($this->cchunk["simplelist"]["type"] === "vert") { + private function format_vertical_simplelist($props) { + $numOfRows = ceil(count($this->cchunk["simplelist"]["members"]) / $this->cchunk["simplelist"]["columns"]); - $table = ""; - $numOfRows = ceil(count($this->cchunk["simplelist"]["members"]) / $this->cchunk["simplelist"]["columns"]); - for ($row = 0; $row < $numOfRows; $row++) { - $table .= str_repeat(" ", $props["depth"] + 2) . "\n"; - for ($col = 0; $col < $this->cchunk["simplelist"]["columns"]; $col++) { - $memberIndex = ($numOfRows * $col) + $row; - $table .= str_repeat(" ", $props["depth"] + 3) . ""; - if ($memberIndex < count($this->cchunk["simplelist"]["members"])) { - $table .= $this->cchunk["simplelist"]["members"][$memberIndex]; - } - $table .= "\n"; - } - $table .= str_repeat(" ", $props["depth"] + 2) . "\n"; - } - $this->cchunk["simplelist"] = $this->dchunk["simplelist"]; + $this->cchunk["simplelist"]["members"] = array_merge($this->cchunk["simplelist"]["members"], $this->get_simplelist_members_padding()); - return $table . str_repeat(" ", $props["depth"] + 1) . "\n" . str_repeat(" ", $props["depth"]) . ""; + $table = ""; + $trPadding = str_repeat(" ", $props["depth"] + 2); + $tdPadding = str_repeat(" ", $props["depth"] + 3); + for ($row = 0; $row < $numOfRows; $row++) { + $table .= $trPadding . "\n"; + for ($col = 0; $col < $this->cchunk["simplelist"]["columns"]; $col++) { + $table .= $tdPadding . "" . $this->cchunk["simplelist"]["members"][($numOfRows * $col) + $row] . "\n"; + } + $table .= $trPadding . "\n"; } - $this->cchunk["simplelist"] = $this->dchunk["simplelist"]; - return ''; + return $table . str_repeat(" ", $props["depth"] + 1) . "\n" . str_repeat(" ", $props["depth"]) . ""; } public function format_member($open, $name, $attrs, $props) {