File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ dependencies = [
5757 " drf-extensions>=0.7.1,<1.0" ,
5858 " iso8601>=2.0,<3.0" ,
5959 " markdown>=3.4,<4.0" ,
60+ " nh3>=0.3,<1.0" ,
6061 " packaging>=23.2,<26.0" ,
6162 " pypandoc>=1.11,<2.0" ,
6263 " requests-toolbelt>=1.0,<2.0" ,
Original file line number Diff line number Diff line change 335335 # for example: 'not_empty': 'core/text_blocks/template_for_not_empty.html',
336336}
337337
338+ MARKDOWN_CLEAN = False
339+ MARKDOWN_CLEAN_KWARGS = {} # see https://nh3.readthedocs.io for available kwargs
340+
338341PROJECT_TABLE_PAGE_SIZE = 20
339342
340343PROJECT_VISIBILITY = True
Original file line number Diff line number Diff line change 1515from django .utils .formats import get_format
1616from django .utils .translation import gettext_lazy as _
1717
18+ import nh3
1819from defusedcsv import csv
1920from markdown import markdown
2021
@@ -253,7 +254,11 @@ def markdown2html(markdown_string):
253254 # textblocks (e.g. for help texts) can be injected into free text fields as small templates via Markdown
254255 html = inject_textblocks (html )
255256
256- return html
257+ if settings .MARKDOWN_CLEAN :
258+ # use nh3/ammonia to clean the html string
259+ return nh3 .clean (html , ** settings .MARKDOWN_CLEAN_KWARGS )
260+ else :
261+ return html
257262
258263
259264def inject_textblocks (html ):
You can’t perform that action at this time.
0 commit comments