diff --git a/arkindex/documents/serializers/light.py b/arkindex/documents/serializers/light.py index f151e8ae453ac3c0b410e25ce1dffbee66b20692..e686640b4301ad465ee55c7e79210d718f69b555 100644 --- a/arkindex/documents/serializers/light.py +++ b/arkindex/documents/serializers/light.py @@ -1,6 +1,6 @@ import markdown from django.db.models import Max -from html_sanitizer import Sanitizer +from html_sanitizer.django import get_sanitizer from rest_framework import serializers from rest_framework.exceptions import APIException, ValidationError @@ -106,7 +106,7 @@ class MetaDataLightSerializer(serializers.ModelSerializer): def to_representation(self, instance): # The value must be HTML if instance.type == MetaType.Markdown: - sanitizer = Sanitizer() + sanitizer = get_sanitizer() html = markdown.markdown(instance.value) instance.value = sanitizer.sanitize(html) return super().to_representation(instance) diff --git a/arkindex/project/settings.py b/arkindex/project/settings.py index d8e9835a81d27659ed0b3fb9d4ecaf02b811dc4d..4569c2ab8e8c37afeb6815a63fc7194f3d8bde37 100644 --- a/arkindex/project/settings.py +++ b/arkindex/project/settings.py @@ -274,6 +274,19 @@ SPECTACULAR_SETTINGS = { ] } +# Sanitizer config +HTML_SANITIZERS = { + 'default': { + 'tags': { + 'a', 'h1', 'h2', 'h3', 'strong', 'em', 'p', + 'ul', 'ol', 'li', 'br', 'sub', 'sup', 'hr', + 'table', 'thead', 'tbody', 'tr', 'th', 'td' + }, + 'empty': {'hr', 'a', 'br', 'th'}, + 'is_mergeable': lambda e1, e2: False, + }, +} + SEARCH_FILTER_MAX_TERMS = 10 # Elastic search config