File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ group :development do
99 # gem 'github-pages', group: :jekyll_plugins
1010
1111 gem 'byebug'
12+ gem 'lp'
1213 gem 'rack-test'
1314 gem 'rdoc'
1415 gem 'rspec'
Original file line number Diff line number Diff line change 1- require 'byebug' if ENV [ 'BYEBUG' ]
1+ if ENV [ 'BYEBUG' ]
2+ require 'byebug'
3+ require 'lp'
4+ end
25
36require 'requires'
47
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ def markdown
9999 def markdown_to_html
100100 doc = CommonMarker . render_doc markdown , :DEFAULT , [ :table ]
101101
102+ replace_toc_marker doc
102103 add_anchor_ids doc
103104 html = doc . to_html :UNSAFE
104105 html = syntax_highlight ( html ) if config . highlighter
@@ -121,6 +122,34 @@ def add_anchor_ids(doc)
121122 end
122123 end
123124
125+ # Replace <!-- TOC --> with a Table of Contents for the page
126+ def replace_toc_marker ( doc )
127+ toc_marker = doc . find do |node |
128+ node . type == :html and node . string_content . include? "<!-- TOC -->"
129+ end
130+
131+ return unless toc_marker
132+
133+ toc = [ ]
134+ doc . walk do |node |
135+ next unless node . type == :header
136+ level = node . header_level
137+ next unless level . between? 2 , 3
138+ text = node . first_child . string_content
139+
140+ if level == 2
141+ toc << "- [#{ text } ](##{ text . to_slug } )"
142+ else
143+ toc << " - [#{ text } ](##{ text . to_slug } )"
144+ end
145+ end
146+
147+ toc = toc . join "\n "
148+ toc = CommonMarker . render_doc toc
149+ toc_marker . insert_after toc . first_child
150+ toc_marker . insert_after CommonMarker . render_doc ( "## Table of Contents" ) . first_child
151+ end
152+
124153 # If the document does not start with an H1 tag, add it.
125154 def prepend_h1 ( html )
126155 unless html [ 0 ..3 ] == "<h1>"
Original file line number Diff line number Diff line change @@ -25,13 +25,11 @@ Gem::Specification.new do |s|
2525 s . add_runtime_dependency 'json' , '~> 2.1'
2626 s . add_runtime_dependency 'naturally' , '~> 2.2'
2727 s . add_runtime_dependency 'os' , '~> 1.0'
28- s . add_runtime_dependency 'puma' , '~> 5.0'
29- # s.add_runtime_dependency 'rack-contrib', '~> 2.1'
28+ s . add_runtime_dependency 'puma' , '~> 4.0'
3029 s . add_runtime_dependency 'rack-ssl' , '~> 1.4'
3130 s . add_runtime_dependency 'requires' , '~> 0.1'
3231 s . add_runtime_dependency 'sass' , '~> 3.7'
3332 s . add_runtime_dependency 'sinatra' , '~> 2.0' , '>= 2.0.5'
34- # s.add_runtime_dependency 'sinatra-contrib', '~> 2.0', '>= 2.0.5'
3533 s . add_runtime_dependency 'slim' , '~> 4.0'
3634 s . add_runtime_dependency 'extended_yaml' , '~> 0.2'
3735 s . add_runtime_dependency 'addressable' , '~> 2.7'
Original file line number Diff line number Diff line change 1+ ## Table of Contents
2+
3+ - [Purpose](#purpose)
4+ - [Scope](#scope)
5+ - [Background](#background)
6+ - [Exceptions](#exceptions)
7+ - [Policy](#policy)
8+ - [Phase 1: Preliminary analysis](#phase-1-preliminary-analysis)
9+ - [Phase 2: Systems analysis and requirements definition](#phase-2-systems-analysis-and-requirements-definition)
10+ - [Phase 3: Systems design](#phase-3-systems-design)
11+ - [Phase 4: Development](#phase-4-development)
12+ - [Phase 5: Integration and testing](#phase-5-integration-and-testing)
13+ - [Phase 6: Acceptance and deployment](#phase-6-acceptance-and-deployment)
14+ - [Phase 7: Maintenance plan](#phase-7-maintenance-plan)
15+ - [Appendix A - Security aspects](#appendix-a---security-aspects)
16+ - [Appendix B - Dependency upgrade guidelines](#appendix-b---dependency-upgrade-guidelines)
17+ - [Upgrading vulnerable dependencies](#upgrading-vulnerable-dependencies)
18+ - [Upgrading high-impact dependencies](#upgrading-high-impact-dependencies)
19+ - [Upgrading low-impact dependencies](#upgrading-low-impact-dependencies)
Original file line number Diff line number Diff line change 1+ # File with TOC
2+
3+ <!-- TOC -->
4+
5+ ## Subject 1
6+
7+ Some text
8+
9+ ### Subject 1.1
10+
11+ Some text
12+
13+ ### Subject 1.2
14+
15+ Some text
16+
17+ ## Subject 2
18+
19+ Some text
Original file line number Diff line number Diff line change 1+ <h1><a id='file-with-toc'></a>File with TOC</h1>
2+ <!-- TOC -->
3+ <h2><a id='table-of-contents'></a>Table of Contents</h2>
4+ <ul>
5+ <li><a href="#subject-1">Subject 1</a>
6+ <ul>
7+ <li><a href="#subject-11">Subject 1.1</a></li>
8+ <li><a href="#subject-12">Subject 1.2</a></li>
9+ </ul>
10+ </li>
11+ <li><a href="#subject-2">Subject 2</a></li>
12+ </ul>
13+ <h2><a id='subject-1'></a>Subject 1</h2>
14+ <p>Some text</p>
15+ <h3><a id='subject-11'></a>Subject 1.1</h3>
16+ <p>Some text</p>
17+ <h3><a id='subject-12'></a>Subject 1.2</h3>
18+ <p>Some text</p>
19+ <h2><a id='subject-2'></a>Subject 2</h2>
20+ <p>Some text</p>
Original file line number Diff line number Diff line change 28281. [File](/File)
29291. [File-with-Dashes](/File-with-Dashes)
30301. [File with Spaces](/File%20with%20Spaces)
31+ 1. [File with TOC](/File%20with%20TOC)
31321. [File without H1](/File%20without%20H1)
Original file line number Diff line number Diff line change 248248 expect ( doc . content ) . to have_tag :a , id : 'just-a-file'
249249 end
250250
251+ it "replaces <!-- TOC --> markers with table of contents" do
252+ doc = described_class . new "File with TOC"
253+ expect ( doc . content ) . to match_approval 'document-toc'
254+ end
255+
251256 context "when headers contain links" do
252257 subject { described_class . new "CHANGELOG" }
253258
You can’t perform that action at this time.
0 commit comments