jekyll-titles-from-headings 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-titles-from-headings.rb +2 -0
- data/lib/jekyll-titles-from-headings/context.rb +13 -0
- data/lib/jekyll-titles-from-headings/filters.rb +11 -0
- data/lib/jekyll-titles-from-headings/generator.rb +29 -2
- data/lib/jekyll-titles-from-headings/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 367e754467d30e9b6ef62d13fb7c1f0030d7c165
|
4
|
+
data.tar.gz: 0e0f69aad2c526cc74cf5a32318879b05013e35e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44d0aa1fdb4dc000ba159948723e4314014d67917be7a131066ce99d079452f8e40963d0cd33d95295fee28345333f6b8f099b92c39375ccb139e6285935c9f
|
7
|
+
data.tar.gz: 8f03486d52cb21770c8cb0314f090ab4096f1da54c8904fffe51933d5e406a3eda80cc91180d451c3f73adfcc27203348ec0f229a891157cd2a9ce9495bbf304
|
@@ -2,8 +2,23 @@ module JekyllTitlesFromHeadings
|
|
2
2
|
class Generator < Jekyll::Generator
|
3
3
|
attr_accessor :site
|
4
4
|
|
5
|
-
TITLE_REGEX =
|
5
|
+
TITLE_REGEX =
|
6
|
+
%r!
|
7
|
+
\A\s* # Beginning and whitespace
|
8
|
+
(?: # either
|
9
|
+
\#{1,3}\s+(.*) # atx-style header
|
10
|
+
| # or
|
11
|
+
(.*)\r?\n[-=]+\s* # Setex-style header
|
12
|
+
)$ # end of line
|
13
|
+
!x
|
6
14
|
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
15
|
+
STRIP_MARKUP_FILTERS = %i[
|
16
|
+
markdownify strip_html normalize_whitespace
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
# Regex to strip extra markup still present after markdownify
|
20
|
+
# (footnotes at the moment).
|
21
|
+
EXTRA_MARKUP_REGEX = %r!\[\^[^\]]*\]!
|
7
22
|
|
8
23
|
safe true
|
9
24
|
priority :lowest
|
@@ -40,9 +55,21 @@ module JekyllTitlesFromHeadings
|
|
40
55
|
def title_for(document)
|
41
56
|
return document.data["title"] if title?(document)
|
42
57
|
matches = document.content.match(TITLE_REGEX)
|
43
|
-
matches[1] if matches
|
58
|
+
strip_markup(matches[1] || matches[2]) if matches
|
44
59
|
rescue ArgumentError => e
|
45
60
|
raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
|
46
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def strip_markup(string)
|
66
|
+
STRIP_MARKUP_FILTERS.reduce(string) do |memo, method|
|
67
|
+
filters.public_send(method, memo)
|
68
|
+
end.gsub(EXTRA_MARKUP_REGEX, "")
|
69
|
+
end
|
70
|
+
|
71
|
+
def filters
|
72
|
+
@filters ||= JekyllTitlesFromHeadings::Filters.new(site)
|
73
|
+
end
|
47
74
|
end
|
48
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-titles-from-headings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- LICENSE.md
|
63
63
|
- README.md
|
64
64
|
- lib/jekyll-titles-from-headings.rb
|
65
|
+
- lib/jekyll-titles-from-headings/context.rb
|
66
|
+
- lib/jekyll-titles-from-headings/filters.rb
|
65
67
|
- lib/jekyll-titles-from-headings/generator.rb
|
66
68
|
- lib/jekyll-titles-from-headings/version.rb
|
67
69
|
homepage: https://github.com/benbalter/jekyll-titles-from-headings
|