@@ -6,6 +6,23 @@ import LiteYouTube from "./LiteYouTube"
6
6
import FileLayout from "./FileLayout"
7
7
import { Icon } from "@iconify/react"
8
8
9
+ export const Components : { [ name : string ] : JSX . Element | Function } = {
10
+ Files,
11
+ Icon,
12
+ Iconify : Icon , // alias for portability with Vue Markdown
13
+ Youtube,
14
+ FileLayout,
15
+ Include,
16
+ Alert,
17
+ Tip : ( { className, ...remaining } : AlertProps ) => < Alert title = "TIP" className = { cn ( 'tip' , className ) } { ...remaining } /> ,
18
+ Info : ( { className, ...remaining } : AlertProps ) => < Alert title = "INFO" className = { cn ( 'info' , className ) } { ...remaining } /> ,
19
+ Warning : ( { className, ...remaining } : AlertProps ) => < Alert title = "WARNING" className = { cn ( 'warning' , className ) } { ...remaining } /> ,
20
+ Danger : ( { className, ...remaining } : AlertProps ) => < Alert title = "DANGER" className = { cn ( 'danger' , className ) } { ...remaining } /> ,
21
+ Copy : ( { className, ...remaining } : CopyLineProps ) => < CopyLine className = { cn ( 'not-prose copy cp' , className ) } icon = "bg-sky-500" { ...remaining } /> ,
22
+ Sh : ( { className, ...remaining } : CopyLineProps ) => < CopyLine className = { cn ( 'not-prose sh-copy cp' , className ) }
23
+ box = "bg-gray-800" icon = "bg-green-600" txt = "whitespace-pre text-base text-gray-100" { ...remaining } /> ,
24
+ }
25
+
9
26
function Include ( { src } : { src : string } ) {
10
27
const press = React . useContext ( PressContext )
11
28
const factory = ( press . components as any ) . includes [ src ]
@@ -76,20 +93,7 @@ function Youtube({ arg }: { arg: string }) {
76
93
return < LiteYouTube id = { arg } />
77
94
}
78
95
79
- const invalidTokens = [ 'function' , 'Function' , 'eval' , '=>' , ';' ]
80
- const restrictedScope = Object . assign ( Object . keys ( globalThis ) . reduce ( ( acc , k ) => {
81
- acc [ k ] = undefined ; return acc
82
- } , { } as Record < string , any > ) )
83
-
84
- function scopedExpr ( src : string ) {
85
- if ( invalidTokens . some ( x => src . includes ( x ) ) )
86
- throw new Error ( `Unsafe script: '${ src } '` )
87
-
88
- return ( new Function ( "with(this) { return (" + src + ") }" ) ) . call ( restrictedScope )
89
- }
90
-
91
96
function Files ( { body } : { body ?: string } ) {
92
-
93
97
/* Takes an ascii string of indented folder and file paths:
94
98
const from = `/meta
95
99
/2022
@@ -149,23 +153,6 @@ function Files({ body }: { body?: string }) {
149
153
return < FileLayout files = { obj } />
150
154
}
151
155
152
- export const Components : { [ name : string ] : JSX . Element | Function } = {
153
- Files,
154
- Icon,
155
- Iconify : Icon , // alias for portability with Vue Markdown
156
- Youtube,
157
- FileLayout,
158
- Include,
159
- Alert,
160
- Tip : ( { className, ...remaining } : AlertProps ) => < Alert title = "TIP" className = { cn ( 'tip' , className ) } { ...remaining } /> ,
161
- Info : ( { className, ...remaining } : AlertProps ) => < Alert title = "INFO" className = { cn ( 'info' , className ) } { ...remaining } /> ,
162
- Warning : ( { className, ...remaining } : AlertProps ) => < Alert title = "WARNING" className = { cn ( 'warning' , className ) } { ...remaining } /> ,
163
- Danger : ( { className, ...remaining } : AlertProps ) => < Alert title = "DANGER" className = { cn ( 'danger' , className ) } { ...remaining } /> ,
164
- Copy : ( { className, ...remaining } : CopyLineProps ) => < CopyLine className = { cn ( 'not-prose copy cp' , className ) } icon = "bg-sky-500" { ...remaining } /> ,
165
- Sh : ( { className, ...remaining } : CopyLineProps ) => < CopyLine className = { cn ( 'not-prose sh-copy cp' , className ) }
166
- box = "bg-gray-800" icon = "bg-green-600" txt = "whitespace-pre text-base text-gray-100" { ...remaining } /> ,
167
- }
168
-
169
156
// .md uses :::info::: and .mdx uses <Info />
170
157
function kebabCase ( s : string ) { return ( s || '' ) . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' ) . toLowerCase ( ) }
171
158
Object . keys ( Components ) . forEach ( k => Components [ kebabCase ( k ) ] = Components [ k ] )
0 commit comments