File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -103,9 +103,7 @@ export async function createMarkdown(options: ResolvedOptions) {
103
103
} = options
104
104
105
105
raw = raw . trimStart ( )
106
-
107
- if ( transforms . before )
108
- raw = transforms . before ( raw , id )
106
+ raw = transforms . before ?.( raw , id ) ?? raw
109
107
110
108
const env : MarkdownEnv = { id }
111
109
let html = markdown . render ( raw , env )
@@ -136,8 +134,7 @@ export async function createMarkdown(options: ResolvedOptions) {
136
134
html = `<${ wrapperComponentName } ${ attrs } >${ html } </${ wrapperComponentName } >`
137
135
}
138
136
139
- if ( transforms . after )
140
- html = transforms . after ( html , id )
137
+ html = transforms . after ?.( html , id ) ?? html
141
138
142
139
if ( options . escapeCodeTagInterpolation ) {
143
140
// escape curly brackets interpolation in <code>, #14
@@ -190,6 +187,8 @@ export async function createMarkdown(options: ResolvedOptions) {
190
187
scriptLines . unshift ( `import { useHead } from "${ importFrom } "` )
191
188
scriptLines . push ( 'useHead(head)' )
192
189
}
190
+
191
+ scriptLines . push ( ...transforms . extraScripts ?.( frontmatter , id ) || [ ] )
193
192
}
194
193
195
194
if ( options . excerpt ) {
Original file line number Diff line number Diff line change @@ -187,6 +187,10 @@ export interface Options {
187
187
transforms ?: {
188
188
before ?: ( code : string , id : string ) => string
189
189
after ?: ( code : string , id : string ) => string
190
+ /**
191
+ * Return extra code to be injected into the `<script>` tag
192
+ */
193
+ extraScripts ?: ( frontmatter : Record < string , any > , id : string ) => string [ ]
190
194
}
191
195
192
196
include ?: FilterPattern
You can’t perform that action at this time.
0 commit comments