asciidoctor-html 2.0.0 → 2.0.2
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/CHANGELOG.md +8 -0
- data/assets/css/styles.css +2 -2
- data/lib/asciidoctor/html/book.rb +13 -15
- data/lib/asciidoctor/html/book_template.rb +1 -1
- data/lib/asciidoctor/html/flip.rb +24 -22
- data/lib/asciidoctor/html/list.rb +3 -2
- data/lib/asciidoctor/html/pagination.rb +2 -2
- data/lib/asciidoctor/html/subnav_block_macro.rb +8 -8
- data/lib/asciidoctor/html/version.rb +1 -1
- metadata +1 -1
|
@@ -51,7 +51,8 @@ module Asciidoctor
|
|
|
51
51
|
:chaptitle,
|
|
52
52
|
:chapheading,
|
|
53
53
|
:chapsubheading,
|
|
54
|
-
:index
|
|
54
|
+
:index,
|
|
55
|
+
:outline)
|
|
55
56
|
|
|
56
57
|
# opts:
|
|
57
58
|
# - title
|
|
@@ -134,7 +135,8 @@ module Asciidoctor
|
|
|
134
135
|
chaptitle: chapsubheading,
|
|
135
136
|
chapheading: (chapref unless index.zero?),
|
|
136
137
|
chapsubheading:,
|
|
137
|
-
index
|
|
138
|
+
index:,
|
|
139
|
+
outline: outline(key, doc)
|
|
138
140
|
)
|
|
139
141
|
process_doc key, doc, tdata, chapref
|
|
140
142
|
end
|
|
@@ -152,7 +154,8 @@ module Asciidoctor
|
|
|
152
154
|
chaptitle: BookTemplate.appendix_title(chapname, chapnum, chapsubheading, num_appendices),
|
|
153
155
|
chapheading: chapref,
|
|
154
156
|
chapsubheading:,
|
|
155
|
-
index
|
|
157
|
+
index:,
|
|
158
|
+
outline: outline(key, doc)
|
|
156
159
|
)
|
|
157
160
|
process_doc key, doc, tdata, chapref
|
|
158
161
|
end
|
|
@@ -202,22 +205,18 @@ module Asciidoctor
|
|
|
202
205
|
].reject(&:empty?).join(" and ")
|
|
203
206
|
end
|
|
204
207
|
|
|
205
|
-
def outline(doc)
|
|
206
|
-
return doc.attr("outline") if doc.attr?("outline")
|
|
207
|
-
|
|
208
|
+
def outline(key, doc, absolute: true)
|
|
208
209
|
items = []
|
|
209
210
|
doc.sections.each do |section|
|
|
210
211
|
next unless section.id && section.level == 1
|
|
211
212
|
|
|
212
213
|
prefix = Utils.display_sectnum(section) if section.numbered
|
|
213
|
-
|
|
214
|
+
url = "#{"#{key}.html" if absolute}##{section.id}"
|
|
215
|
+
items << BookTemplate.nav_item(url, "#{prefix}#{section.title}")
|
|
214
216
|
end
|
|
215
217
|
return "" unless items.size > 1
|
|
216
218
|
|
|
217
|
-
|
|
218
|
-
outline = "<ul>#{items.join "\n"}</ul>"
|
|
219
|
-
doc.set_attr("outline", outline)
|
|
220
|
-
outline
|
|
219
|
+
"<ul>#{items.join "\n"}</ul>"
|
|
221
220
|
end
|
|
222
221
|
|
|
223
222
|
def html(docs)
|
|
@@ -235,7 +234,7 @@ module Asciidoctor
|
|
|
235
234
|
def nav_items(active_key = -1, doc = nil)
|
|
236
235
|
items = @templates.map do |k, td|
|
|
237
236
|
active = (k == active_key)
|
|
238
|
-
subnav = active && doc ? outline(doc) : ""
|
|
237
|
+
subnav = active && doc ? outline(k, doc, absolute: false) : ""
|
|
239
238
|
navtext = BookTemplate.nav_text td.chapprefix, td.chaptitle
|
|
240
239
|
BookTemplate.nav_item "#{k}.html", navtext, subnav, active:
|
|
241
240
|
end
|
|
@@ -251,13 +250,12 @@ module Asciidoctor
|
|
|
251
250
|
def build_template(key, doc)
|
|
252
251
|
tdata = @templates[key]
|
|
253
252
|
nav_items = nav_items key, doc
|
|
254
|
-
|
|
255
|
-
subnav = has_subnav ? outline(doc) : ""
|
|
253
|
+
outline = outline key, doc, absolute: false
|
|
256
254
|
content = ERB.new(doc.convert).result(binding)
|
|
257
255
|
BookTemplate.html(
|
|
258
256
|
content,
|
|
259
257
|
nav_items,
|
|
260
|
-
has_subnav
|
|
258
|
+
has_subnav: !outline.empty?,
|
|
261
259
|
title: @title,
|
|
262
260
|
short_title: @short_title,
|
|
263
261
|
authors: display_authors(doc),
|
|
@@ -99,7 +99,7 @@ module Asciidoctor
|
|
|
99
99
|
def self.main(opts)
|
|
100
100
|
<<~HTML
|
|
101
101
|
<main id="main" class="main">
|
|
102
|
-
<div id="content-container" class="content-container dynamic-width">
|
|
102
|
+
<div id="content-container" class="content-container dynamic-width" tabindex="0">
|
|
103
103
|
#{chapheader opts[:chapheading], opts[:chapsubheading]}
|
|
104
104
|
<div class="chaphead d-block">
|
|
105
105
|
#{toggle_button opts[:pagestyle] if opts[:has_subnav]}
|
|
@@ -17,6 +17,8 @@ module Asciidoctor
|
|
|
17
17
|
const sectsById = { "page": []};
|
|
18
18
|
|
|
19
19
|
const page = document.getElementById('page');
|
|
20
|
+
const focusEl = document.getElementById('content-container');
|
|
21
|
+
const searchForm = document.getElementById('search-form');
|
|
20
22
|
const chapheading = page.querySelector('.chapheading');
|
|
21
23
|
const chaptitle = page.querySelector('.chaptitle');
|
|
22
24
|
|
|
@@ -45,6 +47,12 @@ module Asciidoctor
|
|
|
45
47
|
sects[sects.length - 1].classList.add('last-section-multipage');
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
function focusOnLoad() {
|
|
51
|
+
if(searchForm) return;
|
|
52
|
+
|
|
53
|
+
focusEl.focus({preventScroll: true});
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
function updatePaginator(prev, next) {
|
|
49
57
|
const paginator = document.querySelector('.paginator');
|
|
50
58
|
if(!paginator) return;
|
|
@@ -53,6 +61,7 @@ module Asciidoctor
|
|
|
53
61
|
if(next) {
|
|
54
62
|
const nextH = next.querySelector(':scope > h2');
|
|
55
63
|
const nextLink = document.createElement('a');
|
|
64
|
+
nextLink.id = "flip-forward"
|
|
56
65
|
const nextSectText = nextH && nextH.innerHTML;
|
|
57
66
|
nextLink.href = '#' + next.id;
|
|
58
67
|
nextLink.innerHTML = `
|
|
@@ -68,6 +77,7 @@ module Asciidoctor
|
|
|
68
77
|
const prevH = prev.querySelector(':scope > h2');
|
|
69
78
|
const prevSectitle = prevH && (prevH.innerHTML + ' ');
|
|
70
79
|
const prevLink = document.createElement('a');
|
|
80
|
+
prevLink.id = "flip-back"
|
|
71
81
|
let prevSectText = prevSectitle || chapheading &&
|
|
72
82
|
('<span class="title-prefix">' + chapheading.textContent + '</span><br>');
|
|
73
83
|
if(!prevH) prevSectText += chaptitle.textContent;
|
|
@@ -85,7 +95,10 @@ module Asciidoctor
|
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
function flip(e) {
|
|
88
|
-
if(!page.classList.contains('multi'))
|
|
98
|
+
if(!page.classList.contains('multi')) {
|
|
99
|
+
focusOnLoad();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
89
102
|
|
|
90
103
|
e && e.preventDefault();
|
|
91
104
|
|
|
@@ -119,8 +132,7 @@ module Asciidoctor
|
|
|
119
132
|
|
|
120
133
|
nav.forEach(el => {
|
|
121
134
|
const a = el.querySelector('a');
|
|
122
|
-
|
|
123
|
-
el.classList.toggle('active', id == href.substring(1));
|
|
135
|
+
a && a.hash && el.classList.toggle('active', id == a.hash.substring(1));
|
|
124
136
|
});
|
|
125
137
|
|
|
126
138
|
ADHT.nudgeMenuBtn();
|
|
@@ -137,6 +149,8 @@ module Asciidoctor
|
|
|
137
149
|
left: 0
|
|
138
150
|
});
|
|
139
151
|
}
|
|
152
|
+
|
|
153
|
+
focusOnLoad();
|
|
140
154
|
}
|
|
141
155
|
flip();
|
|
142
156
|
|
|
@@ -158,25 +172,11 @@ module Asciidoctor
|
|
|
158
172
|
});
|
|
159
173
|
}
|
|
160
174
|
function move(direction) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if(direction == 'left') {
|
|
167
|
-
const prevLi = activeSubLi && activeSubLi.previousElementSibling ||
|
|
168
|
-
!activeSubLi && activeTopLevelLi.previousElementSibling;
|
|
169
|
-
if(prevLi) href = prevLi.firstElementChild.href;
|
|
170
|
-
} else if(direction == 'right') {
|
|
171
|
-
const nextLi = !activeSubLi &&
|
|
172
|
-
(page.classList.contains('multi') && activeTopLevelLi.querySelector('ul > li') ||
|
|
173
|
-
activeTopLevelLi.nextElementSibling) ||
|
|
174
|
-
activeSubLi &&
|
|
175
|
-
(activeSubLi.nextElementSibling || activeTopLevelLi.nextElementSibling) ||
|
|
176
|
-
activeSubLi || activeTopLevelLi;
|
|
177
|
-
href = nextLi.firstElementChild.href;
|
|
178
|
-
}
|
|
179
|
-
navigation.navigate(href);
|
|
175
|
+
let link;
|
|
176
|
+
if(direction == 'right' && (link = document.getElementById('flip-forward')))
|
|
177
|
+
navigation.navigate(link.href);
|
|
178
|
+
else if (direction == 'left' && (link = document.getElementById('flip-back')))
|
|
179
|
+
navigation.navigate(link.href);
|
|
180
180
|
}
|
|
181
181
|
addEventListener('hashchange', flip);
|
|
182
182
|
addEventListener('keyup', function(e) {
|
|
@@ -194,6 +194,8 @@ module Asciidoctor
|
|
|
194
194
|
const viewmode = link.dataset.viewmode;
|
|
195
195
|
changeViewmode(viewmode);
|
|
196
196
|
}));
|
|
197
|
+
|
|
198
|
+
page.classList.add('loaded');
|
|
197
199
|
})();
|
|
198
200
|
JS
|
|
199
201
|
end
|
|
@@ -13,7 +13,7 @@ module Asciidoctor
|
|
|
13
13
|
"list",
|
|
14
14
|
"list-#{node.context}",
|
|
15
15
|
("level-#{level} pseudocode" if flat),
|
|
16
|
-
node.role
|
|
16
|
+
node.title? ? nil : node.role
|
|
17
17
|
].compact
|
|
18
18
|
classes << "list-checklist" if node.option?("checklist")
|
|
19
19
|
classes << "list-unmarked" if node.option?("unmarked")
|
|
@@ -25,7 +25,8 @@ module Asciidoctor
|
|
|
25
25
|
result << display_list_item(item, inside:)
|
|
26
26
|
end
|
|
27
27
|
result << %(</#{tag_name}> <!-- .level-#{level} -->\n)
|
|
28
|
-
|
|
28
|
+
wrap_classes = %(list-wrapper#{" #{node.role}" if node.title? && node.role})
|
|
29
|
+
Utils.wrap_id_classes_with_title result.join("\n"), node, node.id, wrap_classes
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def self.display_list_item(item, inside: false)
|
|
@@ -16,7 +16,7 @@ module Asciidoctor
|
|
|
16
16
|
]
|
|
17
17
|
html << if prv
|
|
18
18
|
<<~HTML
|
|
19
|
-
<a href="#{prv.url}">
|
|
19
|
+
<a id="flip-back" href="#{prv.url}">
|
|
20
20
|
<div><i class="bi bi-chevron-compact-left"></i></div>
|
|
21
21
|
<div>#{%(<span class="title-prefix">#{prv.title}</span><br>) if prv.title}#{prv.text}</div>
|
|
22
22
|
</a>
|
|
@@ -26,7 +26,7 @@ module Asciidoctor
|
|
|
26
26
|
end
|
|
27
27
|
html << if nxt
|
|
28
28
|
<<~HTML
|
|
29
|
-
<a href="#{nxt.url}">
|
|
29
|
+
<a id="flip-forward" href="#{nxt.url}">
|
|
30
30
|
<div>#{%(<span class="title-prefix">#{nxt.title}</span><br>) if nxt.title}#{nxt.text}</div>
|
|
31
31
|
<div><i class="bi bi-chevron-compact-right"></i></div>
|
|
32
32
|
</a>
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "asciidoctor"
|
|
4
|
+
require "pathname"
|
|
4
5
|
|
|
5
6
|
module Asciidoctor
|
|
6
7
|
module Html
|
|
7
|
-
# Inserts a subnav for
|
|
8
|
+
# Inserts a subnav for a chapter
|
|
8
9
|
class SubnavBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
|
9
10
|
use_dsl
|
|
10
11
|
|
|
11
12
|
named :subnav
|
|
12
13
|
name_positional_attributes "title"
|
|
13
14
|
|
|
14
|
-
def process(parent,
|
|
15
|
-
|
|
15
|
+
def process(parent, target, attrs)
|
|
16
|
+
doc_key = Pathname(target).sub_ext "" unless target.empty?
|
|
17
|
+
title = %(<h5 class="block-title">#{parent.apply_subs attrs["title"]}</h5>) if attrs.include?("title")
|
|
16
18
|
bordered_class = " bordered" if attrs.include?("border")
|
|
17
19
|
border_width = attrs["border"].to_i if bordered_class
|
|
18
20
|
style = %( style="border-top-width: #{border_width}px; border-bottom-width: #{border_width}px;") if border_width
|
|
19
|
-
roles = attrs["role"] if attrs.include?("role")
|
|
20
|
-
roles = attrs["roles"] if attrs.include?("roles")
|
|
21
|
-
role = " #{roles.tr ",", " "}" if roles
|
|
21
|
+
roles = " #{attrs["role"]}" if attrs.include?("role")
|
|
22
22
|
content = <<~HTML
|
|
23
|
-
<div class="subnav#{bordered_class}#{
|
|
23
|
+
<div class="subnav#{bordered_class}#{roles}"#{style}>
|
|
24
24
|
#{title}
|
|
25
25
|
<nav>
|
|
26
|
-
<%=
|
|
26
|
+
<%= templates.dig("#{doc_key}", "outline") || outline %>
|
|
27
27
|
</nav>
|
|
28
28
|
</div>
|
|
29
29
|
HTML
|