mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
Added code block normalization routing for import
This commit is contained in:
12
lib/import/normalize.rb
Normal file
12
lib/import/normalize.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# markdown normalizer to be used by importers
|
||||
#
|
||||
#
|
||||
require 'htmlentities'
|
||||
module Import::Normalize
|
||||
def self.normalize_code_blocks(code, lang=nil)
|
||||
coder = HTMLEntities.new
|
||||
code.gsub(/<pre>\s*<code>\n?(.*?)\n?<\/code>\s*<\/pre>/m) {
|
||||
"\n```#{lang}\n#{coder.decode($1)}\n```\n"
|
||||
}
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user