@@ -12,18 +12,19 @@ marked.setOptions({
12
12
breaks : true ,
13
13
} )
14
14
15
- export type PurifyConfig = Omit < DOMPurify . Config , "RETURN_DOM" | "RETURN_DOM_FRAGMENT" | "RETURN_TRUSTED_TYPE" >
15
+ export type DOMPurifyConfig = Omit < DOMPurify . Config , "RETURN_DOM" | "RETURN_DOM_FRAGMENT" | "RETURN_TRUSTED_TYPE" >
16
16
17
17
/**
18
18
* renders markdown to safe HTML asynchronously
19
19
* @param markdownText the markdown text to render
20
20
* @param scopeName scope name used for highlighting the code
21
+ * @param purifyConfig (optional) configuration object for DOMPurify
21
22
* @return the html string containing the result
22
23
*/
23
24
function internalRender (
24
25
markdownText : string ,
25
26
scopeName : string = "text.plain" ,
26
- purifyConfig ?: PurifyConfig
27
+ domPurifyConfig ?: DOMPurifyConfig
27
28
) : Promise < string > {
28
29
return new Promise ( ( resolve , reject ) => {
29
30
marked (
@@ -44,7 +45,7 @@ function internalRender(
44
45
reject ( e )
45
46
}
46
47
// sanitization
47
- html = purifyConfig ? DOMPurify . sanitize ( html , purifyConfig ) : DOMPurify . sanitize ( html )
48
+ html = domPurifyConfig ? DOMPurify . sanitize ( html , domPurifyConfig ) : DOMPurify . sanitize ( html )
48
49
49
50
return resolve ( html )
50
51
}
@@ -56,9 +57,14 @@ function internalRender(
56
57
* renders the markdown text to html
57
58
* @param markdownText the markdown text to render
58
59
* @param grammar the default grammar used in code sections that have no specific grammar set
60
+ * @param purifyConfig (optional) configuration object for DOMPurify
59
61
* @return the inner HTML text of the rendered section
60
62
*/
61
- export async function render ( markdownText : string , grammar : string , purifyConfig ?: PurifyConfig ) : Promise < string > {
62
- const html = await internalRender ( markdownText , grammar , purifyConfig )
63
+ export async function render (
64
+ markdownText : string ,
65
+ grammar : string ,
66
+ domPurifyConfig ?: DOMPurifyConfig
67
+ ) : Promise < string > {
68
+ const html = await internalRender ( markdownText , grammar , domPurifyConfig )
63
69
return html
64
70
}
0 commit comments