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
|
2017-07-27 21:20:09 -04:00
|
|
|
def self.normalize_code_blocks(code, lang = nil)
|
2014-06-05 20:34:21 -04:00
|
|
|
coder = HTMLEntities.new
|
|
|
|
code.gsub(/<pre>\s*<code>\n?(.*?)\n?<\/code>\s*<\/pre>/m) {
|
2017-07-27 21:20:09 -04:00
|
|
|
"\n```#{lang}\n#{coder.decode($1)}\n```\n"
|
2014-06-05 20:34:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|