asciidoctor-lists 1.0.3 → 1.0.7
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/README.adoc +28 -19
- data/lib/asciidoctor-lists/extensions.rb +45 -18
- data/lib/asciidoctor-lists/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac525c818bc5254204312158fee82493102b5d61477c3d17e8f6d4a1b6049ebd
|
4
|
+
data.tar.gz: cc8dd13be8fbc15c04627733a0784c2963ddbad3689a2d180af25a15c2b1ef45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6c3a5fd8b0ff322ad297070ed7796d758e4ad0c4d5efb1e285272f12b7b0b9323e90417852f3196aa700cdedb4ae9b5213192598b6f456c59bc55cc6ce4056c
|
7
|
+
data.tar.gz: 8677b62b1edbf1e6024f91422e6ca8670eff647258ac1ced4d8db03f3af9749685f5c1179da3cfbe7dcdf36598b4233ac1ee7b7a7ccfcce2ab1c6d0c39fb2f37
|
data/README.adoc
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
image:https://github.com/Alwinator/asciidoctor-lists/actions/workflows/test.yml/badge.svg[Test, link=https://github.com/Alwinator/asciidoctor-lists/actions/workflows/test.yml]
|
4
4
|
image:https://github.com/Alwinator/asciidoctor-lists/actions/workflows/publish_gem.yml/badge.svg[Build, link=https://github.com/Alwinator/asciidoctor-lists/actions/workflows/publish_gem.yml]
|
5
5
|
image:https://img.shields.io/gem/v/asciidoctor-lists.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-lists]
|
6
|
+
image:https://img.shields.io/github/stars/Alwinator/asciidoctor-lists[Stars, link=https://github.com/Alwinator/asciidoctor-lists]
|
7
|
+
|
6
8
|
|
7
9
|
An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!
|
8
10
|
|
9
|
-
*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.
|
10
14
|
|
11
15
|
== Install
|
12
16
|
[source,asciidoc]
|
@@ -20,32 +24,37 @@ gem install asciidoctor-lists
|
|
20
24
|
----
|
21
25
|
...
|
22
26
|
|
23
|
-
.And this is the second one
|
24
|
-
|===
|
25
|
-
|Column 1, Header Row |Column 2, Header Row
|
26
|
-
|
27
|
-
|Cell in column 1, row 1
|
28
|
-
|Cell in column 2, row 1
|
29
|
-
|
30
|
-
|Cell in column 1, row 2
|
31
|
-
|Cell in column 2, row 2
|
32
|
-
|===
|
33
|
-
|
34
|
-
|
35
|
-
.Another wikipedia SVG image
|
36
|
-
image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
|
37
|
-
|
38
27
|
=== List of figures
|
39
|
-
|
28
|
+
list-of::image[]
|
40
29
|
|
41
30
|
=== List of tables
|
42
|
-
|
31
|
+
list-of::table[]
|
43
32
|
|
33
|
+
=== List of code snippets
|
34
|
+
list-of::listing[]
|
44
35
|
----
|
45
36
|
|
37
|
+
See link:samples/list-sample.adoc[]
|
38
|
+
|
46
39
|
=== Rendered
|
47
40
|
image::img/sample.png[Sample,width=400]
|
48
41
|
|
42
|
+
== Parameters
|
43
|
+
=== element
|
44
|
+
Specifies the element to be listed
|
45
|
+
|
46
|
+
Sample: link:samples/list-sample.adoc[]
|
47
|
+
|
48
|
+
=== enhanced_rendering (experimental)
|
49
|
+
Allows rendering links in the caption
|
50
|
+
|
51
|
+
Sample: link:samples/enhanced-rendering.adoc[]
|
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
|
+
|
49
58
|
== Docker
|
50
59
|
[source,bash]
|
51
60
|
----
|
@@ -69,4 +78,4 @@ asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
|
|
69
78
|
----
|
70
79
|
gem build asciidoctor-lists.gemspec
|
71
80
|
gem install asciidoctor-lists-x.x.x.gem
|
72
|
-
----
|
81
|
+
----
|
@@ -5,40 +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 '
|
13
|
+
named :"list-of"
|
14
|
+
name_positional_attributes 'enhanced_rendering'
|
15
|
+
name_positional_attributes 'hide_empty_section'
|
15
16
|
|
16
|
-
def process(parent,
|
17
|
+
def process(parent, target, attrs)
|
17
18
|
uuid = SecureRandom.uuid
|
18
|
-
|
19
|
+
ListMacroAttributes[uuid] = {
|
20
|
+
element: target,
|
21
|
+
enhanced_rendering: attrs['enhanced_rendering'],
|
22
|
+
hide_empty_section: attrs['hide_empty_section']
|
23
|
+
}
|
19
24
|
create_paragraph parent, uuid, {}
|
20
25
|
end
|
21
26
|
end
|
22
|
-
# Searches for the
|
27
|
+
# Searches for the elements and replaced the UUIDs with the lists
|
23
28
|
# Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
|
24
|
-
class
|
29
|
+
class ListTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
|
25
30
|
def process(document)
|
26
31
|
tof_blocks = document.find_by do |b|
|
27
32
|
# for fast search (since most searches shall fail)
|
28
33
|
(b.content_model == :simple) && (b.lines.size == 1) \
|
29
|
-
&& (
|
34
|
+
&& (ListMacroAttributes.keys.include?(b.lines[0]))
|
30
35
|
end
|
31
36
|
tof_blocks.each do |block|
|
32
37
|
references_asciidoc = []
|
33
|
-
element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
|
34
|
-
document.find_by(context: eval(element_name)).each do |element|
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
params = ListMacroAttributes[block.lines[0]]
|
40
|
+
enhanced_rendering = params[:enhanced_rendering]
|
41
|
+
hide_empty_section = params[:hide_empty_section]
|
42
|
+
|
43
|
+
elements = document.find_by(context: params[:element].to_sym)
|
44
|
+
if elements.length > 0
|
45
|
+
elements.each do |element|
|
46
|
+
|
47
|
+
if element.caption or element.title
|
48
|
+
unless element.id
|
49
|
+
element.id = SecureRandom.uuid
|
50
|
+
end
|
51
|
+
|
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}] +)
|
63
|
+
end
|
64
|
+
end
|
39
65
|
end
|
40
|
-
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
|
41
66
|
end
|
67
|
+
elsif hide_empty_section
|
68
|
+
block.parent.parent.blocks.delete block.parent
|
42
69
|
end
|
43
70
|
|
44
71
|
block_index = block.parent.blocks.index do |b|
|
@@ -69,6 +96,6 @@ end
|
|
69
96
|
|
70
97
|
# Register the extensions to asciidoctor
|
71
98
|
Asciidoctor::Extensions.register do
|
72
|
-
block_macro AsciidoctorLists::Asciidoctor::
|
73
|
-
tree_processor AsciidoctorLists::Asciidoctor::
|
99
|
+
block_macro AsciidoctorLists::Asciidoctor::ListMacro
|
100
|
+
tree_processor AsciidoctorLists::Asciidoctor::ListTreeprocessor
|
74
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.7
|
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-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- lib/asciidoctor-lists/version.rb
|
38
38
|
homepage: https://github.com/Alwinator/asciidoctor-lists
|
39
39
|
licenses:
|
40
|
-
-
|
40
|
+
- MPL-2
|
41
41
|
metadata: {}
|
42
42
|
post_install_message:
|
43
43
|
rdoc_options: []
|