Last active
December 2, 2016 00:04
-
-
Save mojavelinux/414879b55ac7f3e18648f8347fc81811 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' | |
# Reconfigure AST to convert all blocks with the role SLIDE into | |
# sections and transferring the content to the new sections. | |
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 = '!' | |
# set both id field and attribute, which is required for the Bespoke converter | |
sect.set_attr 'id', (sect.id = slide.id) | |
slide.roles.each do |role| | |
sect.add_role role unless role == 'SLIDE' | |
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