@@ -157,20 +157,25 @@ object tags {
157157 * `Title`.
158158 *
159159 * ```html
160- * {% renderTitle title, parent %}
160+ * {% renderTitle title, page.url %}
161161 * ```
162- *
163- * The rendering currently works on depths up to 2. This means that each
164- * title can have a subsection with its own titles.
165162 */
166163 case class RenderTitle (params : Map [String , AnyRef ])(implicit ctx : Context )
167164 extends Tag (" renderTitle" ) with ParamConverter {
168- private def renderTitle (t : Title , parent : String ): String = {
165+ private def isParent (t : Title , htmlPath : String ): Boolean = {
166+ t.url match {
167+ case Some (url) => url == htmlPath
168+ case None => t.subsection.exists(isParent(_, htmlPath))
169+ }
170+ }
171+ private def renderTitle (t : Title , pageUrl : String ): String = {
169172 if (! t.url.isDefined && t.subsection.nonEmpty) {
173+ val htmlPath = pageUrl.replace(" .md" , " .html" )
174+ val marker = if (isParent(t, htmlPath)) " class=\" toggled\" " else " "
170175 s """ |<li class="section">
171176 | <a onclick='toggleSection(this);'> ${t.title}</a>
172- | <ul id=" ${ if (parent == t.title.toLowerCase.split( " " ).mkString( " - " )) " active-toc-entry " else " " } " >
173- | ${ t.subsection.map(renderTitle(_, parent )).mkString(" \n " ) }
177+ | <ul $marker >
178+ | ${ t.subsection.map(renderTitle(_, htmlPath )).mkString(" \n " ) }
174179 | </ul>
175180 |</li>
176181 | """ .stripMargin
@@ -188,13 +193,13 @@ object tags {
188193 }
189194
190195 override def render (ctx : TemplateContext , nodes : LNode * ): AnyRef =
191- (nodes(0 ).render(ctx), nodes(1 ).render(ctx)) match {
192- case (map : JMap [String , AnyRef ] @ unchecked, parent : String ) =>
193- Title (map).map(renderTitle(_, parent)).getOrElse( null )
196+ (( nodes(0 ).render(ctx), nodes(1 ).render(ctx)) match {
197+ case (map : JMap [String , AnyRef ] @ unchecked, url : String ) =>
198+ Title (map).map(renderTitle(_, url) )
194199 case (map : JMap [String , AnyRef ] @ unchecked, _) =>
195- Title (map).map(renderTitle(_, " ./" )).getOrElse( null ) // file is in top dir
196- case _ => null
197- }
200+ Title (map).map(renderTitle(_, " ./" )) // file is in top dir
201+ case _ => None
202+ }).orNull
198203 }
199204
200205 /** Allows the extraction of docstrings from the given path. E.g:
0 commit comments