Skip to content

Commit

Permalink
Move formatting into separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
haszi committed Feb 15, 2024
1 parent 6882a73 commit 1a889c5
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2056,75 +2056,71 @@ public function format_simplelist($open, $name, $attrs, $props) {

if ($this->cchunk["simplelist"]["type"] === "inline") {
return '<span class="' . $name . '">';
} else if ($this->cchunk["simplelist"]["type"] === "vert" || $this->cchunk["simplelist"]["type"] === "horiz") {
}

if ($this->cchunk["simplelist"]["type"] === "vert"
|| $this->cchunk["simplelist"]["type"] === "horiz") {
return '<table class="' . $name . '">' . "\n" . str_repeat(" ", $props["depth"] + 1) . "<tbody>\n";
}

return '<ul class="' . $name . '">';
}

if ($this->cchunk["simplelist"]["type"] === "inline") {
$list = "";
foreach ($this->cchunk["simplelist"]["members"] as $member) {
$list .= $member . ", ";
}
$list = rtrim($list, ", ");
$list = match ($this->cchunk["simplelist"]["type"]) {
"inline" => $this->format_inline_simplelist(),
"horiz" => $this->format_horizontal_simplelist($props),
"vert" => $this->format_vertical_simplelist($props),
default => "</ul>",
};

$this->cchunk["simplelist"] = $this->dchunk["simplelist"];
return $list . '</span>';
$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"]) . '</span>';
}

$table = "";
for ($i = 0; $i < count($this->cchunk["simplelist"]["members"]); $i++) {
if ($i % $this->cchunk["simplelist"]["columns"] === 0) {
$table .= str_repeat(" ", $props["depth"] + 2) . "<tr>\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) . "<td>" . $this->cchunk["simplelist"]["members"][$i] . "</td>\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 . "<tr>\n") : "";
$trClose = ($i % $this->cchunk["simplelist"]["columns"] === $this->cchunk["simplelist"]["columns"] - 1) ? ($trPadding . "</tr>\n") : "";

if ($i % $this->cchunk["simplelist"]["columns"] === $this->cchunk["simplelist"]["columns"] - 1) {
$table .= str_repeat(" ", $props["depth"] + 2) . "</tr>\n";
}
}
if ($i % $this->cchunk["simplelist"]["columns"] !== 0) {
$numOfMissingCells = $this->cchunk["simplelist"]["columns"] - ($i % $this->cchunk["simplelist"]["columns"]);
$oneRow = str_repeat(" ", $props["depth"] + 3) . "<td></td>\n";
$table .= str_repeat($oneRow, $numOfMissingCells);
$table .= str_repeat(" ", $props["depth"] + 2) . "</tr>\n";
}
$table .= $trOpen . $tdPadding . "<td>" . $this->cchunk["simplelist"]["members"][$i] . "</td>\n" . $trClose;
}

$this->cchunk["simplelist"] = $this->dchunk["simplelist"];
return $table . str_repeat(" ", $props["depth"] + 1) . "</tbody>\n" . str_repeat(" ", $props["depth"]) . "</table>";
}

return $table . str_repeat(" ", $props["depth"] + 1) . "</tbody>\n" . str_repeat(" ", $props["depth"]) . "</table>";
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) . "<tr>\n";
for ($col = 0; $col < $this->cchunk["simplelist"]["columns"]; $col++) {
$memberIndex = ($numOfRows * $col) + $row;
$table .= str_repeat(" ", $props["depth"] + 3) . "<td>";
if ($memberIndex < count($this->cchunk["simplelist"]["members"])) {
$table .= $this->cchunk["simplelist"]["members"][$memberIndex];
}
$table .= "</td>\n";
}
$table .= str_repeat(" ", $props["depth"] + 2) . "</tr>\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) . "</tbody>\n" . str_repeat(" ", $props["depth"]) . "</table>";
$table = "";
$trPadding = str_repeat(" ", $props["depth"] + 2);
$tdPadding = str_repeat(" ", $props["depth"] + 3);
for ($row = 0; $row < $numOfRows; $row++) {
$table .= $trPadding . "<tr>\n";
for ($col = 0; $col < $this->cchunk["simplelist"]["columns"]; $col++) {
$table .= $tdPadding . "<td>" . $this->cchunk["simplelist"]["members"][($numOfRows * $col) + $row] . "</td>\n";
}
$table .= $trPadding . "</tr>\n";
}

$this->cchunk["simplelist"] = $this->dchunk["simplelist"];
return '</ul>';
return $table . str_repeat(" ", $props["depth"] + 1) . "</tbody>\n" . str_repeat(" ", $props["depth"]) . "</table>";
}

public function format_member($open, $name, $attrs, $props) {
Expand Down

0 comments on commit 1a889c5

Please sign in to comment.