diff --git a/app/renderers/hyrax/renderers/formatted_text_renderer.rb b/app/renderers/hyrax/renderers/formatted_text_renderer.rb index bb748abb3..97680ec39 100644 --- a/app/renderers/hyrax/renderers/formatted_text_renderer.rb +++ b/app/renderers/hyrax/renderers/formatted_text_renderer.rb @@ -1,22 +1,30 @@ +# frozen_string_literal: true module Hyrax - module Renderers - class FormattedTextRenderer < AttributeRenderer - private - def attribute_value_to_html(value) - # Define allowed tags and attributes - allowed_tags = %w[strong em b i u p br small mark sub sup a ul ol li dl dt dd div span h1 h2 h3 h4 h5 h6] - allowed_attributes = %w[href] - - # Sanitize the value, allowing only safe HTML tags and attributes - # Allow for rendering of text as html for the sanitized value - safe_value = sanitize(value, tags: allowed_tags, attributes: allowed_attributes).html_safe - - if microdata_value_attributes(field).present? - "#{safe_value}" - else - li_value(value) - end + module Renderers + class FormattedTextRenderer < AttributeRenderer + private + def attribute_value_to_html(value) + sanitized_value = get_sanitized_string(value) + if microdata_value_attributes(field).present? + "#{sanitized_value}" + else + li_value(sanitized_value) end end + + # Sanitize the value, allowing only safe HTML tags and attributes + def get_sanitized_string(string) + # Define allowed tags and attributes + allowed_tags = %w[strong em b i u p br small mark sub sup a ul ol li dl dt dd div span h1 h2 h3 h4 h5 h6] + allowed_attributes = %w[href] + sanitize(string, tags: allowed_tags, attributes: allowed_attributes) + end + + # [hyc-override] Same as attribute renderer override, but without escaping the value + def li_value(value) + field_value = find_language(value) || value + auto_link((field_value)) + end end -end \ No newline at end of file + end +end