From 2d18dcd2046051a1769d9714016e08819bd0c3fe Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 4 Nov 2013 15:04:01 +0200 Subject: [PATCH] Turn all TOC entries into
  • elements. It's a list, and should me marked up accoringly. --- lib/jsduck/guide_toc.rb | 18 ++++++++++++++++-- template/resources/sass/viewport.scss | 8 +++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/jsduck/guide_toc.rb b/lib/jsduck/guide_toc.rb index 12d08280..126a97b1 100644 --- a/lib/jsduck/guide_toc.rb +++ b/lib/jsduck/guide_toc.rb @@ -21,6 +21,8 @@ module JsDuck # Inserts table of contents at the top of guide HTML by looking # for headings at or below the specified maximum level. def inject! + prev_level = @min_level-1 + @html.each_line do |line| if line =~ /^\s*(.*?)<\/h[1-6]>$/ level = $1.to_i @@ -29,7 +31,15 @@ module JsDuck if include_to_toc?(level) increment_heading_count!(level) - @toc << toc_entry(level, id, text) + if level > prev_level + list_tags = "
    • " * (level - prev_level) + elsif prev_level > level + list_tags = "
  • " * (prev_level - level) + else + list_tags = "
  • " + end + @toc << list_tags + toc_entry(level, id, text) + prev_level = level end @new_html << "#{text}\n" @@ -38,6 +48,10 @@ module JsDuck end end + if @toc.length > 0 + @toc[@toc.length-1] += "
  • " * (prev_level - @min_level + 1) + end + inject_toc! @new_html.flatten.join @@ -57,7 +71,7 @@ module JsDuck end def toc_entry(level, id, text) - "#{toc_prefix(level)}. #{text}
    \n" + "#{toc_prefix(level)}. #{text}\n" end def toc_prefix(level) diff --git a/template/resources/sass/viewport.scss b/template/resources/sass/viewport.scss index 6f4aa2a3..4199b0bc 100644 --- a/template/resources/sass/viewport.scss +++ b/template/resources/sass/viewport.scss @@ -143,7 +143,13 @@ border: solid 1px #e8e8e8; padding: 10px 20px; margin: 0 14px; - @include border-radius(5px); } + @include border-radius(5px); + // no bullets and smaller indent + ul { + margin-left: 0.5em; + margin-bottom: 0; + li { + list-style-type: none; } } } h1 { background: url(../images/doc-m.png) no-repeat -5px -5px; padding: 10px 0 10px 55px; -- GitLab