asciidoctor-lists 1.0.5 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +16 -6
- data/lib/asciidoctor-lists/extensions.rb +37 -31
- data/lib/asciidoctor-lists/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: 4e4c385d098f83a5dc7c73e70afe4e09c1a414b5b8e6ceeb1c12aef78f47b372
|
4
|
+
data.tar.gz: 8536f12d37553f0c813719d69871c5073378b0aff7fdb973a26c72bd7fde6682
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c1d33f380081b1e4a7e28a64c45298df459e7ec8298a72baa9315beb3bb4088deda57bf76d31414b0e0432eade7ed56620417b11a29b35547da9446208a5931
|
7
|
+
data.tar.gz: 327515c647fb79c583011fc2271012a43ae502e5e9bd5919f2c89a647e1024041074ad20973512a74f9b74a602bef8fe2e4a2acff75f9d48880cabf109ae67fe
|
data/README.adoc
CHANGED
@@ -8,7 +8,9 @@ image:https://img.shields.io/github/stars/Alwinator/asciidoctor-lists[Stars, lin
|
|
8
8
|
|
9
9
|
An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!
|
10
10
|
|
11
|
-
*Pull
|
11
|
+
*Pull Requests are always welcome! :)*
|
12
|
+
|
13
|
+
IMPORTANT: With version 1.0.6 the syntax was changed from `element_list::[element=image]` to `list-of::image[]` to make it more intuitive.
|
12
14
|
|
13
15
|
== Install
|
14
16
|
[source,asciidoc]
|
@@ -23,13 +25,13 @@ gem install asciidoctor-lists
|
|
23
25
|
...
|
24
26
|
|
25
27
|
=== List of figures
|
26
|
-
|
28
|
+
list-of::image[]
|
27
29
|
|
28
30
|
=== List of tables
|
29
|
-
|
31
|
+
list-of::table[]
|
30
32
|
|
31
33
|
=== List of code snippets
|
32
|
-
|
34
|
+
list-of::listing[]
|
33
35
|
----
|
34
36
|
|
35
37
|
See link:samples/list-sample.adoc[]
|
@@ -39,15 +41,20 @@ image::img/sample.png[Sample,width=400]
|
|
39
41
|
|
40
42
|
== Parameters
|
41
43
|
=== element
|
42
|
-
Specifies the element
|
44
|
+
Specifies the element to be listed
|
43
45
|
|
44
46
|
Sample: link:samples/list-sample.adoc[]
|
45
47
|
|
46
48
|
=== enhanced_rendering (experimental)
|
47
|
-
Allows
|
49
|
+
Allows rendering links in the caption
|
48
50
|
|
49
51
|
Sample: link:samples/enhanced-rendering.adoc[]
|
50
52
|
|
53
|
+
=== hide_empty_section
|
54
|
+
Removes the section when no elements are found
|
55
|
+
|
56
|
+
Sample: link:samples/hide-if-empty-list-sample.adoc[]
|
57
|
+
|
51
58
|
== Docker
|
52
59
|
[source,bash]
|
53
60
|
----
|
@@ -72,3 +79,6 @@ asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
|
|
72
79
|
gem build asciidoctor-lists.gemspec
|
73
80
|
gem install asciidoctor-lists-x.x.x.gem
|
74
81
|
----
|
82
|
+
|
83
|
+
== Docker Image
|
84
|
+
- Support in official asciidoctor Docker image is waiting for approval (See https://github.com/asciidoctor/docker-asciidoctor/pull/262)
|
@@ -5,61 +5,67 @@ require 'securerandom'
|
|
5
5
|
module AsciidoctorLists
|
6
6
|
module Asciidoctor
|
7
7
|
|
8
|
-
|
8
|
+
ListMacroAttributes = Hash.new
|
9
9
|
|
10
|
-
# Replaces
|
11
|
-
class
|
10
|
+
# Replaces list-of::element[] with UUID and saves attributes in ListMacroPlaceholder
|
11
|
+
class ListMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
|
12
12
|
use_dsl
|
13
|
-
named :
|
14
|
-
name_positional_attributes 'element'
|
13
|
+
named :"list-of"
|
15
14
|
name_positional_attributes 'enhanced_rendering'
|
15
|
+
name_positional_attributes 'hide_empty_section'
|
16
16
|
|
17
|
-
def process(parent,
|
17
|
+
def process(parent, target, attrs)
|
18
18
|
uuid = SecureRandom.uuid
|
19
|
-
|
20
|
-
element:
|
21
|
-
enhanced_rendering: attrs['enhanced_rendering']
|
19
|
+
ListMacroAttributes[uuid] = {
|
20
|
+
element: target,
|
21
|
+
enhanced_rendering: attrs['enhanced_rendering'],
|
22
|
+
hide_empty_section: attrs['hide_empty_section']
|
22
23
|
}
|
23
24
|
create_paragraph parent, uuid, {}
|
24
25
|
end
|
25
26
|
end
|
26
|
-
# Searches for the
|
27
|
+
# Searches for the elements and replaced the UUIDs with the lists
|
27
28
|
# Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
|
28
|
-
class
|
29
|
+
class ListTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
|
29
30
|
def process(document)
|
30
31
|
tof_blocks = document.find_by do |b|
|
31
32
|
# for fast search (since most searches shall fail)
|
32
33
|
(b.content_model == :simple) && (b.lines.size == 1) \
|
33
|
-
&& (
|
34
|
+
&& (ListMacroAttributes.keys.include?(b.lines[0]))
|
34
35
|
end
|
35
36
|
tof_blocks.each do |block|
|
36
37
|
references_asciidoc = []
|
37
38
|
|
38
|
-
params =
|
39
|
-
element_name = ":" + params[:element]
|
39
|
+
params = ListMacroAttributes[block.lines[0]]
|
40
40
|
enhanced_rendering = params[:enhanced_rendering]
|
41
|
+
hide_empty_section = params[:hide_empty_section]
|
41
42
|
|
42
|
-
document.find_by(
|
43
|
+
elements = document.find_by(traverse_documents: true, context: params[:element].to_sym)
|
44
|
+
if elements.length > 0
|
45
|
+
elements.each do |element|
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
if element.caption or element.title
|
48
|
+
unless element.id
|
49
|
+
element.id = SecureRandom.uuid
|
50
|
+
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
if enhanced_rendering
|
53
|
+
if element.caption
|
54
|
+
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.instance_variable_get(:@title)} +)
|
55
|
+
else element.caption
|
56
|
+
references_asciidoc << %(xref:#{element.id}[#{element.instance_variable_get(:@title)}] +)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
if element.caption
|
60
|
+
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
|
61
|
+
else element.caption
|
62
|
+
references_asciidoc << %(xref:#{element.id}[#{element.title}] +)
|
54
63
|
end
|
55
|
-
else
|
56
|
-
if element.caption
|
57
|
-
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
|
58
|
-
else element.caption
|
59
|
-
references_asciidoc << %(xref:#{element.id}[#{element.title}] +)
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
67
|
+
elsif hide_empty_section
|
68
|
+
block.parent.parent.blocks.delete block.parent
|
63
69
|
end
|
64
70
|
|
65
71
|
block_index = block.parent.blocks.index do |b|
|
@@ -90,6 +96,6 @@ end
|
|
90
96
|
|
91
97
|
# Register the extensions to asciidoctor
|
92
98
|
Asciidoctor::Extensions.register do
|
93
|
-
block_macro AsciidoctorLists::Asciidoctor::
|
94
|
-
tree_processor AsciidoctorLists::Asciidoctor::
|
99
|
+
block_macro AsciidoctorLists::Asciidoctor::ListMacro
|
100
|
+
tree_processor AsciidoctorLists::Asciidoctor::ListTreeprocessor
|
95
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-lists
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alwin Schuster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|