asciidoctor-lists 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.adoc +41 -0
- data/lib/asciidoctor-lists/extensions.rb +81 -0
- data/lib/asciidoctor-lists/version.rb +3 -0
- data/lib/asciidoctor-lists.rb +2 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58e02dec63f52918b2ee0c8f5062d14eb451ef8c8847f07014e6d826c1c28a95
|
4
|
+
data.tar.gz: cefa380ff2daf11a8bffd28c6e5e957a3ec95e16bdb619d3f514c5f9ce0fd212
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e96c24f4090ae29d3cfbaa9d95167bd8435a0510fcd3231b47cd822352a7fe603f933660eaa7b1aec12f8689f3217353b14d3e27ac566b40cc837e40ec9ca77
|
7
|
+
data.tar.gz: ad010ae3a5c0803d4431c702e1cb02d825aa76253d903c50540455fa450ecb20cbbc546192de71c14973efbbbbe0a2f9849633664564e831ae828bc06699e201
|
data/README.adoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= asciidoctor-lists (WIP)
|
2
|
+
:toc: macro
|
3
|
+
:toclevels: 1
|
4
|
+
|
5
|
+
image:https://img.shields.io/gem/v/asciidoctor-lists.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-lists]
|
6
|
+
Adds a list of figures, list of tables (WIP) or list of anything you want!
|
7
|
+
|
8
|
+
== Install
|
9
|
+
WIP :)
|
10
|
+
|
11
|
+
== Sample
|
12
|
+
=== Code
|
13
|
+
[source,asciidoc]
|
14
|
+
----
|
15
|
+
== Test the List of Figures Macro
|
16
|
+
|
17
|
+
.The wonderful linux logo
|
18
|
+
image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
|
19
|
+
|
20
|
+
.Another wikipedia SVG image
|
21
|
+
image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
|
22
|
+
|
23
|
+
=== List of figures
|
24
|
+
|
25
|
+
tof::[]
|
26
|
+
|
27
|
+
----
|
28
|
+
|
29
|
+
=== Rendered
|
30
|
+
image::https://user-images.githubusercontent.com/39517491/139903592-84e9e6cd-c1a8-45ec-acb7-52f37e366ddc.png[Sample,width=400]
|
31
|
+
|
32
|
+
== What is planned next?
|
33
|
+
* Link between image/table/element and list
|
34
|
+
* Make generic (Also allow list of tables, or list of x)
|
35
|
+
|
36
|
+
== Dev setup
|
37
|
+
[source,bash]
|
38
|
+
----
|
39
|
+
gem build asciidoctor-lists.gemspec
|
40
|
+
gem install asciidoctor-lists-0.0.1.gem
|
41
|
+
----
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'asciidoctor'
|
2
|
+
require 'asciidoctor/extensions'
|
3
|
+
|
4
|
+
module AsciidoctorLists
|
5
|
+
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
|
+
|
13
|
+
.The wonderful linux logo
|
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)
|
24
|
+
|
25
|
+
# Replaces tof::[] with ListOfFiguresMacroPlaceholder
|
26
|
+
class ListOfFiguresMacro < ::Extensions::BlockMacroProcessor
|
27
|
+
use_dsl
|
28
|
+
named :tof
|
29
|
+
|
30
|
+
def process(parent, target, attrs)
|
31
|
+
create_paragraph parent, ListOfFiguresMacroPlaceholder, {}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# Searches for the figures and replaced ListOfFiguresMacroPlaceholder with the list of figures
|
35
|
+
# Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
|
36
|
+
class ListOfFiguresTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
|
37
|
+
def process document
|
38
|
+
references_asciidoc = []
|
39
|
+
document.find_by(context: :image).each do |image|
|
40
|
+
|
41
|
+
if image.caption
|
42
|
+
references_asciidoc << %(#{image.caption}#{image.title} +)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
tof_blocks = document.find_by do |b|
|
46
|
+
# for fast search (since most searches shall fail)
|
47
|
+
(b.content_model == :simple) && (b.lines.size == 1) \
|
48
|
+
&& (b.lines[0] == ListOfFiguresMacroPlaceholder)
|
49
|
+
end
|
50
|
+
tof_blocks.each do |block|
|
51
|
+
block_index = block.parent.blocks.index do |b|
|
52
|
+
b == block
|
53
|
+
end
|
54
|
+
reference_blocks = parse_asciidoc block.parent, references_asciidoc
|
55
|
+
reference_blocks.reverse.each do |b|
|
56
|
+
block.parent.blocks.insert block_index, b
|
57
|
+
end
|
58
|
+
block.parent.blocks.delete_at block_index + reference_blocks.size
|
59
|
+
end
|
60
|
+
end
|
61
|
+
# This is an adapted version of Asciidoctor::Extension::parse_content,
|
62
|
+
# where resultant blocks are returned as a list instead of attached to
|
63
|
+
# the parent.
|
64
|
+
def parse_asciidoc(parent, content, attributes = {})
|
65
|
+
result = []
|
66
|
+
reader = ::Asciidoctor::Reader.new content
|
67
|
+
while reader.has_more_lines?
|
68
|
+
block = ::Asciidoctor::Parser.next_block reader, parent, attributes
|
69
|
+
result << block if block
|
70
|
+
end
|
71
|
+
result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Register the extensions to asciidoctor
|
78
|
+
Asciidoctor::Extensions.register do
|
79
|
+
block_macro AsciidoctorLists::Asciidoctor::ListOfFiguresMacro
|
80
|
+
tree_processor AsciidoctorLists::Asciidoctor::ListOfFiguresTreeprocessor
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asciidoctor-lists
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alwin Schuster
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: asciidoctor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: Adds lists
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.adoc
|
34
|
+
- lib/asciidoctor-lists.rb
|
35
|
+
- lib/asciidoctor-lists/extensions.rb
|
36
|
+
- lib/asciidoctor-lists/version.rb
|
37
|
+
homepage: https://github.com/Alwinator/asciidoctor-lists
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.4.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.2.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: An Asciidoctor extension that adds bibtex integration to AsciiDoc
|
60
|
+
test_files: []
|