Skip to content

Instantly share code, notes, and snippets.

@danyill
Last active December 23, 2019 23:50
Show Gist options
  • Save danyill/c329586baab40344570bbca246942970 to your computer and use it in GitHub Desktop.
Save danyill/c329586baab40344570bbca246942970 to your computer and use it in GitHub Desktop.
Extension for numbering figures
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