Skip to content

Commit f4f2f27

Browse files
lierdakilaminya
authored andcommitted
refactor: rename PurifyConfig to DOMPurifyConfig; add docstrings
1 parent 6ef490f commit f4f2f27

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/renderer.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ marked.setOptions({
1212
breaks: true,
1313
})
1414

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">
1616

1717
/**
1818
* renders markdown to safe HTML asynchronously
1919
* @param markdownText the markdown text to render
2020
* @param scopeName scope name used for highlighting the code
21+
* @param purifyConfig (optional) configuration object for DOMPurify
2122
* @return the html string containing the result
2223
*/
2324
function internalRender(
2425
markdownText: string,
2526
scopeName: string = "text.plain",
26-
purifyConfig?: PurifyConfig
27+
domPurifyConfig?: DOMPurifyConfig
2728
): Promise<string> {
2829
return new Promise((resolve, reject) => {
2930
marked(
@@ -44,7 +45,7 @@ function internalRender(
4445
reject(e)
4546
}
4647
// sanitization
47-
html = purifyConfig ? DOMPurify.sanitize(html, purifyConfig) : DOMPurify.sanitize(html)
48+
html = domPurifyConfig ? DOMPurify.sanitize(html, domPurifyConfig) : DOMPurify.sanitize(html)
4849

4950
return resolve(html)
5051
}
@@ -56,9 +57,14 @@ function internalRender(
5657
* renders the markdown text to html
5758
* @param markdownText the markdown text to render
5859
* @param grammar the default grammar used in code sections that have no specific grammar set
60+
* @param purifyConfig (optional) configuration object for DOMPurify
5961
* @return the inner HTML text of the rendered section
6062
*/
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)
6369
return html
6470
}

0 commit comments

Comments
 (0)