Skip to content

Commit

Permalink
Closing ul-elements correctly now. Remove comments in headings from toc
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Pegenau committed Jul 11, 2016
1 parent 0edd1a1 commit fb7c621
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tableofcontents.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function toHtml() {

$toc = $this->ToC;
//echo "<pre>" . print_r($toc, true) . "</pre>";
$output = "<h3 class='ouwtopheading'>" . get_string('tableofcontents', 'ouwiki') . "</h3>";
$output = PHP_EOL . "<h3 class='ouwtopheading'>" . get_string('tableofcontents', 'ouwiki') . "</h3>" . PHP_EOL;

// Helps building the nested <ul>-elements
$lastlvl = 0;
Expand All @@ -81,16 +81,16 @@ public function toHtml() {
$currentLvl = $this->getLvlByChapterNumber($chapterNumber);

// The elements heading
$element = '<li><a href="#'.$obj->id.'">'.$chapterNumber." ".$obj->name .'</a></li>';
$element = '<li><a href="#'.$obj->id.'">'.$chapterNumber." ".$obj->name .'</a></li>' . PHP_EOL;

// New nested <ul>
if($currentLvl > $lastlvl) {
$output .= str_repeat("<ul>", $currentLvl - $lastlvl);
$output .= str_repeat("<ul>" . PHP_EOL, $currentLvl - $lastlvl);
$output .= $element;
}
// Close as many <ul> as necessary
elseif ($currentLvl < $lastlvl) {
$output .= str_repeat("</ul>", $lastlvl - $currentLvl);
$output .= str_repeat("</ul>" . PHP_EOL, $lastlvl - $currentLvl);
$output .= $element;
}
// Same level, just add <li>
Expand All @@ -108,7 +108,7 @@ public function toHtml() {
}
}

$output .= "</ul>";
$output .= str_repeat("</ul>" . PHP_EOL, $lastlvl);
return $output;
}

Expand Down Expand Up @@ -189,7 +189,17 @@ private function parseHtml($html) {
foreach ($headings as $heading) {
// Get Heading level: <h6> => 6
$lvl = substr($heading->tagName, 1);


$childNodes = $heading->childNodes;
for($i = 0; $i < $childNodes->length; $i++) {
$node = $childNodes->item($i);
if(isset($node->tagName)) {
$heading->removeChild($node);
echo "Child removed! <br />";
}
}


// Get id:
// <h1 id="ouw_s0_0"> => ouw_s0_0
$attributes = $heading->attributes;
Expand Down

0 comments on commit fb7c621

Please sign in to comment.