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
|
2023-12-15 10:46:04 -05:00
|
|
|
|
2014-06-05 20:34:21 -04:00
|
|
|
module Import::Normalize
|
|
|
|
def self.normalize_code_blocks(code, lang = nil)
|
|
|
|
coder = HTMLEntities.new
|
|
|
|
code.gsub(%r{<pre>\s*<code>\n?(.*?)\n?</code>\s*</pre>}m) do
|
|
|
|
"\n```#{lang}\n#{coder.decode($1)}\n```\n"
|
2023-01-09 07:10:19 -05:00
|
|
|
end
|
2014-06-05 20:34:21 -04:00
|
|
|
end
|
|
|
|
end
|