utopia-project 0.37.0 → 0.37.1
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
- checksums.yaml.gz.sig +0 -0
- data/lib/utopia/project/sidebar.rb +18 -26
- data/lib/utopia/project/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6467795f4ec1c68ecc0606fbd6ca86367532a9f4ba85ecd7a45d9246037c289
|
4
|
+
data.tar.gz: 143589e65aa521ef0ccab3886a02ccd86cd6e83519b91935ad3a1bf14086e1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67297da20eb02586984c38b3586cf844600b67179b50d00a13f15e264399cd83fe79420d64348139eabf368fc0d56fd73fe730b7f42c19c4247032e3423cf261
|
7
|
+
data.tar.gz: c384960157c37c7a3934a40c2b557fbdf9b054a889104be3599beba0d8d9ec9143c0523c72ebd14f1d853c9394f82b318078f57c9394de4ae039eb148169e782
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -3,21 +3,24 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2020-2025, by Samuel Williams.
|
5
5
|
|
6
|
+
require_relative "renderer"
|
7
|
+
|
6
8
|
module Utopia
|
7
9
|
module Project
|
8
10
|
# Generates a sidebar navigation from markdown document headings.
|
9
11
|
class Sidebar
|
12
|
+
|
10
13
|
# Represents a sidebar navigation entry with title, level, and anchor.
|
11
14
|
class Entry
|
12
|
-
def initialize(
|
13
|
-
@
|
15
|
+
def initialize(title_html, level, anchor)
|
16
|
+
@title_html = title_html
|
14
17
|
@level = level
|
15
18
|
@anchor = anchor
|
16
19
|
end
|
17
20
|
|
18
|
-
# The
|
19
|
-
# @attribute [
|
20
|
-
attr :
|
21
|
+
# The HTML content of the heading.
|
22
|
+
# @attribute [XRB::Markup]
|
23
|
+
attr :title_html
|
21
24
|
|
22
25
|
# The heading level (1-6).
|
23
26
|
# @attribute [Integer]
|
@@ -68,13 +71,13 @@ module Utopia
|
|
68
71
|
if entry.level > 2
|
69
72
|
builder.tag :li, {class: "level-#{entry.level}"} do
|
70
73
|
builder.tag :a, {href: "##{entry.anchor}"} do
|
71
|
-
builder
|
74
|
+
builder << entry.title_html
|
72
75
|
end
|
73
76
|
end
|
74
77
|
else
|
75
78
|
builder.tag :li do
|
76
79
|
builder.tag :a, {href: "##{entry.anchor}"} do
|
77
|
-
builder
|
80
|
+
builder << entry.title_html
|
78
81
|
end
|
79
82
|
end
|
80
83
|
end
|
@@ -85,38 +88,27 @@ module Utopia
|
|
85
88
|
end
|
86
89
|
|
87
90
|
private
|
88
|
-
|
91
|
+
|
89
92
|
def self.extract_headings_from_document(document)
|
90
93
|
headings = []
|
91
94
|
return headings unless document&.root
|
92
95
|
|
93
96
|
document.root.walk do |node|
|
94
97
|
if node.type == :header
|
95
|
-
|
98
|
+
next if node.header_level < 2 or node.header_level > 3
|
99
|
+
|
100
|
+
fragment = node.dup.extract_children
|
101
|
+
|
102
|
+
title = XRB::Markup.raw(fragment.to_html)
|
96
103
|
level = node.header_level
|
97
|
-
anchor =
|
104
|
+
anchor = Markly::Renderer::HTML.anchor_for(fragment)
|
98
105
|
|
99
|
-
|
100
|
-
if title && !title.empty? && level >= 2
|
101
|
-
headings << Entry.new(title, level, anchor)
|
102
|
-
end
|
106
|
+
headings << Entry.new(title, level, anchor)
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
106
110
|
headings
|
107
111
|
end
|
108
|
-
|
109
|
-
def self.generate_anchor(title)
|
110
|
-
# Generate anchor ID exactly like Markly renderer does it
|
111
|
-
title.downcase
|
112
|
-
.gsub(/\s+/, "-") # Replace spaces with hyphens
|
113
|
-
.gsub("&", "&") # HTML encode ampersand
|
114
|
-
.gsub('"', """) # HTML encode quotes
|
115
|
-
.gsub("'", "'") # HTML encode single quotes
|
116
|
-
.gsub("<", "<") # HTML encode less than
|
117
|
-
.gsub(">", ">") # HTML encode greater than
|
118
|
-
end
|
119
|
-
|
120
112
|
end
|
121
113
|
end
|
122
114
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|