@@ -12,7 +12,7 @@ import { Metadata } from "../../config/types.ts";
1212import { lines } from "../lib/text.ts" ;
1313import { markdownWithExtractedHeading } from "../pandoc/pandoc-partition.ts" ;
1414import { partitionYamlFrontMatter , readYamlFromMarkdown } from "../yaml.ts" ;
15- import { JupyterNotebook , JupyterOutput } from "./types.ts" ;
15+ import { JupyterCell , JupyterNotebook , JupyterOutput } from "./types.ts" ;
1616import {
1717 jupyterCellSrcAsLines ,
1818 jupyterCellSrcAsStr ,
@@ -149,6 +149,34 @@ export function fixupFrontMatter(nb: JupyterNotebook): JupyterNotebook {
149149 return lns . map ( ( line ) => line . endsWith ( "\n" ) ? line : `${ line } \n` ) ;
150150 } ;
151151
152+ // https://github.com/quarto-dev/quarto-cli/issues/12440
153+ // first, we need to find cells that have front matter _and_ markdown content,
154+ // and split them into two cells.
155+ const newCells : JupyterCell [ ] = [ ] ;
156+ nb . cells . forEach ( ( cell ) => {
157+ if ( cell . cell_type === "raw" || cell . cell_type === "markdown" ) {
158+ const partitioned = partitionYamlFrontMatter ( jupyterCellSrcAsStr ( cell ) ) ||
159+ undefined ;
160+ if ( partitioned ?. yaml . trim ( ) ) {
161+ newCells . push ( {
162+ cell_type : "raw" ,
163+ source : nbLines ( partitioned . yaml . split ( "\n" ) ) ,
164+ metadata : { } ,
165+ } ) ;
166+ }
167+ if ( partitioned ?. markdown . trim ( ) ) {
168+ newCells . push ( {
169+ cell_type : "markdown" ,
170+ source : nbLines ( partitioned . markdown . split ( "\n" ) ) ,
171+ metadata : { } ,
172+ } ) ;
173+ }
174+ } else {
175+ newCells . push ( cell ) ;
176+ }
177+ } ) ;
178+ nb . cells = newCells ;
179+
152180 // look for the first raw block that has a yaml object
153181 let partitioned : { yaml : string ; markdown : string } | undefined ;
154182 const frontMatterCellIndex = nb . cells . findIndex ( ( cell ) => {
0 commit comments