Skip to content

Commit 02c950a

Browse files
Merge pull request #1445 from projectblacklight/title-display
Convert XML <title> to HTML <span>
2 parents 07ab982 + 9f5ca3b commit 02c950a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

app/helpers/arclight/ead_format_helpers.rb

+8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ def transform_ead_to_html(value)
2626
def ead_to_html_scrubber
2727
Loofah::Scrubber.new do |node|
2828
format_render_attributes(node) if node.attr('render').present?
29+
convert_to_span(node) if CONVERT_TO_SPAN_TAGS.include? node.name
2930
format_lists(node) if %w[list chronlist].include? node.name
3031
node
3132
end
3233
end
3334

35+
# Tags that should be converted to <span> tags because of formatting conflicts between XML and HTML
36+
CONVERT_TO_SPAN_TAGS = ['title'].freeze
37+
38+
def convert_to_span(node)
39+
node.name = 'span'
40+
end
41+
3442
def condense_whitespace(str)
3543
str.squish.strip.gsub(/>[\n\s]+</, '><')
3644
end

spec/controllers/concerns/arclight/ead_format_helpers_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class TestController
4040
end
4141
end
4242

43+
describe 'converts conflicting tags' do
44+
# this is needed because browsers apply display:none to <title> tags by default
45+
it 'converts <title> tags to <span> tags' do
46+
content = helper.render_html_tags(value: %w[<title>Title</title>])
47+
expect(content).to eq_ignoring_whitespace '<span>Title</span>'
48+
end
49+
end
50+
4351
describe 'nodes with @render attributes' do
4452
it 'altrender custom -> html class' do
4553
content = helper.render_html_tags(value: ['<emph render="altrender" altrender="my-custom-class">special text</emph>'])

0 commit comments

Comments
 (0)