Skip to content

Commit

Permalink
AR-1810 AR-1821 Treat mixed content more consistently
Browse files Browse the repository at this point in the history
  * Don't escape strip_mixed_content.  It's assumed to be OK already.

  * Process mixed content for titles, rather than stripping it.

  * Process mixed content in the PDF view and apply CSS classes to
    have italics show correctly.
  • Loading branch information
marktriggs committed Jun 19, 2017
1 parent be8b7c3 commit f607e25
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
20 changes: 13 additions & 7 deletions public-new/app/controllers/concerns/manipulate_node.rb
Expand Up @@ -10,26 +10,32 @@ module ManipulateNode
# item.name = "li"
# end

def process_mixed_content(in_txt)
def process_mixed_content(in_txt, opts = {})
return if !in_txt

# Don't fire up nokogiri if there's no mixed content to parse
unless in_txt.include?("<")
return CGI::escapeHTML(in_txt)
end
needs_nokogiri = in_txt.include?("<")

txt = in_txt.strip

txt = txt.gsub("chronlist>", "ul>")
.gsub("chronitem>", "li>")
txt = txt.gsub("list>", "ul>")
.gsub("item>", "li>")
.gsub(/\n\n/,"<br /><br />")
.gsub(/\r\n\r\n/,"<br /><br />")

unless opts[:preserve_newlines]
txt = txt.gsub(/\n\n/,"<br /><br />")
.gsub(/\r\n\r\n/,"<br /><br />")
end

txt = txt.gsub(/ & /, ' &amp; ')

txt = txt.gsub("xlink\:type=\"simple\"", "")

unless needs_nokogiri
return txt
end

@frag = Nokogiri::XML.fragment(txt)
move_list_heads
@frag.traverse { |el|
Expand All @@ -47,7 +53,7 @@ def strip_mixed_content(in_text)

# Don't fire up nokogiri if there's no mixed content to parse
unless in_text.include?("<")
return CGI::escapeHTML(in_text)
return in_text
end

in_text = in_text.gsub(/ & /, ' &amp; ')
Expand Down
4 changes: 2 additions & 2 deletions public-new/app/models/record.rb
Expand Up @@ -74,9 +74,9 @@ def request_item
private

def parse_full_title
ft = strip_mixed_content(json['display_string'] || json['title'])
ft = process_mixed_content(json['display_string'] || json['title'], :preserve_newlines => true)
unless json['title_inherited'].blank? || (json['display_string'] || '') == json['title']
ft = I18n.t('inherited', :title => strip_mixed_content(json['title']), :display => ft)
ft = I18n.t('inherited', :title => process_mixed_content(json['title'], :preserve_newlines => true), :display => ft)
end
ft
end
Expand Down
2 changes: 1 addition & 1 deletion public-new/app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="<%= AppConfig[:locale] %>">
<head>
<title><%= (@page_title.blank? ? '' : "#{@page_title} | ") %><%= t('brand.title') %></title>
<title><%= (@page_title.blank? ? '' : "#{strip_mixed_content(@page_title)} | ") %><%= t('brand.title') %></title>
<%= csrf_meta_tags %>
<%# block cross-origin refer per https://go-to-hellman.blogspot.com/2015/06/protect-reader-privacy-with-referrer.html %>
<% if AppConfig[:pui_block_referrer] %>
Expand Down
2 changes: 1 addition & 1 deletion public-new/app/views/pdf/_archival_object.html.erb
Expand Up @@ -14,7 +14,7 @@ end

<div class="avoid-break">
<div class="print-record-border print-record level-<%= level %>">
<h3><a class="record-title" id="<%= record.uri %>"><%= record.display_string %></a></h3>
<h3><a class="record-title" id="<%= record.uri %>"><%== record.display_string %></a></h3>

<% Array(record.instances).each do |instance| %>
<% if instance['sub_container'] %>
Expand Down
8 changes: 8 additions & 0 deletions public-new/app/views/pdf/_header.html.erb
Expand Up @@ -153,6 +153,14 @@
color: #aaa;
}

.italic {
font-style: italic;
}

.inherit {
font-style: italic;
}

<%# Don't show headers/footers on the titlepage %>
@page :first {
@top-center {
Expand Down
2 changes: 1 addition & 1 deletion public-new/app/views/pdf/_resource.html.erb
Expand Up @@ -14,7 +14,7 @@
<% end %>
<% end %>

<dt><%= I18n.t('resource._public.finding_aid.title') %></dt><dd><%= record.display_string %></dd>
<dt><%= I18n.t('resource._public.finding_aid.title') %></dt><dd><%== record.display_string %></dd>

<dt><%= I18n.t('resource._public.identifier') %></dt><dd><%= record.identifier %></dd>

Expand Down

0 comments on commit f607e25

Please sign in to comment.