asciidoctor-html 2.0.1 → 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.
@@ -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
- items << BookTemplate.nav_item("##{section.id}", "#{prefix}#{section.title}")
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
- doc.set_attr("has-subnav", true)
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
- has_subnav = doc.attr?("has-subnav")
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),
@@ -61,6 +61,7 @@ module Asciidoctor
61
61
  if(next) {
62
62
  const nextH = next.querySelector(':scope > h2');
63
63
  const nextLink = document.createElement('a');
64
+ nextLink.id = "flip-forward"
64
65
  const nextSectText = nextH && nextH.innerHTML;
65
66
  nextLink.href = '#' + next.id;
66
67
  nextLink.innerHTML = `
@@ -76,6 +77,7 @@ module Asciidoctor
76
77
  const prevH = prev.querySelector(':scope > h2');
77
78
  const prevSectitle = prevH && (prevH.innerHTML + ' ');
78
79
  const prevLink = document.createElement('a');
80
+ prevLink.id = "flip-back"
79
81
  let prevSectText = prevSectitle || chapheading &&
80
82
  ('<span class="title-prefix">' + chapheading.textContent + '</span><br>');
81
83
  if(!prevH) prevSectText += chaptitle.textContent;
@@ -130,8 +132,7 @@ module Asciidoctor
130
132
 
131
133
  nav.forEach(el => {
132
134
  const a = el.querySelector('a');
133
- const href = a && a.getAttribute('href');
134
- el.classList.toggle('active', id == href.substring(1));
135
+ a && a.hash && el.classList.toggle('active', id == a.hash.substring(1));
135
136
  });
136
137
 
137
138
  ADHT.nudgeMenuBtn();
@@ -171,25 +172,11 @@ module Asciidoctor
171
172
  });
172
173
  }
173
174
  function move(direction) {
174
- const activeTopLevelLi = document.querySelector('#sidebar nav > ul > li.active');
175
- if(!activeTopLevelLi) return;
176
-
177
- const activeSubLi = activeTopLevelLi.querySelector('ul > li.active');
178
- let href = '#page';
179
- if(direction == 'left') {
180
- const prevLi = activeSubLi && activeSubLi.previousElementSibling ||
181
- !activeSubLi && activeTopLevelLi.previousElementSibling;
182
- if(prevLi) href = prevLi.firstElementChild.href;
183
- } else if(direction == 'right') {
184
- const nextLi = !activeSubLi &&
185
- (page.classList.contains('multi') && activeTopLevelLi.querySelector('ul > li') ||
186
- activeTopLevelLi.nextElementSibling) ||
187
- activeSubLi &&
188
- (activeSubLi.nextElementSibling || activeTopLevelLi.nextElementSibling) ||
189
- activeSubLi || activeTopLevelLi;
190
- href = nextLi.firstElementChild.href;
191
- }
192
- 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);
193
180
  }
194
181
  addEventListener('hashchange', flip);
195
182
  addEventListener('keyup', function(e) {
@@ -207,6 +194,8 @@ module Asciidoctor
207
194
  const viewmode = link.dataset.viewmode;
208
195
  changeViewmode(viewmode);
209
196
  }));
197
+
198
+ page.classList.add('loaded');
210
199
  })();
211
200
  JS
212
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
- Utils.wrap_id_classes_with_title result.join("\n"), node, node.id, "list-wrapper"
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 current chapter
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, _target, attrs)
15
- title = %(<h5 class="block-title">#{attrs["title"]}</h5>) if attrs.include?("title")
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}#{role}"#{style}>
23
+ <div class="subnav#{bordered_class}#{roles}"#{style}>
24
24
  #{title}
25
25
  <nav>
26
- <%= subnav %>
26
+ <%= templates.dig("#{doc_key}", "outline") || outline %>
27
27
  </nav>
28
28
  </div>
29
29
  HTML
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Html
5
- VERSION = "2.0.1"
5
+ VERSION = "2.0.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Rajani