madness 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/madness.rb +4 -1
- data/lib/madness/document.rb +29 -0
- data/lib/madness/table_of_contents.rb +2 -2
- data/lib/madness/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe93b51cce9d5f1e2b37597b86bbcab62273fd2ba588d013308b194bb607d20e
|
4
|
+
data.tar.gz: 4b5e8a9de2af92f7aef8fa86792c8f3156ae9aba4b5049507693c2467dcc439c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e416333ece7eb2a236a07593c31f78cb93919f8842b5fede75baff6ae6e07d956ff0b1f30501c1be99416aab4ce036885d49800eeea5d38d5f811745d4c55d
|
7
|
+
data.tar.gz: d237b707b9a7d7a6d9334942a760811f51463a9aa04c007f54789bfa89be08cd04ac6bf7e6f946d86aa45302b50d3d6e4e7c5d4d83ffec88fb4a42c65cdb063c
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ searching for local, markdown based documentation directories.
|
|
61
61
|
- Configure with a configuration file or command arguments.
|
62
62
|
- Fully customizable theme.
|
63
63
|
- Automatic generation of navigation sidebar.
|
64
|
-
- Automatic generation of Table of Contents.
|
64
|
+
- Automatic generation of Table of Contents (site-wide and inline).
|
65
65
|
|
66
66
|
## Usage
|
67
67
|
|
@@ -179,8 +179,17 @@ will be automatically added based on the file name.
|
|
179
179
|
|
180
180
|
## Table of Contents Generation
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
### Site-wide
|
183
|
+
|
184
|
+
To generate a Table of Contents file for the entire site (for the directories
|
185
|
+
and files), run `madness --toc FILENAME`
|
186
|
+
|
187
|
+
### Inline
|
188
|
+
|
189
|
+
If you have long markdown documents, and you wish to add an inline Table of
|
190
|
+
Contents for them, simply add an HTML comment `<!-- TOC -->` where you want
|
191
|
+
the Table of Contents to be generated. The inserted list will only consider
|
192
|
+
H2 and H3 headings.
|
184
193
|
|
185
194
|
## Hidden Directories
|
186
195
|
|
data/lib/madness.rb
CHANGED
data/lib/madness/document.rb
CHANGED
@@ -99,6 +99,7 @@ module Madness
|
|
99
99
|
def markdown_to_html
|
100
100
|
doc = CommonMarker.render_doc markdown, :DEFAULT, [:table]
|
101
101
|
|
102
|
+
replace_toc_marker doc
|
102
103
|
add_anchor_ids doc
|
103
104
|
html = doc.to_html :UNSAFE
|
104
105
|
html = syntax_highlight(html) if config.highlighter
|
@@ -121,6 +122,34 @@ module Madness
|
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
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
|
+
|
124
153
|
# If the document does not start with an H1 tag, add it.
|
125
154
|
def prepend_h1(html)
|
126
155
|
unless html[0..3] == "<h1>"
|
@@ -5,7 +5,7 @@ module Madness
|
|
5
5
|
|
6
6
|
attr_reader :dir
|
7
7
|
|
8
|
-
def initialize(dir=nil)
|
8
|
+
def initialize(dir = nil)
|
9
9
|
@dir = dir || docroot
|
10
10
|
end
|
11
11
|
|
@@ -20,7 +20,7 @@ module Madness
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def toc!(path=dir, indent=0)
|
23
|
+
def toc!(path = dir, indent = 0)
|
24
24
|
list = Directory.new(path).list
|
25
25
|
|
26
26
|
result = []
|
data/lib/madness/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coderay
|
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
327
327
|
- !ruby/object:Gem::Version
|
328
328
|
version: '0'
|
329
329
|
requirements: []
|
330
|
-
rubygems_version: 3.1.
|
330
|
+
rubygems_version: 3.1.4
|
331
331
|
signing_key:
|
332
332
|
specification_version: 4
|
333
333
|
summary: Instant Markdown Server
|