Skip to content

Instantly share code, notes, and snippets.

@hsablonniere
Forked from mojavelinux/slide-transformer.rb
Created December 1, 2016 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsablonniere/ca916bdbff667926f355faac24e73ea1 to your computer and use it in GitHub Desktop.
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.
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