Skip to content

Commit

Permalink
Merge pull request #1445 from projectblacklight/title-display
Browse files Browse the repository at this point in the history
Convert XML <title> to HTML <span>
  • Loading branch information
randalldfloyd authored Dec 8, 2023
2 parents 07ab982 + 9f5ca3b commit 02c950a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/helpers/arclight/ead_format_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span> 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
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/concerns/arclight/ead_format_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class TestController
end
end

describe 'converts conflicting tags' do
# this is needed because browsers apply display:none to <title> tags by default
it 'converts <title> tags to <span> tags' do
content = helper.render_html_tags(value: %w[<title>Title</title>])
expect(content).to eq_ignoring_whitespace '<span>Title</span>'
end
end

describe 'nodes with @render attributes' do
it 'altrender custom -> html class' do
content = helper.render_html_tags(value: ['<emph render="altrender" altrender="my-custom-class">special text</emph>'])
Expand Down

0 comments on commit 02c950a

Please sign in to comment.