diff --git a/lib/import/normalize.rb b/lib/import/normalize.rb index 368147c59aa..79dfb255f83 100644 --- a/lib/import/normalize.rb +++ b/lib/import/normalize.rb @@ -2,6 +2,7 @@ # # require 'htmlentities' +module Import; end module Import::Normalize def self.normalize_code_blocks(code, lang=nil) coder = HTMLEntities.new diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 5b448e3c196..2b5c023dce2 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -36,3 +36,24 @@ def rebake_posts(opts = {}) puts "\n\n#{total} posts done!\n#{'-' * 50}\n" end + + +desc 'normalize all markdown so
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 '%%%'").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