2024-09-05 22:54:38 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-07-21 01:41:08 +02:00
|
|
|
module PdfHelper
|
|
|
|
|
def prepare_rich_text(rich_text)
|
2024-07-21 02:15:06 +02:00
|
|
|
return rich_text
|
|
|
|
|
|
2024-09-05 22:54:38 +02:00
|
|
|
{ del: "strikethrough" }.each do |tag, replacement|
|
2024-07-21 02:15:06 +02:00
|
|
|
rich_text = rich_text.to_s.gsub("<#{tag}", "<#{replacement}")
|
|
|
|
|
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-21 01:41:08 +02:00
|
|
|
%w[div p del blockquote pre code].each do |tag|
|
2024-09-05 22:54:38 +02:00
|
|
|
rich_text = rich_text.to_s.gsub(%r{<#{tag}.*?>|</#{tag}>}, "")
|
2024-07-21 01:41:08 +02:00
|
|
|
end
|
2024-09-05 22:54:38 +02:00
|
|
|
rich_text.gsub!(/<h1.*?>/, "")
|
|
|
|
|
rich_text.gsub!(%r{</h1>}, "<br><br>")
|
2024-07-21 01:41:08 +02:00
|
|
|
rich_text
|
|
|
|
|
end
|
|
|
|
|
end
|