Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert lb tags to br tags in HTML output #1484

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/helpers/arclight/ead_format_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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
convert_to_br(node) if CONVERT_TO_BR_TAG.include? node.name
format_links(node) if %w[extptr extref extrefloc ptr ref].include? node.name
format_lists(node) if %w[list chronlist].include? node.name
node
Expand All @@ -35,11 +36,17 @@ def ead_to_html_scrubber

# Tags that should be converted to <span> tags because of formatting conflicts between XML and HTML
CONVERT_TO_SPAN_TAGS = ['title'].freeze
# Tags that should be converted to <span> tags because of formatting conflicts between XML and HTML
CONVERT_TO_BR_TAG = ['lb'].freeze

def convert_to_span(node)
node.name = 'span'
end

def convert_to_br(node)
node.name = 'br'
end

def condense_whitespace(str)
str.squish.strip.gsub(/>[\n\s]+</, '><')
end
Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/arclight/ead_format_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
content = helper.render_html_tags(value: %w[<title>Title</title>])
expect(content).to eq_ignoring_whitespace '<span>Title</span>'
end

it 'converts <lb> tags to <br> tags' do
content = helper.render_html_tags(value: %w[My<lb/>line-break])
expect(content).to eq_ignoring_whitespace 'My<br>line-break'
end
end

describe 'nodes with @render attributes' do
Expand Down