raindown 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/raindown/toc.rb +10 -2
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b35949f91c9cf54ccb1ab0fe6b0e24a2e9529f830cd648f097015aba55acb135
|
|
4
|
+
data.tar.gz: 3b62d3623ea255e6767b349a3210c48a331bcdae8282d9a365adea680e2242e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c63653585217df9c3129b554f0619fe024916a73c7eaea2fcad53199ee2f790fbece26bf90c956fa716109080b6c457048acbc3bb39fa97d3520765b4d9ff47d
|
|
7
|
+
data.tar.gz: 1f6e1d91403fcfbf9f2968885bf94a227a1a114084a65bb8735c7dbdff4479b622f8fa3ea17fab42f7e3cc826372c726d1d90f137b50eac32a92f531b935f20a
|
data/lib/raindown/toc.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Raindown
|
|
|
15
15
|
TAG = /<[^>]*>/
|
|
16
16
|
|
|
17
17
|
def rewrite(document:, metadata: nil, bare: false)
|
|
18
|
-
headings =
|
|
18
|
+
headings = headings_below_title(markdown: document, metadata:, bare:)
|
|
19
19
|
return '' if headings.empty?
|
|
20
20
|
|
|
21
21
|
min_level = headings.map { |heading| heading[:level] }.min
|
|
@@ -27,7 +27,7 @@ module Raindown
|
|
|
27
27
|
|
|
28
28
|
# With the document's final HTML, the headings include ones its components render.
|
|
29
29
|
def render(document:, html: nil, metadata: nil, bare: false)
|
|
30
|
-
items =
|
|
30
|
+
items = headings_below_title(markdown: document, html:, metadata:, bare:).map do |heading|
|
|
31
31
|
"<li class='h#{heading[:level]}'><a href='##{heading[:id]}'>#{CGI.escapeHTML(heading[:text])}</a></li>"
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -43,6 +43,14 @@ module Raindown
|
|
|
43
43
|
HTML
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
# A lone top-level heading that starts the document is its title, so it's left out when there are headings below it.
|
|
47
|
+
def headings_below_title(**)
|
|
48
|
+
title, *below = headings = headings(**)
|
|
49
|
+
return headings if below.empty? || title[:level] != 1 || below.any? { it[:level] == 1 }
|
|
50
|
+
|
|
51
|
+
below
|
|
52
|
+
end
|
|
53
|
+
|
|
46
54
|
# The document's headings, from its final HTML, or else by rendering it with its components.
|
|
47
55
|
def headings(markdown:, html: nil, metadata: nil, bare: false)
|
|
48
56
|
html ||= Fragments.collect { Raindown.assembled(Context.new(document: markdown, metadata: metadata || NoMetadata, bare:)) }
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: raindown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.16.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-07 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: antlers
|