asciidoctor-tabs 1.0.0.alpha.2 → 1.0.0.alpha.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3efce4ce7fa405dd4983609797c24e85e5ee768ff1e70ee3df4e702cd579d79
4
- data.tar.gz: b7671c6c76d775c1e46850fd0464c45e9b4ef7f9478c478b5f8c13d9a2cebb02
3
+ metadata.gz: e968b72b74144aad60adceb6290712b43017a61b74cc80c73793f474473e59c3
4
+ data.tar.gz: c7a33865929a61775548be25bda28627c6d9687e68e5d498134d3d87a4eef82b
5
5
  SHA512:
6
- metadata.gz: 18b40647d4c424f1d9ce9749c7ca038342ae31ce4660ba4099b89cf9ca5a4c37540eb984384212f74f7b11b8987b9762847ff32710b2372a9bb3f186a720cd31
7
- data.tar.gz: 21296914a580547da6f0703af319390351f9326a18ccc99b51719482fa6e73f2e466b6d2f9b0e99c673d7337aaf32faa8cc7a1d221f9b9bc5b6dc427b89bef34
6
+ metadata.gz: afdc6a70cec6b9a9519a9f8d72a29e234099ab3b58ed0cceabdcfff3a14574ad905214af88b6c32ffa527994607d30d3ed66403c22f4c60442cd318fd2f9dc7c
7
+ data.tar.gz: d09843fadb14ddee7d2fa5baf42e0125faeebe6342f7428175100ad7d0401cb6d8693045d51dfe53225e637849cefd15085ca7c7d52ec94f847d3949fc31e2a4
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,48 @@
4
4
  This document provides a curated view of the changes to Asciidoctor Tabs per release.
5
5
  For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
6
6
 
