diff --git a/system/typemill/Extensions/ParsedownExtension.php b/system/typemill/Extensions/ParsedownExtension.php
index 105eed4..410e5f3 100644
--- a/system/typemill/Extensions/ParsedownExtension.php
+++ b/system/typemill/Extensions/ParsedownExtension.php
@@ -425,46 +425,52 @@ class ParsedownExtension extends \ParsedownExtra
}
- # build the markup for table of contents
+ # build the markup for table of contents, thanks gtp for fixing!
public function buildTOC($headlines)
{
$markup = '
';
# we have to reindex the array
-
$headlines = array_values($headlines);
+ # Initialize previous level to the highest possible level
+ $prevLevel = 1;
+
+ # Stack to keep track of open tags
+ $stack = array();
+
foreach($headlines as $key => $headline)
{
$thisLevel = $headline['level'];
- $prevLevel = $key > 0 ? $headlines[$key-1]['level'] : 1;
- $nextLevel = isset($headlines[$key+1]) ? $headlines[$key+1]['level'] : 0;
- if($thisLevel > $prevLevel)
+ # Close any open - tags if the current level is lower than the previous level
+ while ($thisLevel < $prevLevel)
+ {
+ $markup .= '
';
+ $markup .= array_pop($stack); // Close the corresponding tag
+ $prevLevel--;
+ }
+
+ # Open a new tag if the current level is higher than the previous level
+ if ($thisLevel > $prevLevel)
{
$markup .= ''; // Add the closing
tag to the stack
}
$markup .= '- ' . $headline['text'] . '';
- if($thisLevel == $nextLevel )
- {
- $markup .= '
';
- }
- elseif($thisLevel > $nextLevel)
- {
- while($thisLevel > $nextLevel)
- {
- $markup .= '
';
- $thisLevel--;
- }
-
- if($thisLevel > 0)
- {
- $markup .= '';
- }
- }
+ $prevLevel = $thisLevel;
}
+
+ # Close any remaining open - tags and
tags
+ while (!empty($stack)) {
+ $markup .= '
';
+ $markup .= array_pop($stack);
+ }
+
+ # Close the top-level ';
return $markup;
}
diff --git a/system/typemill/author/css/custom.css b/system/typemill/author/css/custom.css
index ea85a1c..32e2755 100644
--- a/system/typemill/author/css/custom.css
+++ b/system/typemill/author/css/custom.css
@@ -423,12 +423,14 @@
}
-.blox-preview ul.TOC,
-.blox-preview .TOC ul{
+.blox-preview ul.TOC{
list-style: none;
padding-left: 0px;
margin-left: 0px;
}
+.blox-preview .TOC ul{
+ list-style: none;
+}
.blox-preview .TOC li:before{
content: "\2192";
color: #bbb;
diff --git a/system/typemill/settings/defaults.yaml b/system/typemill/settings/defaults.yaml
index 9bd8e57..ac548fb 100644
--- a/system/typemill/settings/defaults.yaml
+++ b/system/typemill/settings/defaults.yaml
@@ -1,4 +1,4 @@
-version: '2.4.1'
+version: '2.4.2'
title: 'Typemill'
author: 'Unknown'
copyright: false