|
32 | 32 | has_read_record_permission, |
33 | 33 | ) |
34 | 34 | from ..utils import HTMLTagRemover, parse_video_chapters, remove_html_tags |
35 | | -from marshmallow_utils.html import sanitize_html |
| 35 | +from marshmallow_utils.html import sanitize_html, ALLOWED_HTML_ATTRS, ALLOWED_CSS_STYLES |
| 36 | + |
| 37 | +CUSTOM_ALLOWED_ATTRS = { |
| 38 | + **ALLOWED_HTML_ATTRS, |
| 39 | + "p": ALLOWED_HTML_ATTRS.get("p", []) + ["style"], |
| 40 | + "span": ALLOWED_HTML_ATTRS.get("span", []) + ["style"], |
| 41 | +} |
| 42 | + |
| 43 | +CUSTOM_ALLOWED_CSS = ALLOWED_CSS_STYLES + ["color"] |
36 | 44 |
|
37 | 45 |
|
38 | 46 | class CDSJSONSerializer(JSONSerializer): |
@@ -60,7 +68,11 @@ def _sanitize_metadata(self, metadata): |
60 | 68 | if "description" in metadata: |
61 | 69 | description = metadata["description"] |
62 | 70 | description = self.html_tag_remover.unescape(description) |
63 | | - metadata["description"] = sanitize_html(description) |
| 71 | + metadata["description"] = sanitize_html( |
| 72 | + description, |
| 73 | + attrs=CUSTOM_ALLOWED_ATTRS, |
| 74 | + css_styles=CUSTOM_ALLOWED_CSS, |
| 75 | + ) |
64 | 76 |
|
65 | 77 | if "translations" in metadata: |
66 | 78 | for t in metadata["translations"]: |
@@ -108,12 +120,12 @@ def preprocess_record(self, pid, record, links_factory=None): |
108 | 120 | except KeyError: |
109 | 121 | # ignore error if keys are missing in the metadata |
110 | 122 | pass |
111 | | - |
112 | | - description = metadata.get('description', '') |
| 123 | + |
| 124 | + description = metadata.get("description", "") |
113 | 125 | if description: |
114 | | - metadata['chapters'] = parse_video_chapters(description) |
| 126 | + metadata["chapters"] = parse_video_chapters(description) |
115 | 127 | else: |
116 | | - metadata['chapters'] = [] |
| 128 | + metadata["chapters"] = [] |
117 | 129 |
|
118 | 130 | return result |
119 | 131 |
|
|
0 commit comments