7
+ == 1.0.0-alpha.4 (2022-10-08) - @mojavelinux
8
+
9
+ === Added
10
+
11
+ * Define exports for behavior (tabs.js) and style (tabs.css) in npm package
12
+
13
+ === Changed
14
+
15
+ * Use value of `idseparator` attribute in front of tabset number in auto-generated ID (#16)
16
+ * Add aliases for `Block` and `Docinfo` classes to `Extensions` class; remove workaround in js module
17
+ * Move `margin-bottom` style to tabset element
18
+ * Move behavior (tabs.js) and style (tabs.css) to dist folder in npm package
19
+
20
+ === Fixed
21
+
22
+ * Increase specificity of sibling selector for tab to work with Antora default UI
23
+
24
+ === Details
25
+
26
+ {url-repo}/releases/tag/v1.0.0-alpha.4[git tag] | {url-repo}/compare/v1.0.0-alpha.3\...v1.0.0-alpha.4[full diff]
27
+
28
+ == 1.0.0-alpha.3 (2022-10-05) - @mojavelinux
29
+
30
+ === Added
31
+
32
+ * Provide fallback behavior for non-HTML backends (filetype is not html) (#4)
33
+ * Support multiple tab labels (terms) for the same content (description) (#8)
34
+ * Allow alternate stylesheet for tabs to be specified using `tabs-stylesheet` attribute (#6)
35
+
36
+ === Changed
37
+
38
+ * Assign ID directly to tab (list item) node (instead of using inline anchor) if backend supports it (#11)
39
+
40
+ === Fixed
41
+
42
+ * Preserve text of dlist item for tab if item has both text and blocks (#13)
43
+ * Create empty pane instead of crashing if dlist item has term only / no description
44
+
45
+ === Details
46
+
47
+ {url-repo}/releases/tag/v1.0.0-alpha.3[git tag] | {url-repo}/compare/v1.0.0-alpha.2\...v1.0.0-alpha.3[full diff]
48
+
7
49
  == 1.0.0-alpha.2 (2022-10-03) - @mojavelinux
8
50
 
9
51
  === Added
@@ -21,7 +63,9 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
21
63
  === Fixed
22
64
 
23
65
  * Honor explicit ID on tabs block and use it as ID prefix for tabs
66
+ * Register reference for tabset in document catalog
24
67
  * Autogenerate IDs for tabsets and tabs in a manner consistent with section ID generation (#2)
68
+ * Fix context value on pass blocks created by extension
25
69
 
26
70
  === Details
27
71
 
data/README.adoc CHANGED
@@ -1,12 +1,21 @@
1
1
  = Asciidoctor Tabs
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
- v1.0.0-alpha.2, 2022-10-03
3
+ v1.0.0-alpha.4, 2022-10-08
4
4
  :idprefix:
5
5
  :idseparator: -
6
+ ifndef::env-github[:icons: font]
7
+ ifdef::env-github[]
8
+ :note-caption: :paperclip:
9
+ :tip-caption: :bulb:
10
+ endif::[]
6
11
 
7
12
  An Asciidoctor extension that adds a tabs block to the AsciiDoc syntax.
8
13
  Each set of tabs (a "tabset") is constructed from a dlist enclosed in an example block marked with the tabs style.
9
- This extension is only designed to be used with the `html` backend.
14
+
15
+ NOTE: This extension is intended to be used with HTML backends (e.g., `html`).
16
+ For other backends (i.e., filetype is not html), the example block enclosure will be taken away and the dlist will be converted normally.
17
+
18
+ TIP: This extension is also published as an npm package named `@asciidoctor/tabs` for use with Asciidoctor.js (and thus Antora).
10
19
 
11
20
  == Install
12
21
 
@@ -69,8 +78,51 @@ Contains more than one block.
69
78
 
70
79
  == Usage
71
80
 
81
+ === CLI
82
+
72
83
  $ asciidoctor -r asciidoctor-tabs document-with-tabs.adoc
73
84
 
85
+ You can specify an alternate stylesheet for tabs using the `tabs-stylesheet` document attribute.
86
+ The value of this attribute is handled in the same way as the built-in `stylesheet` document attribute.
87
+ A relative path is resolved starting from the value of the `stylesdir` document attribute, which defaults to the directory of the document.
88
+
89
+ $ asciidoctor -r asciidoctor-tabs -a tabs-stylesheet=my-tabs.css document-with-tabs.adoc
90
+
91
+ === API
92
+
93
+ There are two ways to use the extension with the Asciidoctor API.
94
+ In either case, you must require the Asciidoctor gem (`asciidoctor`) before requiring this one.
95
+
96
+ You can require `asciidoctor/tabs` to register the extension as a global extension, just like with the CLI.
97
+
98
+ [,js]
99
+ ----
100
+ require 'asciidoctor'
101
+ require 'asciidoctor/tabs'
102
+
103
+ Asciidoctor.convert_file 'document-with-tabs.adoc', safe: :safe
104
+ ----
105
+
106
+ Or you can pass a registry instance to the `Extensions.register` method to register the extension with a scoped registry.
107
+
108
+ [,js]
109
+ ----
110
+ require 'asciidoctor'
111
+ require 'asciidoctor/tabs/extensions'
112
+
113
+ registry = Asciidoctor::Extensions.create
114
+ Asciidoctor::Tabs::Extensions.register registry
115
+
116
+ Asciidoctor.convert_file 'document-with-tabs.adoc', extension_registry: registry, safe: :safe
117
+ ----
118
+
119
+ If you're not using other scoped extensions, you can pass in the extensions group without creating a registry instance:
120
+
121
+ [,js]
122
+ ----
123
+ Asciidoctor.convert_file 'document-with-tabs.adoc', extensions: Asciidoctor::Tabs::Extensions.group, safe: :safe
124
+ ----
125
+
74
126
  == Authors
75
127
 
76
128
  Asciidoctor Tabs was written by Dan Allen of OpenDevise Inc. and contributed to the Asciidoctor project.
data/data/css/tabs.css CHANGED
@@ -1,5 +1,5 @@
1
- /*! Asciidoctor Tabs stylesheet | Copyright (c) 2018-present Dan Allen | MIT License */
2
- .tabs ul {
1
+ /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */
2
+ .tabs > ul {
3
3
  display: flex;
4
4
  flex-wrap: wrap;
5
5
  list-style: none;
@@ -7,7 +7,7 @@
7
7
  padding: 0;
8
8
  }
9
9
 
10
- .tabs li {
10
+ .tabs > ul li {
11
11
  align-items: center;
12
12
  border: 1px solid black;
13
13
  border-bottom: 0;
@@ -21,14 +21,18 @@
21
21
  position: relative;
22
22
  }
23
23
 
24
- .tabs.ulist li, .tabs.ulist p {
24
+ .tabs > ul li, .tabs > ul p {
25
25
  margin-bottom: 0;
26
26
  }
27
27
 
28
- .tabs li + li {
28
+ .tabs > ul li + li[id] {
29
29
  margin-top: 0;
30
30
  }
31
31
 
32
+ .tabset {
33
+ margin-bottom: 1.25em;
34
+ }
35
+
32
36
  .tabset.is-loading .tabs li:not(:first-child),
33
37
  .tabset:not(.is-loading) .tabs li:not(.is-active) {
34
38
  background-color: black;
@@ -50,7 +54,6 @@
50
54
  .tabset > .content {
51
55
  border: 1px solid gray;
52
56
  padding: 1.25em;
53
- margin-bottom: 1.25em;
54
57
  }
55
58
 
56
59
  .tabset.is-loading .tab-pane:not(:first-child),
data/data/js/tabs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Asciidoctor Tabs behavior | Copyright (c) 2018-present Dan Allen | MIT License */
1
+ /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */
2
2
  ;(function () {
3
3
  'use strict'
4
4
 
@@ -11,7 +11,8 @@
11
11
  find('li', tabs).forEach(function (tab, idx) {
12
12
  var id = (tab.querySelector('a[id]') || tab).id
13
13
  if (!id) return
14
- var pane = getPane(id, tabset)
14
+ var pane = tabset.querySelector('.tab-pane[aria-labelledby~="' + id + '"]')
15
+ if (!pane) return
15
16
  if (!idx) first = { tab: tab, pane: pane }
16
17
  if (!active && hash === '#' + id && (active = true)) {
17
18
  tab.classList.add('is-active')
@@ -42,10 +43,4 @@
42
43
  function find (selector, from) {
43
44
  return Array.prototype.slice.call((from || document).querySelectorAll(selector))
44
45
  }
45
-
46
- function getPane (id, tabset) {
47
- return find('.tab-pane', tabset).find(function (it) {
48
- return it.getAttribute('aria-labelledby') === id
49
- })
50
- }
51
46
  })()
@@ -10,47 +10,53 @@ module Asciidoctor
10
10
  block = create_block parent, attrs['cloaked-context'], nil, attrs, content_model: :compound
11
11
  children = (parse_content block, reader).blocks
12
12
  return block unless children.size == 1 && (source_tabs = children[0]).context == :dlist && source_tabs.items?
13
- nodes = []
14
- tabset_number = (doc = parent.document).counter 'tabset-number'
15
- id = attrs['id'] || %(#{doc.attributes['idprefix'] || '_'}tabset#{tabset_number})
16
- nodes << (create_html_fragment parent, %(<div id="#{id}" class="tabset is-loading">))
17
- tabs = create_list parent, :ulist
18
- tabs.add_role 'tabs'
13
+ unless (doc = parent.document).attr? 'filetype', 'html'
14
+ source_tabs.id ||= attrs['id']
15
+ (reftext = attrs['reftext']) && (source_tabs.set_attr 'reftext', reftext) unless source_tabs.attr? 'reftext'
16
+ return source_tabs
17
+ end
18
+ tabset_number = doc.counter 'tabset-number'
19
+ id = attrs['id'] ||
20
+ %(#{doc.attributes['idprefix'] || '_'}tabset#{doc.attributes['idseparator'] || '_'}#{tabset_number})
21
+ parent << (create_html_fragment parent, %(<div id="#{id}" class="tabset is-loading">))
22
+ (tabs = create_list parent, :ulist).add_role 'tabs'
19
23
  panes = {}
20
- source_tabs.items.each do |(title), details|
21
- tab = create_list_item tabs
22
- tabs << tab
23
- tab_id = generate_id title.text, id, doc
24
- tab.text = %([[#{tab_id}]]#{title.instance_variable_get :@text})
25
- if details.blocks?
26
- blocks = details.blocks
27
- elsif details.text?
28
- blocks = [(create_paragraph parent, (details.instance_variable_get :@text), {})]
29
- else
30
- next
24
+ set_id_on_tab = (doc.backend == 'html5') || (list_item_supports_id? doc)
25
+ source_tabs.items.each do |labels, content|
26
+ tab_ids = labels.map do |tab|
27
+ tabs << tab
28
+ tab_id = generate_id tab.text, id, doc
29
+ set_id_on_tab ? (tab.id = tab_id) : (tab.text = %([[#{tab_id}]]#{tab.instance_variable_get :@text}))
30
+ tab_id
31
31
  end
32
- if (block0 = blocks[0]).context == :open && blocks.size == 1 && block0.blocks?
33
- blocks = block0.blocks
32
+ if content
33
+ text = create_paragraph parent, (content.instance_variable_get :@text), nil if content.text?
34
+ if content.blocks?
35
+ if (block0 = (blocks = content.blocks)[0]).context == :open && blocks.size == 1 && block0.blocks?
36
+ blocks = block0.blocks
37
+ end
38
+ blocks.unshift text if text
39
+ elsif text
40
+ blocks = [text]
41
+ end
34
42
  end
35
- (panes[tab_id] = blocks).each {|it| it.parent = parent }
43
+ panes[tab_ids] = blocks || []
36
44
  end
37
- nodes << tabs
38
- nodes << (create_html_fragment parent, '<div class="content">')
39
- panes.each do |tab_id, blocks|
40
- nodes << (create_html_fragment parent, %(<div class="tab-pane" aria-labelledby="#{tab_id}">))
41
- nodes.push(*blocks)
42
- nodes << (create_html_fragment parent, '</div>')
45
+ parent << tabs
46
+ parent << (create_html_fragment parent, '<div class="content">')
47
+ panes.each do |tab_ids, blocks|
48
+ parent << (create_html_fragment parent, %(<div class="tab-pane" aria-labelledby="#{tab_ids.join ' '}">))
49
+ blocks.each {|it| parent << it }
50
+ parent << (create_html_fragment parent, '</div>')
43
51
  end
44
- nodes << (create_html_fragment parent, '</div>')
45
- nodes << (create_html_fragment parent, '</div>')
46
- nodes.each {|it| parent.blocks << it }
47
- nil
52
+ parent << (create_html_fragment parent, '</div>')
53
+ create_html_fragment parent, '</div>', 'id' => id
48
54
  end
49
55
 
50
56
  private
51
57
 
52
- def create_html_fragment parent, html
53
- create_block parent, 'pass', html, nil
58
+ def create_html_fragment parent, html, attributes = nil
59
+ create_block parent, :pass, html, attributes
54
60
  end
55
61
 
56
62
  def generate_id str, base_id, doc
@@ -60,6 +66,15 @@ module Asciidoctor
60
66
  ensure
61
67
  restore_idprefix ? (attrs['idprefix'] = restore_idprefix) : (attrs.delete 'idprefix')
62
68
  end
69
+
70
+ def list_item_supports_id? doc
71
+ if (converter = doc.converter).instance_variable_defined? :@list_item_supports_id
72
+ converter.instance_variable_get :@list_item_supports_id
73
+ else
74
+ output = (create_list doc, :ulist).tap {|ul| ul << (create_list_item ul).tap {|li| li.id = 'name' } }.convert
75
+ converter.instance_variable_set :@list_item_supports_id, (output.include? ' id="name"')
76
+ end
77
+ end
63
78
  end
64
79
  end
65
80
  end
@@ -5,20 +5,22 @@ module Asciidoctor
5
5
  module Docinfo
6
6
  if RUBY_ENGINE == 'opal'
7
7
  DATA_DIR = ::File.absolute_path '../data', %x(__dirname)
8
- FILE_READ_MODE = 'r'
9
8
  else
10
9
  DATA_DIR = ::File.join (::File.absolute_path '../../..', __dir__), 'data'
11
- FILE_READ_MODE = 'rb:utf-8:utf-8'
12
10
  end
13
11
 
14
12
  class Styles < ::Asciidoctor::Extensions::DocinfoProcessor
15
13
  use_dsl
16
14
  at_location :head
17
15
 
18
- STYLESHEET_FILE = ::File.join DATA_DIR, 'css/tabs.css'
16
+ DEFAULT_STYLESHEET_FILE = ::File.join DATA_DIR, 'css/tabs.css'
19
17
 
20
- def process _doc
21
- %(<style>\n#{(::File.read STYLESHEET_FILE, mode: FILE_READ_MODE).chomp}\n</style>)
18
+ def process doc
19
+ return unless (path = doc.attr 'tabs-stylesheet')
20
+ return unless (styles = path.empty? ?
21
+ (doc.read_asset DEFAULT_STYLESHEET_FILE) :
22
+ (doc.read_contents path, start: (doc.attr 'stylesdir'), warn_on_failure: true, label: 'tabs stylesheet'))
23
+ %(<style>\n#{styles.chomp}\n</style>)
22
24
  end
23
25
  end
24
26
 
@@ -28,8 +30,9 @@ module Asciidoctor
28
30
 
29
31
  JAVASCRIPT_FILE = ::File.join DATA_DIR, 'js/tabs.js'
30
32
 
31
- def process _doc
32
- %(<script>\n#{(::File.read JAVASCRIPT_FILE, mode: FILE_READ_MODE).chomp}\n</script>)
33
+ def process doc
34
+ return unless (script = doc.read_asset JAVASCRIPT_FILE)
35
+ %(<script>\n#{script.chomp}\n</script>)
33
36
  end
34
37
  end
35
38
  end
@@ -8,12 +8,19 @@ end
8
8
  module Asciidoctor
9
9
  module Tabs
10
10
  module Extensions
11
+ const_set :Block, Block
12
+ const_set :Docinfo, Docinfo
13
+
11
14
  module_function
12
15
 
13
16
  def group
14
17
  proc do
15
18
  block Block, :tabs
16
- next if @document.embedded?
19
+ next if (doc = @document).embedded? || !(doc.attr? 'filetype', 'html')
20
+ unless (doc.attribute_locked? 'tabs-stylesheet') ||
21
+ ((doc.options[:attributes] || {}).transform_keys {|it| it.delete '@!' }.key? 'tabs-stylesheet')
22
+ doc.set_attr 'tabs-stylesheet'
23
+ end
17
24
  docinfo_processor Docinfo::Styles
18
25
  docinfo_processor Docinfo::Behavior
19
26
  nil
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Tabs
5
- VERSION = '1.0.0.alpha.2'
5
+ VERSION = '1.0.0.alpha.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.2
4
+ version: 1.0.0.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor