Skip to content

Instantly share code, notes, and snippets.

@jaredmcateer
Last active March 7, 2017 09:49
Show Gist options
  • Save jaredmcateer/5ff596493b4cf317e6799a5143a8076b to your computer and use it in GitHub Desktop.
Save jaredmcateer/5ff596493b4cf317e6799a5143a8076b to your computer and use it in GitHub Desktop.
Original
#<Asciidoctor::ListItem@47313569818400 {list_context: :ulist, text: "<<worklist,Worklist>>", blocks: 0}>
new_block
#<Asciidoctor::ListItem@47313570547660 {list_context: :ulist, text: "{{<a href=\"#worklist\">Worklist</a> | localize}}", blocks: 0}>
Desired
#<Asciidoctor::ListItem@47313570547660 {list_context: :ulist, text: "{{<<worklist,Worklist>> | localize}}", blocks: 0}>
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment