Skip to content

Commit

Permalink
Merge pull request #1458 from benwbrum/1445-supress-spans-xhtml-export
Browse files Browse the repository at this point in the history
export: supress spans in XHTML export
  • Loading branch information
benwbrum authored Sep 11, 2019
2 parents b076915 + 1af9130 commit e5590b6
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions app/helpers/abstract_xml_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def xml_to_html(xml_text, preserve_lb=true, flatten_links=false)
return "" if xml_text.blank?
xml_text.gsub!(/\n/, "")
xml_text.gsub!('ISO-8859-15', 'UTF-8')

if preserve_lb
xml_text.gsub!("<lb break='no'/> ", "-<br />")
end

doc = REXML::Document.new(xml_text)
#unless subject linking is disabled, do this
unless @collection.subjects_disabled
Expand Down Expand Up @@ -38,23 +43,31 @@ def xml_to_html(xml_text, preserve_lb=true, flatten_links=false)
end
# get rid of line breaks within other html mark-up
doc.elements.delete_all("//table//lb")

# convert line breaks to br or nothing, depending
doc.elements.each("//lb") do |e|
lb = REXML::Element.new('span')
lb.add_text("")
lb.add_attribute('class', 'line-break')

if preserve_lb
if e.attributes['break'] == "no"
lb.add_text('-')
end
lb.add_element(REXML::Element.new('br'))
e.replace_with(REXML::Element.new('br'))
else
unless e.attributes['break']=="no"
lb.add_text(' ')
if params[:action] == "read_work"
if e.attributes['break'] == "no"
lb.add_text('')
else
lb.add_text(' ')
lb.add_attribute('class', 'line-break')
end
else
if e.attributes['break'] == "no"
lb.add_text('-')
end
end
end
e.replace_with(lb)

e.replace_with(lb) unless preserve_lb
end

doc.elements.each("//entryHeading") do |e|
Expand Down Expand Up @@ -87,7 +100,6 @@ def xml_to_html(xml_text, preserve_lb=true, flatten_links=false)
# now our doc is correct - what do we do with it?
my_display_html = ""
doc.write(my_display_html)
my_display_html.gsub!("<br/></p>", "</p>")
my_display_html.gsub!("</p>", "</p>\n\n")
my_display_html.gsub!("<br/>","<br/>\n")

Expand Down

0 comments on commit e5590b6

Please sign in to comment.