Skip to content

Commit a225d16

Browse files
committed
move components to top
1 parent 5065197 commit a225d16

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

src/components/MarkdownComponent.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ import LiteYouTube from "./LiteYouTube"
66
import FileLayout from "./FileLayout"
77
import { Icon } from "@iconify/react"
88

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+
926
function Include({ src }: { src: string }) {
1027
const press = React.useContext(PressContext)
1128
const factory = (press.components as any).includes[src]
@@ -76,20 +93,7 @@ function Youtube({ arg }: { arg: string }) {
7693
return <LiteYouTube id={arg} />
7794
}
7895

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-
9196
function Files({ body }: { body?: string }) {
92-
9397
/* Takes an ascii string of indented folder and file paths:
9498
const from = `/meta
9599
/2022
@@ -149,23 +153,6 @@ function Files({ body }: { body?: string }) {
149153
return <FileLayout files={obj} />
150154
}
151155

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-
169156
// .md uses :::info::: and .mdx uses <Info />
170157
function kebabCase(s: string) { return (s || '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() }
171158
Object.keys(Components).forEach(k => Components[kebabCase(k)] = Components[k])

src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ export function dateTimestamp(date:any) {
4545
}
4646
}
4747

48+
const invalidTokens = ['function', 'Function', 'eval', '=>', ';']
49+
const restrictedScope = Object.assign(Object.keys(globalThis).reduce((acc, k) => {
50+
acc[k] = undefined; return acc
51+
}, {} as Record<string, any>))
52+
53+
export function scopedExpr(src: string) {
54+
if (invalidTokens.some(x => src.includes(x)))
55+
throw new Error(`Unsafe script: '${src}'`)
56+
57+
return (new Function("with(this) { return (" + src + ") }")).call(restrictedScope)
58+
}
59+
4860
export function cn(...inputs: ClassValue[]) {
4961
return twMerge(clsx(inputs))
5062
}

0 commit comments

Comments
 (0)