Added rake task to normalize code

This commit is contained in:
Sam 2014-06-06 14:08:39 +10:00
parent d97ceb1d72
commit 3767080f3b
2 changed files with 22 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#
#
require 'htmlentities'
module Import; end
module Import::Normalize
def self.normalize_code_blocks(code, lang=nil)
coder = HTMLEntities.new

View file

@ -36,3 +36,24 @@ def rebake_posts(opts = {})
puts "\n\n#{total} posts done!\n#{'-' * 50}\n"
end
desc 'normalize all markdown so <pre><code> is not used and instead backticks'
task 'posts:normalize_code' => :environment do
lang = ENV['CODE_LANG'] || ''
require 'import/normalize'
puts "Normalizing"
i = 0
Post.where("raw like '%<pre>%<code>%'").each do |p|
normalized = Import::Normalize.normalize_code_blocks(p.raw, lang)
if normalized != p.raw
p.revise(Discourse.system_user, normalized)
putc "."
i += 1
end
end
puts
puts "#{i} posts normalized!"
end