#!/usr/bin/env ruby require 'asciidoctor' require 'asciidoctor/extensions' class AngularLocalizeWrapperTreeprocessor < Asciidoctor::Extensions::Treeprocessor def process document return unless document.blocks? process_blocks document nil end def process_blocks node node.blocks.each_with_index do |block, i| class_name = block.class.name.split('::').last case class_name when 'Block' block.lines = block.lines.map do |line| line = wrap_text(line) end node.blocks[i] = block when 'ListItem' # Apperantly cannot assign block.text a new value puts block new_block = Asciidoctor::ListItem.new(block.parent, wrap_text(block.text)) puts new_block node.blocks[i] = new_block else puts %(Unhandled class: #{class_name}) end process_blocks block if block.respond_to?('blocks') end end def wrap_text text %({{#{text} | localize}}) end end Asciidoctor::Extensions.register do treeprocessor AngularLocalizeWrapperTreeprocessor end Asciidoctor.convert_file 'documentation/manual.adoc', :safe => :unsafe