Skip to content

Commit

Permalink
schema: extend content accepted HTML tags & attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Samk13 authored and Sam Arbid committed Nov 27, 2023
1 parent 717e99f commit 9ca56fd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion invenio_pages/services/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
# Copyright (C) 2023 KTH Royal Institute of Technology.
#
# Invenio-Pages is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -11,6 +12,14 @@

from marshmallow import Schema, fields
from marshmallow_utils.fields import SanitizedHTML, TZDateTime
from marshmallow_utils.html import ALLOWED_HTML_ATTRS, ALLOWED_HTML_TAGS

EXTENDED_ALLOWED_TAGS = ALLOWED_HTML_TAGS + ["img", "button"]
EXTENDED_ALLOWED_ATTRS = {
**ALLOWED_HTML_ATTRS,
"img": ["src", "alt", "title", "width", "height"],
"button": ["type", "name", "value", "disabled", "onclick"],
}


class PageSchema(Schema):
Expand All @@ -19,7 +28,7 @@ class PageSchema(Schema):
id = fields.String()
url = fields.String(metadata={"create_only": True})
title = fields.String()
content = SanitizedHTML()
content = SanitizedHTML(tags=EXTENDED_ALLOWED_TAGS, attrs=EXTENDED_ALLOWED_ATTRS)
description = fields.String()
template_name = fields.String()
created = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
Expand Down

0 comments on commit 9ca56fd

Please sign in to comment.