diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index cc6a12f4ccadeb73c05adfbceead0adecd7d68df..9820cf3fb4a12c4ab3c062f9f07e9164678d6193 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -77,7 +77,7 @@ module Admin::ApplicationHelper end def prepare_html_for_static(html, university) - text = html.to_s + text = html.to_s.dup text = sanitize text text.gsub! "\r", '' text.gsub! "\n", ' ' @@ -86,19 +86,27 @@ module Admin::ApplicationHelper end def prepare_text_for_static(text, depth = 1) + text = strip_tags text.to_s.dup + text = indent text, depth + CGI.unescapeHTML text + end + + def prepare_code_for_static(code, depth = 1) + text = code.to_s.dup + text = indent text, depth + raw text + end + + def indent(text, depth) indentation = ' ' * depth - text = text.to_s.dup - text = strip_tags text - text = text.strip # Remove useless \r - text = text.gsub "\r\n", "\n" + text.gsub! "\r\n", "\n" # Replace lonely \r - text = text.gsub "\r", "\n" + text.gsub! "\r", "\n" # Indent properly to avoid broken frontmatter, with 2 lines so the linebreak work - text = text.gsub "\n", "\n#{indentation}\n#{indentation}" - # Remove extra newlines - text = text.chomp - CGI.unescapeHTML text + text.gsub! "\n", "\n#{indentation}\n#{indentation}" + text.chomp! + text end def prepare_media_for_static(object, key) diff --git a/app/models/communication/block/component/code.rb b/app/models/communication/block/component/code.rb index e858409689f853424ea2f58a29821da115accaf6..49f21bde000ad872292c8185cff0d07070ce5dfd 100644 --- a/app/models/communication/block/component/code.rb +++ b/app/models/communication/block/component/code.rb @@ -1,6 +1,3 @@ class Communication::Block::Component::Code < Communication::Block::Component::Base - def data=(value) - @data = value - end end \ No newline at end of file diff --git a/app/views/admin/communication/blocks/components/code/_static.html.erb b/app/views/admin/communication/blocks/components/code/_static.html.erb index c4afc99498f820a9243b26e6091c3d1f8087324d..2d3119af23bb623dfef67ab3608471c87e76108c 100644 --- a/app/views/admin/communication/blocks/components/code/_static.html.erb +++ b/app/views/admin/communication/blocks/components/code/_static.html.erb @@ -1,7 +1,7 @@ <% if list %> <%= indentation %>- <%= property %>: >- -<%= indentation %> <%= prepare_html_for_static value, @university, depth + 2 %> +<%= indentation %> <%= prepare_code_for_static value, depth + 2 %> <% else %> <%= indentation %><%= property %>: >- -<%= indentation %> <%= prepare_html_for_static value, @university %> +<%= indentation %> <%= prepare_code_for_static value, depth + 1 %> <% end %>