Last active
December 23, 2019 23:50
-
-
Save danyill/c329586baab40344570bbca246942970 to your computer and use it in GitHub Desktop.
Extension for numbering figures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' | |
include Asciidoctor | |
Extensions.register do | |
treeprocessor do | |
process do |document| | |
figureNumbers = {} | |
document.find_by(context: :section) {|sect| | |
if sect.level == 1 | |
figureNumbers[sect.level] = 0 | |
sect.find_by(context: :image) {|image| | |
figureNumbers[sect.level] += 1 | |
image.caption = 'Figure ' + sect.sectnum.to_s + figureNumbers[sect.level].to_s + '. ' | |
image.attributes['reftext'] = image.caption | |
} | |
end | |
} | |
end | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment