@@ -157,20 +157,25 @@ object tags {
157
157
* `Title`.
158
158
*
159
159
* ```html
160
- * {% renderTitle title, parent %}
160
+ * {% renderTitle title, page.url %}
161
161
* ```
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.
165
162
*/
166
163
case class RenderTitle (params : Map [String , AnyRef ])(implicit ctx : Context )
167
164
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 = {
169
172
if (! t.url.isDefined && t.subsection.nonEmpty) {
173
+ val htmlPath = pageUrl.replace(" .md" , " .html" )
174
+ val marker = if (isParent(t, htmlPath)) " class=\" toggled\" " else " "
170
175
s """ |<li class="section">
171
176
| <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 " ) }
174
179
| </ul>
175
180
|</li>
176
181
| """ .stripMargin
@@ -188,13 +193,13 @@ object tags {
188
193
}
189
194
190
195
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) )
194
199
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
198
203
}
199
204
200
205
/** Allows the extraction of docstrings from the given path. E.g:
0 commit comments