html_toc 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/html_toc.rb +4 -4
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b307e27db1ddd1187a5b57fbbbb73f631d454c55
|
4
|
+
data.tar.gz: f633df32057c695f0746466703d94c8b5262d1f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0d6218b679c46bc1e802116b44899a2df27331702d6d50e6d161fdc5b1f8edaf9f20b337e1a6e28ea2d3fb095a951b62fa1a90baa269629d38ee3d8303c23cb
|
7
|
+
data.tar.gz: 88b0c8acb1abc416f8091f74f7b0b648973f81802ed0126f14f28697e69bfc7aa101e05159e249e79f06718f26f22dfe38b20e301c37582c9c54c3f08c982a93
|
data/README.md
CHANGED
@@ -8,11 +8,11 @@ HtmlToc is a Ruby module that post-processes an HTML document to built a table o
|
|
8
8
|
|
9
9
|
The gem consists of a single module, <span style="color:#009900;">HtmlToc</span>, which exposes a single public method, <span style="color:#009900;">process</span>.
|
10
10
|
|
11
|
-
<span style="color:#009900;">#process</span> starts by performing a case-insensitive search for a
|
11
|
+
<span style="color:#009900;">#process</span> starts by performing a case-insensitive search for a pseudo-tag, **<toc />**. If it is found, the unmodified source text is return.
|
12
12
|
|
13
|
-
If the
|
13
|
+
If the tag is found, <span style="color:#009900;">#process</span> scans for header tags falling within a provided range. If a matching header does not already have an id attribute, one is added. If no matching headers are found, the **<toc />** pseudo-tag is removed and the modified source text is returned.
|
14
14
|
|
15
|
-
If headers are found, a link is generated for each matching header. The link text is taken from the header text, and the link's href points to the header's id. Each link wrapped in a div tag; the div is given a class name that matches is level relative to the search range. The link divs are wrapped in a few more divs with unique ids to create the table of contents. Lastly, the table of contents replaces the
|
15
|
+
If headers are found, a link is generated for each matching header. The link text is taken from the header text, and the link's href points to the header's id. Each link wrapped in a div tag; the div is given a class name that matches is level relative to the search range. The link divs are wrapped in a few more divs with unique ids to create the table of contents. Lastly, the table of contents replaces the **<toc />** pseudo-tag and the modified source is returned. The classes and id allow the page to be styled to match the website's design context. The resulting table of contents might look like this:
|
16
16
|
|
17
17
|
<div style="border:solid 1px #000000;margin-left:1em;">
|
18
18
|
|
@@ -40,7 +40,7 @@ If headers are found, a link is generated for each matching header. The link tex
|
|
40
40
|
|
41
41
|
>**source** is a string holding the HTML source.
|
42
42
|
|
43
|
-
>**h_tags** is a range of integers giving the indexes of the header tags that will be used to the table of contents. The method iterates through it to build the regular expression <span style="color:#800000;">/<h#{x}(?: .\*?)?>(.\*?)<\/h#{x}>
|
43
|
+
>**h_tags** is a range of integers giving the indexes of the header tags that will be used to the table of contents. The method iterates through it to build the regular expression <span style="color:#800000;">/<h#{x}(?: .\*?)?>(.\*?)<\/h#{x}>/i</span>.
|
44
44
|
|
45
45
|
>**show_toggle** flags whether or not to include a toggle button in the table of contents header. The span is programmed to call a Javascript method, ShowHideToc(). The implementing script is *not* included: it must be supplied by the programmer.
|
46
46
|
|
@@ -68,6 +68,7 @@ See **sample/html_toc.js** for the Javascript to toggle visibility of the table
|
|
68
68
|
|
69
69
|
##Change log
|
70
70
|
|
71
|
+
**1.2** - Fixed some issues where matches were not case insensitive, and change the table of contents indicator from a keyword token to a pseudo-tag.
|
71
72
|
**1.1** - Added keyword arguments.
|
72
73
|
**1.0** - Initial deployment.
|
73
74
|
|
data/lib/html_toc.rb
CHANGED
@@ -6,7 +6,7 @@ module HtmlToc
|
|
6
6
|
def self.process(source:, h_tags: Range.new(2, 6), show_toggle: false, use_numbers: false)
|
7
7
|
|
8
8
|
#Search regex for {{toc}}
|
9
|
-
|
9
|
+
token = /<toc\s*\/>|\[\[toc\]\]/i #Allow for a token of either <toc/> or [[toc]]
|
10
10
|
|
11
11
|
#If there is no token, just return the source
|
12
12
|
if source !~ token then
|
@@ -36,7 +36,7 @@ module HtmlToc
|
|
36
36
|
depth += 1
|
37
37
|
|
38
38
|
#Regex for indexed header tags
|
39
|
-
test = /<h#{x}(?: .*?)?>(.*?)<\/h#{x}>/
|
39
|
+
test = /<h#{x}(?: .*?)?>(.*?)<\/h#{x}>/i
|
40
40
|
|
41
41
|
#Scan, and use the resulting MatchData objects
|
42
42
|
#to populate the hash
|
@@ -134,7 +134,7 @@ private
|
|
134
134
|
@end_index = md.end(0)
|
135
135
|
|
136
136
|
#If the tag does not have an ID, give it one
|
137
|
-
tag_id = @text.match(/\bid(\s*?)=(\s*?)(["'])(.*?)\3/)
|
137
|
+
tag_id = @text.match(/\bid(\s*?)=(\s*?)(["'])(.*?)\3/i)
|
138
138
|
if tag_id == nil
|
139
139
|
@@unique_id += 1
|
140
140
|
id = " id='_id__#{@@unique_id}'"
|
@@ -145,7 +145,7 @@ private
|
|
145
145
|
|
146
146
|
def id
|
147
147
|
#TODO Allow for undelimited attribute values, as in HTML5
|
148
|
-
tag_id = @text.match(/\bid(\s*?)=(\s*?)(["'])(.*?)\3/)
|
148
|
+
tag_id = @text.match(/\bid(\s*?)=(\s*?)(["'])(.*?)\3/i)
|
149
149
|
|
150
150
|
if tag_id == nil
|
151
151
|
""
|
metadata
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Gadow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "This gem is intended to be used in Rails pre-processing, after the page
|
14
14
|
has been generated but before it is delivered to the requestor. \n\nIt does a case-insensitive
|
15
|
-
search in the source text for
|
16
|
-
be placed. If the
|
17
|
-
|
18
|
-
id attribute if the header does not already have one. If no headers were found,
|
19
|
-
it will remove the
|
15
|
+
search in the source text for the pseudo-tag <toc />, which marks where the table
|
16
|
+
of contents will be placed. If the tag is not found, the unmodified source is returned.\n\nIf
|
17
|
+
the tag is found, it searches the text for header tags in a given range, and add
|
18
|
+
an id attribute if the header does not already have one. If no headers were found,
|
19
|
+
it will remove the tag and return the modified source. \n\nIf there are headers,
|
20
20
|
a link is generated for each one, using the header's text and id for the link's
|
21
21
|
text and href. The links are wrapped in some divs, with classes and ids added so
|
22
|
-
the table of contents can be styled. The
|
23
|
-
contents, and the the modified source is returned.\n"
|
22
|
+
the table of contents can be styled. The <toc /> pseudo-tag is then replaced with
|
23
|
+
the table of contents, and the the modified source is returned.\n"
|
24
24
|
email: gpg@gregory-gadow.net
|
25
25
|
executables: []
|
26
26
|
extensions: []
|