-
-
Save hsablonniere/ca916bdbff667926f355faac24e73ea1 to your computer and use it in GitHub Desktop.
Reconfigure AST to convert all blocks with the role SLIDE into sections and transferring the content to those new sections.
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' | |
require 'pp' | |
Asciidoctor::Extensions.register do | |
treeprocessor do | |
process do |doc| | |
doc.blocks.replace (doc.find_by role: 'SLIDE').map {|slide| | |
slide.parent.blocks.delete slide | |
sect = Asciidoctor::Section.new doc, 1, false | |
sect.title = '!' | |
sect.id = slide.id | |
sect.set_attr "id", "" | |
slide.id = nil | |
slide.roles.each {|r| | |
if r != 'SLIDE' | |
sect.add_role r | |
end | |
} | |
if slide.blocks? | |
slide.blocks.each do |child| | |
child.remove_role 'SLIDE' | |
child.parent = sect | |
sect << child | |
end | |
else | |
slide.remove_role 'SLIDE' | |
slide.parent = sect | |
sect << slide | |
end | |
sect | |
} | |
nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment