2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-06-05 19:34:21 -05:00
|
|
|
# markdown normalizer to be used by importers
|
|
|
|
#
|
|
|
|
#
|
2023-01-09 06:10:19 -06:00
|
|
|
require "htmlentities"
|
|
|
|
module Import
|
|
|
|
end
|
2014-06-05 19:34:21 -05:00
|
|
|
module Import::Normalize
|
2017-07-27 20:20:09 -05:00
|
|
|
def self.normalize_code_blocks(code, lang = nil)
|
2014-06-05 19:34:21 -05:00
|
|
|
coder = HTMLEntities.new
|
2023-01-09 06:10:19 -06:00
|
|
|
code.gsub(%r{<pre>\s*<code>\n?(.*?)\n?</code>\s*</pre>}m) do
|
2017-07-27 20:20:09 -05:00
|
|
|
"\n```#{lang}\n#{coder.decode($1)}\n```\n"
|
2023-01-09 06:10:19 -06:00
|
|
|
end
|
2014-06-05 19:34:21 -05:00
|
|
|
end
|
|
|
|
end
|