@@ -3,21 +3,25 @@ import { type Notebook, type Cell, transpile } from "@observablehq/notebook-kit"
33import { type Definition } from "@observablehq/notebook-kit/runtime" ;
44import { constructFunction } from "./util.ts" ;
55
6+ export { Notebook , Cell } ;
7+
68export interface CompileKitOptions {
79 inline ?: boolean ;
10+ resolveLocalImports ?: boolean ;
11+ includePinned ?: boolean ;
812}
913
10- export function compileCell ( cell : Cell , options : CompileKitOptions = { inline : true } ) : Definition [ ] {
14+ export function compileCell ( cell : Cell , { inline = true , resolveLocalImports = false , includePinned = true } : CompileKitOptions = { } ) : Definition [ ] {
1115 const retVal : Definition [ ] = [ ] ;
1216 const sourceIDOffset = 1000000 ;
1317 try {
14- const compiled = transpile ( cell ) ;
18+ const compiled = transpile ( cell , { resolveLocalImports } ) ;
1519 retVal . push ( {
1620 id : cell . id ,
1721 ...compiled ,
18- body : options . inline ? constructFunction ( compiled . body , `cell_${ cell . id } ` ) : compiled . body ,
22+ body : inline ? constructFunction ( compiled . body , `cell_${ cell . id } ` ) : compiled . body ,
1923 } ) ;
20- if ( cell . pinned ) {
24+ if ( includePinned && cell . pinned ) {
2125 const compiled = transpile ( {
2226 ...cell ,
2327 mode : "md" ,
@@ -29,7 +33,7 @@ ${cell.value}
2933 retVal . push ( {
3034 id : sourceIDOffset + cell . id ,
3135 ...compiled ,
32- body : options . inline ? constructFunction ( compiled . body , `cell_source_ ${ sourceIDOffset + cell . id } ` ) : compiled . body ,
36+ body : inline ? constructFunction ( compiled . body , `cell_ ${ sourceIDOffset + cell . id } ` ) : compiled . body ,
3337 } ) ;
3438 }
3539 } catch ( error ) {
@@ -38,10 +42,10 @@ ${cell.value}
3842 return retVal ;
3943}
4044
41- export function compileNotebook ( notebook : Notebook , options : CompileKitOptions = { inline : true } ) : Definition [ ] {
45+ export function compileNotebook ( notebook : Notebook , { inline = true , resolveLocalImports = false } : CompileKitOptions = { } ) : Definition [ ] {
4246 const retVal : Definition [ ] = [ ] ;
4347 for ( const cell of notebook . cells ) {
44- const cellDefs = compileCell ( cell , options ) ;
48+ const cellDefs = compileCell ( cell , { inline , resolveLocalImports } ) ;
4549 retVal . push ( ...cellDefs ) ;
4650 }
4751 return retVal ;
0 commit comments