Last active
March 7, 2017 09:49
-
-
Save jaredmcateer/5ff596493b4cf317e6799a5143a8076b to your computer and use it in GitHub Desktop.
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
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}> |
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
#!/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