asciidoctor-lists 0.0.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +32 -16
- data/lib/asciidoctor-lists/extensions.rb +43 -50
- 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: 938bd9392b0c912ac112ced82ebef41f9bbf0772215f7d1a5f5bc1b5fdfa0a9a
|
4
|
+
data.tar.gz: 45b6506f0adfc38b3ae52077e26a1ee4f8d8bc3bcded0c8a99e1b98ac5696a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82b2c2dd1b85bd0d4b163110033c801f023795a2b42133639f5449541916fba75b66ab06ddef1c1e13de40c3b122d471fe7a1d2a9fe9c0b7fa893036fb965d87
|
7
|
+
data.tar.gz: cd5ed1b976130783ba8ff6badc212eadc123d6a0906ea4575020e55fdebee56189a78015838d2ce001bbe63041997843aeb0bcff0b53027fe278e738b10704cf
|
data/README.adoc
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
= asciidoctor-lists
|
2
|
-
:toc: macro
|
3
|
-
:toclevels: 1
|
1
|
+
= asciidoctor-lists
|
4
2
|
|
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
|
+
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
6
|
|
7
|
-
|
7
|
+
An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!
|
8
|
+
|
9
|
+
*Pull Request are always welcome! :)*
|
8
10
|
|
9
11
|
== Install
|
10
12
|
[source,asciidoc]
|
@@ -16,26 +18,33 @@ gem install asciidoctor-lists
|
|
16
18
|
=== Code
|
17
19
|
[source,asciidoc]
|
18
20
|
----
|
19
|
-
|
21
|
+
...
|
22
|
+
|
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
|
+
|===
|
20
33
|
|
21
|
-
.The wonderful linux logo
|
22
|
-
image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
|
23
34
|
|
24
35
|
.Another wikipedia SVG image
|
25
36
|
image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
|
26
37
|
|
27
38
|
=== List of figures
|
39
|
+
element_list::[element=image]
|
28
40
|
|
29
|
-
|
41
|
+
=== List of tables
|
42
|
+
element_list::[element=table]
|
30
43
|
|
31
44
|
----
|
32
45
|
|
33
46
|
=== Rendered
|
34
|
-
image::
|
35
|
-
|
36
|
-
== What is planned next?
|
37
|
-
* Link between image/table/element and list
|
38
|
-
* Make generic (Also allow list of tables, or list of x)
|
47
|
+
image::img/sample.png[Sample,width=400]
|
39
48
|
|
40
49
|
== Docker
|
41
50
|
[source,bash]
|
@@ -43,14 +52,21 @@ image::https://user-images.githubusercontent.com/39517491/139903592-84e9e6cd-c1a
|
|
43
52
|
# Build container
|
44
53
|
docker build -t asciidoctor-lists .
|
45
54
|
# Run Docker
|
46
|
-
docker run -it --rm -v $(pwd):/work asciidoctor-lists
|
55
|
+
docker run -it --rm -v $(pwd):/work asciidoctor-lists
|
47
56
|
# Build sample
|
48
|
-
asciidoctor-pdf -r asciidoctor-lists samples/list-
|
57
|
+
asciidoctor-pdf -r asciidoctor-lists samples/list-sample.adoc
|
49
58
|
----
|
50
59
|
|
51
60
|
== Dev setup
|
61
|
+
=== Run
|
62
|
+
[source,bash]
|
63
|
+
----
|
64
|
+
asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
|
65
|
+
----
|
66
|
+
|
67
|
+
=== Install Gem
|
52
68
|
[source,bash]
|
53
69
|
----
|
54
70
|
gem build asciidoctor-lists.gemspec
|
55
|
-
gem install asciidoctor-lists-
|
71
|
+
gem install asciidoctor-lists-x.x.x.gem
|
56
72
|
----
|
@@ -1,74 +1,67 @@
|
|
1
1
|
require 'asciidoctor'
|
2
2
|
require 'asciidoctor/extensions'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module AsciidoctorLists
|
5
6
|
module Asciidoctor
|
6
|
-
# An macro that adds a list of all figures
|
7
|
-
# It only uses images that have a caption!
|
8
|
-
#
|
9
|
-
# Usage
|
10
|
-
"""
|
11
|
-
== Test the List of Figures Macro
|
12
7
|
|
13
|
-
|
14
|
-
image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
|
15
|
-
|
16
|
-
.Another wikipedia SVG image
|
17
|
-
image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
|
18
|
-
|
19
|
-
=== List of figures
|
20
|
-
|
21
|
-
tof::[]
|
22
|
-
"""
|
23
|
-
ListOfFiguresMacroPlaceholder = %(9d9711cf-0e95-4230-9973-78559fe928db)
|
8
|
+
MacroPlaceholder = Hash.new
|
24
9
|
|
25
10
|
# Replaces tof::[] with ListOfFiguresMacroPlaceholder
|
26
|
-
class ListOfFiguresMacro < ::Extensions::BlockMacroProcessor
|
11
|
+
class ListOfFiguresMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
|
27
12
|
use_dsl
|
28
|
-
named :
|
13
|
+
named :element_list
|
14
|
+
name_positional_attributes 'element'
|
29
15
|
|
30
|
-
def process(parent,
|
31
|
-
|
16
|
+
def process(parent, _target, attrs)
|
17
|
+
uuid = SecureRandom.uuid
|
18
|
+
MacroPlaceholder[uuid] = {element: attrs['element']}
|
19
|
+
create_paragraph parent, uuid, {}
|
32
20
|
end
|
33
21
|
end
|
34
22
|
# Searches for the figures and replaced ListOfFiguresMacroPlaceholder with the list of figures
|
35
23
|
# Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
|
36
24
|
class ListOfFiguresTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
|
37
|
-
def process
|
25
|
+
def process(document)
|
26
|
+
tof_blocks = document.find_by do |b|
|
27
|
+
# for fast search (since most searches shall fail)
|
28
|
+
(b.content_model == :simple) && (b.lines.size == 1) \
|
29
|
+
&& (MacroPlaceholder.keys.include?(b.lines[0]))
|
30
|
+
end
|
31
|
+
tof_blocks.each do |block|
|
38
32
|
references_asciidoc = []
|
39
|
-
|
33
|
+
element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
|
34
|
+
document.find_by(context: eval(element_name)).each do |element|
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
36
|
+
if element.caption
|
37
|
+
unless element.id
|
38
|
+
element.id = SecureRandom.uuid
|
39
|
+
end
|
40
|
+
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
block_index = block.parent.blocks.index do |b|
|
45
|
+
b == block
|
46
|
+
end
|
47
|
+
reference_blocks = parse_asciidoc block.parent, references_asciidoc
|
48
|
+
reference_blocks.reverse.each do |b|
|
49
|
+
block.parent.blocks.insert block_index, b
|
50
|
+
end
|
51
|
+
block.parent.blocks.delete_at block_index + reference_blocks.size
|
52
|
+
end
|
53
|
+
end
|
61
54
|
# This is an adapted version of Asciidoctor::Extension::parse_content,
|
62
55
|
# where resultant blocks are returned as a list instead of attached to
|
63
56
|
# the parent.
|
64
57
|
def parse_asciidoc(parent, content, attributes = {})
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
58
|
+
result = []
|
59
|
+
reader = ::Asciidoctor::Reader.new content
|
60
|
+
while reader.has_more_lines?
|
61
|
+
block = ::Asciidoctor::Parser.next_block reader, parent, attributes
|
62
|
+
result << block if block
|
63
|
+
end
|
64
|
+
result
|
72
65
|
end
|
73
66
|
end
|
74
67
|
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:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alwin Schuster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|