mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Added rake task to normalize code
This commit is contained in:
parent
d97ceb1d72
commit
3767080f3b
2 changed files with 22 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require 'htmlentities'
|
require 'htmlentities'
|
||||||
|
module Import; end
|
||||||
module Import::Normalize
|
module Import::Normalize
|
||||||
def self.normalize_code_blocks(code, lang=nil)
|
def self.normalize_code_blocks(code, lang=nil)
|
||||||
coder = HTMLEntities.new
|
coder = HTMLEntities.new
|
||||||
|
|
|
@ -36,3 +36,24 @@ def rebake_posts(opts = {})
|
||||||
|
|
||||||
puts "\n\n#{total} posts done!\n#{'-' * 50}\n"
|
puts "\n\n#{total} posts done!\n#{'-' * 50}\n"
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in a new issue