2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-06-05 20:34:21 -04:00
|
|
|
# markdown normalizer to be used by importers
|
|
|
|
#
|
|
|
|
#
|
|
|
|
require 'htmlentities'
|
2014-06-06 00:08:39 -04:00
|
|
|
module Import; end
|
2014-06-05 20:34:21 -04:00
|
|
|
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
|