@@ -13,7 +13,7 @@ import { Motion } from "solid-motionone"
1313import { unified } from "unified"
1414import { useCDN , useParseText , useRouter } from "~/hooks"
1515import { useScrollListener } from "~/pages/home/toolbar/BackTop.jsx"
16- import { getMainColor , me } from "~/store"
16+ import { getMainColor , getSettingBool , me } from "~/store"
1717import { api , notify , pathDir , pathJoin , pathResolve } from "~/utils"
1818import { isMobile } from "~/utils/compatibility.js"
1919import hljs from "highlight.js"
@@ -169,6 +169,7 @@ const loadMermaidJS = once(
169169
170170async function renderMarkdown (
171171 content : string ,
172+ sanitize : boolean ,
172173) : Promise < { html : string ; hasMermaid : boolean } > {
173174 let processor = unified ( )
174175
@@ -189,10 +190,10 @@ async function renderMarkdown(
189190 )
190191 }
191192
192- processor
193- . use ( remarkRehype , { allowDangerousHtml : true } )
194- . use ( rehypeRaw )
195- . use ( rehypeSanitize , {
193+ processor . use ( remarkRehype , { allowDangerousHtml : true } ) . use ( rehypeRaw )
194+
195+ if ( sanitize )
196+ processor . use ( rehypeSanitize , {
196197 ...defaultSchema ,
197198 attributes : {
198199 ...defaultSchema . attributes ,
@@ -220,6 +221,7 @@ export function Markdown(props: {
220221 ext ?: string
221222 readme ?: boolean
222223 toc ?: boolean
224+ sanitize ?: boolean
223225} ) {
224226 const [ encoding , setEncoding ] = createSignal < string > ( "utf-8" )
225227 const [ show , setShow ] = createSignal ( true )
@@ -263,7 +265,10 @@ export function Markdown(props: {
263265 on ( [ md , mermaidTheme ] , async ( ) => {
264266 setShow ( false )
265267
266- const { html, hasMermaid } = await renderMarkdown ( md ( ) )
268+ const { html, hasMermaid } = await renderMarkdown (
269+ md ( ) ,
270+ props . sanitize || getSettingBool ( "filter_readme_scripts" ) ,
271+ )
267272 setMarkdownHTML ( html )
268273
269274 setTimeout ( ( ) => {
0 commit comments