Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Last active December 2, 2016 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mojavelinux/414879b55ac7f3e18648f8347fc81811 to your computer and use it in GitHub Desktop.
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.
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