返回 slidev
scoped.ts
根目录 / packages / slidev / node / syntax / scoped.ts
1 import type MarkdownExit from 'markdown-exit'
2
3 const RE_STYLE_TAG_OPEN = /<style\b([^>]*)>/gi
4 const RE_SCOPED_ATTR = /\bscoped\b/i
5
6 export default function MarkdownItStyleScoped(md: MarkdownExit) {
7 const addScoped = (html: string) => {
8 return html.replace(RE_STYLE_TAG_OPEN, (match, attrs) => {
9 if (RE_SCOPED_ATTR.test(attrs))
10 return match
11 return `<style scoped${attrs}>`
12 })
13 }
14
15 const htmlBlock = md.renderer.rules.html_block!
16 md.renderer.rules.html_block = async (...args) => addScoped(await htmlBlock(...args))
17
18 const htmlInline = md.renderer.rules.html_inline!
19 md.renderer.rules.html_inline = async (...args) => addScoped(await htmlInline(...args))
20 }
21
21 lines TYPESCRIPT