Skip to content

Commit b92d3b5

Browse files
authored
Adjusted HTML sanitizing library to allow class and role attributes (#1568)
1 parent 391c022 commit b92d3b5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/bindingHandlers/markdown.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import remarkParse from "remark-parse";
44
import remarkGfm from "remark-gfm";
55
import remarkRehype from "remark-rehype";
66
import rehypeRaw from "rehype-raw";
7-
import rehypeSanitize from "rehype-sanitize";
7+
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
88
import rehypeStringify from "rehype-stringify";
99
import * as truncateHtml from "truncate-html";
1010

@@ -48,7 +48,12 @@ ko.bindingHandlers["markdown"] = {
4848
.use(remarkGfm)
4949
.use(remarkRehype, { allowDangerousHtml: true })
5050
.use(rehypeRaw)
51-
.use(rehypeSanitize)
51+
.use(rehypeSanitize, {
52+
...defaultSchema,
53+
attributes: {
54+
'*': ['className', 'role']
55+
}
56+
})
5257
.use(rehypeStringify)
5358
.process(markdown, (err: any, html: any) => {
5459
html = truncateHtml.default(html, { length: length, reserveLastWord: true });

0 commit comments

Comments
 (0)