Skip to content

Extension of the AsciiDoctor (https://github.com/asciidoctor/asciidoctor) document parser to allow the creation of a custom type of image for painting displays. Also a method for creating custom Table of Contents.

Notifications You must be signed in to change notification settings

wsidl/asciidoctor-painting-macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Painting Macro

An extension for the AsciiDoctor (https://github.com/asciidoctor/asciidoctor) document parser allowing for custom image types 'paintings'. Also includes another class for creating custom Tables of Contents.

To use the extension, add the files to your project’s "lib" directory and run the command

$ asciidoctor -r ./lib/painting-macro.rb document.adoc

Using the Extension

To work with the extension, you will have access to a new macro call "painting::". It is used similarly to an "image::" macro but has a number of attributes for defining the properties of a painting.

An example of inserting a painting object into a document
== Source of Paintings

painting::source.png["The Epic Title", "Amazing Artist", "New York, NY", "Oil on Canvas", "15 x 12 inches", "2014"]

painting::source2.png[title="Not so Epic Title", artist="Amazing Artist", location="Seoul, KR", medium="Acrylic on Plywood", size="4 x 8 feet", "2015"]

Some work will be needed to allow for custom styling of the attributes. Currently, you will need to modify the Ruby code to apply your own layout.

Once the paintings are inserted, you can insert the Table of Paintings by creating an emtpy, id’d Section.

Create the Table of Paintings
[[toc-paintings]]
== Table of Paintings

== Source of Paintings
...

Custom Table of Contents

Within the extension is a AsciiDoctor Treeprocessor that cycles through objects of a specific type (using the Document’s find_by method) and listing the items. It is simple to add your own criteria to this class for another custom Table of Contents.

If you are interested in a Table of Contents for all images within your project and prepare your document and code.

For the Asciidoctor document, specify the level 2 header with the role name you want to look for (be sure it is unique)

[[toc-figures]]
== Table of Figures

== Introduction
image::source.png["Amazing Pictures by Great Photographer"]

In the Ruby extension, modify the Treeprocessor (or create your own) that will parse the figures you wish.

class PaintingTOCTreeprocessor < Extensions::Treeprocessor
  def process document
    tocfigures = []
    figure_id = 0
    case document.backend
    when 'html5' then
      document.find_by context: :image do |block|
        unless block.title == nil #Skip non-captioned figures
          figure_id += 1
          block.id = figure_id
          tocfigures.push("<li><a href=\"#figure_#{figure_id}\">Figure #{figure_id}: #{block.title}</a></li>")
        end
      end
      tocfigures = "<div id=\"toc\" class\"toc\"><ul>\n#{tocfigures.join("\n")}</ul></div>"
    end
    document.find_by id: "toc-figures" {|b| b << Block.new(b, :pass, :source => tocfogures)}
  end
end
Warning
Notice that the 'id' attribute on the new 'div' tag is "toc". This will break HTML Compliance as this was stolen from Asciidoctor’s built-in Table of Contents. This was done to keep with the style used by Asciidoctor’s own stylesheets. If you create your own stylesheets, then define your own layout.

About

Extension of the AsciiDoctor (https://github.com/asciidoctor/asciidoctor) document parser to allow the creation of a custom type of image for painting displays. Also a method for creating custom Table of Contents.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages