Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'nokogiri'
- file = Nokogiri::HTML::Document.parse(open('./docs/templates/pages/upgrading.mustache'));
- #file = Nokogiri::HTML::Document.parse(open('./docs/templates/pages/scaffolding.mustache'));
- def wrap_text(text)
- "{{_i}}"+text+"{{/i}}"
- end
- file.css("h1,h2,h3,p,a").each do |e|
- e.children = wrap_text(e.children.to_s)
- end
- file.css("li").each do |li|
- li.children.each do |c|
- if c.name.eql?("ul")
- c.children.each do |c2|
- if c2.name.eql?("li")
- c2.children = wrap_text(c2.children.to_s)
- end
- end
- else
- if c.type == 3 && !c.text.include?('{{/i}}') && !c.text.include?('{{_i}}')
- c.content = wrap_text(c.content)
- end
- end
- end
- end
- f = File.open("./newfile.html", "w")
- f.write(file)
Advertisement
Add Comment
Please, Sign In to add comment