diff --git a/app/helpers/arclight/ead_format_helpers.rb b/app/helpers/arclight/ead_format_helpers.rb index c63a86c01..f6dad77c3 100644 --- a/app/helpers/arclight/ead_format_helpers.rb +++ b/app/helpers/arclight/ead_format_helpers.rb @@ -26,11 +26,19 @@ def transform_ead_to_html(value) def ead_to_html_scrubber Loofah::Scrubber.new do |node| format_render_attributes(node) if node.attr('render').present? + convert_to_span(node) if CONVERT_TO_SPAN_TAGS.include? node.name format_lists(node) if %w[list chronlist].include? node.name node end end + # Tags that should be converted to tags because of formatting conflicts between XML and HTML + CONVERT_TO_SPAN_TAGS = ['title'].freeze + + def convert_to_span(node) + node.name = 'span' + end + def condense_whitespace(str) str.squish.strip.gsub(/>[\n\s]+<') end diff --git a/spec/controllers/concerns/arclight/ead_format_helpers_spec.rb b/spec/controllers/concerns/arclight/ead_format_helpers_spec.rb index d8c23bcb7..5ed1340c9 100644 --- a/spec/controllers/concerns/arclight/ead_format_helpers_spec.rb +++ b/spec/controllers/concerns/arclight/ead_format_helpers_spec.rb @@ -40,6 +40,14 @@ class TestController end end + describe 'converts conflicting tags' do + # this is needed because browsers apply display:none to tags by default + it 'converts <title> tags to <span> tags' do + content = helper.render_html_tags(value: %w[<title>Title]) + expect(content).to eq_ignoring_whitespace 'Title' + end + end + describe 'nodes with @render attributes' do it 'altrender custom -> html class' do content = helper.render_html_tags(value: ['special text'])