File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -549,7 +549,7 @@ function jatsFilterParams(options: PandocOptions) {
549549
550550function notebookContextFilterParams ( options : PandocOptions ) {
551551 const nbContext = options . services . notebook ;
552- const notebooks = nbContext . all ( ) ;
552+ const notebooks = nbContext . all ( options . project ) ;
553553 if ( notebooks . length > 0 ) {
554554 return {
555555 "notebook-context" : notebooks ,
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ export function notebookContext(): NotebookContext {
7575 const nb : Notebook = notebooks [ nbAbsPath ] || emptyNotebook ( nbAbsPath ) ;
7676 nb [ renderType ] = output ;
7777 notebooks [ nbAbsPath ] = nb ;
78+ needRewrite = true ;
7879
7980 if ( context ) {
8081 const contrib = contributor ( renderType ) ;
@@ -191,9 +192,28 @@ export function notebookContext(): NotebookContext {
191192 }
192193 }
193194
195+ let allNotebooksTempFilename : string | undefined ;
196+ let needRewrite = true ;
197+
194198 return {
195- all : ( ) => {
196- return Object . values ( notebooks ) ;
199+ all : ( context : ProjectContext ) => {
200+ if ( ! allNotebooksTempFilename ) {
201+ allNotebooksTempFilename = context . temp . createFile ( {
202+ suffix : ".json" ,
203+ } ) ;
204+ }
205+ if ( needRewrite ) {
206+ debug (
207+ `[NotebookContext]: Writing all notebooks to ${ allNotebooksTempFilename } ` ,
208+ ) ;
209+ const objs = Object . values ( notebooks ) ;
210+ Deno . writeTextFileSync (
211+ allNotebooksTempFilename ,
212+ JSON . stringify ( objs ) ,
213+ ) ;
214+ needRewrite = false ;
215+ }
216+ return allNotebooksTempFilename ;
197217 } ,
198218 get : ( nbAbsPath : string , context ?: ProjectContext ) => {
199219 debug ( `[NotebookContext]: Get Notebook:${ nbAbsPath } ` ) ;
Original file line number Diff line number Diff line change @@ -81,7 +81,10 @@ export interface NotebookTemplateMetadata extends NotebookMetadata {
8181export interface NotebookContext {
8282 // Retrieves the notebook from the context.
8383 get : ( nbPath : string , context : ProjectContext ) => Notebook | undefined ;
84- all : ( ) => Notebook [ ] ;
84+
85+ // returns a file name with the JSON serialization of all notebooks, Notebook[]
86+ all : ( context : ProjectContext ) => string ;
87+
8588 // Resolves the data on an executedFile into data that will
8689 // create a `renderType` output when rendered.
8790 addMetadata : ( nbPath : string , notebookMetadata : NotebookMetadata ) => void ;
Original file line number Diff line number Diff line change @@ -82,7 +82,8 @@ function manuscript()
8282
8383 -- Use the notebook cotnext to try to determine the name
8484 -- of the output file
85- local notebooks = param (" notebook-context" , {})
85+ local notebooks_filename = param (" notebook-context" , {})
86+ local notebooks = quarto .json .decode (io.open (notebooks_filename , " r" ):read (" *a" ))
8687 local nbFileName = pandoc .path .filename (nbRelPath )
8788 local previewFile = nbFileName .. " .html"
8889 for _i , notebook in ipairs (notebooks ) do
You can’t perform that action at this time.
0 commit comments