-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65b753b
commit 75bbc64
Showing
1 changed file
with
26 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? | ||
"<span#{html_attributes(microdata_value_attributes(field))}>#{safe_value}</span>" | ||
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? | ||
"<span#{html_attributes(microdata_value_attributes(field))}>#{sanitized_value}</span>" | ||
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 | ||
end | ||
end |