@@ -13,6 +13,7 @@ import * as ld from "../../core/lodash.ts";
1313import {
1414 kNotebookLinks ,
1515 kNotebookView ,
16+ kNotebookViewStyle ,
1617 kOutputFile ,
1718 kRelatedNotebooksTitle ,
1819 kSourceNotebookPrefix ,
@@ -21,7 +22,10 @@ import {
2122} from "../../config/constants.ts" ;
2223import { Format , NotebookPublishOptions } from "../../config/types.ts" ;
2324
24- import { RenderServices } from "../../command/render/types.ts" ;
25+ import {
26+ HtmlPostProcessResult ,
27+ RenderServices ,
28+ } from "../../command/render/types.ts" ;
2529import { render , renderServices } from "../../command/render/render-shared.ts" ;
2630
2731import { basename , dirname , join } from "path/mod.ts" ;
@@ -36,6 +40,46 @@ interface NotebookViewOptions {
3640 href ?: string ;
3741}
3842
43+ export const kNotebookViewStyleNotebook = "notebook" ;
44+
45+ const kQuartoNbClass = "quarto-notebook" ;
46+ const kQuartoCellContainerClass = "cell-container" ;
47+ const kQuartoCellDecoratorClass = "cell-decorator" ;
48+
49+ export function notebookViewPostProcessor ( ) {
50+ return ( doc : Document ) : Promise < HtmlPostProcessResult > => {
51+ doc . body . classList . add ( kQuartoNbClass ) ;
52+ const cells = doc . querySelectorAll ( "div.cell[data-execution_count]" ) ;
53+ for ( const cell of cells ) {
54+ const cellEl = cell as Element ;
55+ const count = cellEl . getAttribute ( "data-execution_count" ) ;
56+ if ( count ) {
57+ const containerNode = doc . createElement ( "div" ) ;
58+ containerNode . classList . add ( kQuartoCellContainerClass ) ;
59+ containerNode . classList . add ( "column-page-left" ) ;
60+
61+ const decoratorNode = doc . createElement ( "div" ) ;
62+ decoratorNode . classList . add ( kQuartoCellDecoratorClass ) ;
63+
64+ const contentsEl = doc . createElement ( "pre" ) ;
65+ contentsEl . appendChild ( doc . createTextNode ( `In [${ count } ]:` ) ) ;
66+ decoratorNode . appendChild ( contentsEl ) ;
67+
68+ containerNode . appendChild ( decoratorNode ) ;
69+ cell . parentElement ?. insertBefore ( containerNode , cell ) ;
70+ containerNode . appendChild ( cell ) ;
71+ }
72+ }
73+
74+ const resources : string [ ] = [ ] ;
75+ const supporting : string [ ] = [ ] ;
76+ return Promise . resolve ( {
77+ resources,
78+ supporting,
79+ } ) ;
80+ } ;
81+ }
82+
3983export async function processNotebookEmbeds (
4084 doc : Document ,
4185 format : Format ,
@@ -57,7 +101,6 @@ export async function processNotebookEmbeds(
57101 const linkedNotebooks : string [ ] = [ ] ;
58102 for ( const nbDivNode of notebookDivNodes ) {
59103 const nbDivEl = nbDivNode as Element ;
60- nbDivEl . classList . add ( "quarto-notebook" ) ;
61104 const notebookPath = nbDivEl . getAttribute ( "data-notebook" ) ;
62105 if ( notebookPath ) {
63106 linkedNotebooks . push ( notebookPath ) ;
@@ -236,6 +279,7 @@ async function renderHtmlView(
236279 [ kTheme ] : format . metadata [ kTheme ] ,
237280 [ kOutputFile ] : nbPreviewFile ,
238281 [ kTemplate ] : templatePath ,
282+ [ kNotebookViewStyle ] : kNotebookViewStyleNotebook ,
239283 } ,
240284 quiet : false ,
241285 } ,
0 commit comments