Skip to content

Commit

Permalink
Merge pull request #2 from Alwinator/add_links
Browse files Browse the repository at this point in the history
Add links
  • Loading branch information
Alwinator authored Nov 8, 2021
2 parents ce387ea + 126ffa3 commit 1d7bd5f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM asciidoctor/docker-asciidoctor
RUN gem install asciidoctor-lists
RUN mkdir /work
WORKDIR /work
COPY . .
RUN gem build asciidoctor-lists.gemspec
RUN mv asciidoctor-lists-*.gem asciidoctor-lists.gem
RUN gem install asciidoctor-lists.gem
CMD ["/bin/bash"]
16 changes: 10 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
= asciidoctor-lists
:toc: macro
:toclevels: 1

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]
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]
image:https://img.shields.io/gem/v/asciidoctor-lists.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-lists]

An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!

*Pull Request are always welcome! :)*

== Install
[source,asciidoc]
----
Expand Down Expand Up @@ -46,21 +46,25 @@ element_list::[element=table]
=== Rendered
image::img/sample.png[Sample,width=400]

== What is planned next?
* Link between image/table/element and list

== Docker
[source,bash]
----
# Build container
docker build --no-cache -t asciidoctor-lists .
docker build -t asciidoctor-lists .
# Run Docker
docker run -it --rm -v $(pwd):/work asciidoctor-lists
# Build sample
asciidoctor-pdf -r asciidoctor-lists samples/list-sample.adoc
----

== Dev setup
=== Run
[source,bash]
----
asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
----

=== Install Gem
[source,bash]
----
gem build asciidoctor-lists.gemspec
Expand Down
Binary file modified img/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 23 additions & 22 deletions lib/asciidoctor-lists/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,33 @@ def process(parent, _target, attrs)
# Searches for the figures and replaced ListOfFiguresMacroPlaceholder with the list of figures
# Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
class ListOfFiguresTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
def process document
def process(document)
tof_blocks = document.find_by do |b|
# for fast search (since most searches shall fail)
(b.content_model == :simple) && (b.lines.size == 1) \
# for fast search (since most searches shall fail)
(b.content_model == :simple) && (b.lines.size == 1) \
&& (MacroPlaceholder.keys.include?(b.lines[0]))
end
tof_blocks.each do |block|
references_asciidoc = []
element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
document.find_by(context: eval(element_name)).each do |element|
end
tof_blocks.each do |block|
references_asciidoc = []
element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
document.find_by(context: eval(element_name)).each do |element|

if element.caption
references_asciidoc << %(#{element.caption}#{element.title} +)
end
end
if element.caption
element.id = SecureRandom.uuid
references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
end
end

block_index = block.parent.blocks.index do |b|
b == block
end
reference_blocks = parse_asciidoc block.parent, references_asciidoc
reference_blocks.reverse.each do |b|
block.parent.blocks.insert block_index, b
end
block.parent.blocks.delete_at block_index + reference_blocks.size
end
end
block_index = block.parent.blocks.index do |b|
b == block
end
reference_blocks = parse_asciidoc block.parent, references_asciidoc
reference_blocks.reverse.each do |b|
block.parent.blocks.insert block_index, b
end
block.parent.blocks.delete_at block_index + reference_blocks.size
end
end
# This is an adapted version of Asciidoctor::Extension::parse_content,
# where resultant blocks are returned as a list instead of attached to
# the parent.
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor-lists/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AsciidoctorLists
VERSION = '0.0.4'
VERSION = '1.0.0'
end
1 change: 0 additions & 1 deletion samples/list-sample.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,10
|Cell in column 2, row 2
|===


.Another wikipedia SVG image
image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]

Expand Down

0 comments on commit 1d7bd5f

Please sign in to comment.