@@ -44,6 +44,11 @@ function manuscript()
4444 local notebookLinks = param (constants .kNotebookLinks )
4545
4646 return {
47+ traverse = ' topdown' ,
48+ Pandoc = function (el )
49+ local html = pandoc .write (el , " html" )
50+ _quarto .file .write (" /Users/ct/Desktop/test.html" , html )
51+ end ,
4752
4853 -- Process any cells that originated from notebooks
4954 Div = function (divEl )
@@ -54,33 +59,67 @@ function manuscript()
5459 return
5560 end
5661
57- local nbPath = divEl .attributes [constants .kNotebook ]
62+ -- we can't process links without a base url
63+ if not manuscriptBaseUrl then
64+ return
65+ end
66+
67+ -- Read notebook parameters from the cell, if present
68+ local nbAbsPath = divEl .attributes [constants .kNotebook ]
5869 local nbTitle = divEl .attributes [constants .kNotebookTitle ]
59- if manuscriptBaseUrl ~= nil and nbPath == nil then
70+
71+ -- If this is a notebook embed cell, 'lift' the contents of any child divs
72+ -- up (unroll their contents), this will help us avoid
73+ -- labeling divs marked as `cells` more than once
74+ local blocks = pandoc .List ()
75+ for _ , childBlock in ipairs (divEl .content ) do
76+ if childBlock .t == " Div" then
77+ tappend (blocks , childBlock .content )
78+ else
79+ blocks :insert (childBlock )
80+ end
81+ end
82+ divEl .content = blocks
83+
84+ if nbAbsPath == nil then
6085 -- if this is a computational cell, synthesize the nbPath
6186 if divEl .classes :includes (" cell" ) then
62- local relativeInputPath = pandoc . path . make_relative ( quarto . doc . input_file , quarto . project . directory )
63- nbPath = relativeInputPath
87+ -- See if this cell contains a div with explicit notebook info, if it does, we can safely ignore
88+ nbAbsPath = quarto . doc . input_file
6489 nbTitle = language [' article-notebook-label' ]
6590 end
6691 end
6792
68- if manuscriptBaseUrl ~= nil and nbPath ~= nil then
69-
93+
94+ if nbAbsPath ~= nil then
95+ local nbRelPath = pandoc .path .make_relative (nbAbsPath , quarto .project .directory )
96+
97+ -- Use the notebook cotnext to try to determine the name
98+ -- of the output file
99+ local notebooks = param (" notebook-context" , {})
100+ local nbFileName = pandoc .path .filename (nbRelPath )
101+ local previewFile = nbFileName .. " .html"
102+ for _i , notebook in ipairs (notebooks ) do
103+ if notebook .source == nbAbsPath then
104+ if notebook [' html-preview' ].output then
105+ previewFile = pandoc .path .filename (notebook [' html-preview' ].output .path )
106+ end
107+ break
108+ end
109+ end
110+
70111 -- Provide preview path for the preview generator - this
71112 -- will specify a preview file name to use when generating this preview
72113 --
73114 -- NOTE: This is a point of coordinate where the name of the notebooks is important
74115 -- and this is relying upon that name being present in order to form these links
75116 --
76117 -- TODO: Make the filter params include notebook-context information that
77- -- can be used to resolve links (if they are present)
78- local nbFileName = pandoc .path .filename (nbPath )
79- local nbDir = pandoc .path .directory (nbPath )
118+ -- can be used to resolve links (if they are present)
119+ local nbDir = pandoc .path .directory (nbRelPath )
80120 if nbDir == " ." then
81121 nbDir = " "
82122 end
83- local previewFile = nbFileName .. " .html"
84123 local previewPath = pandoc .path .join ({nbDir , previewFile })
85124
86125 -- The title for the notebook
0 commit comments