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