Skip to content

Commit 85ed036

Browse files
committed
Allow injection into the document
1 parent 8b0cebd commit 85ed036

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Document level settings ----
2+
3+
// Determine if we need to install R packages
4+
globalThis.qpyodideInstallPythonPackagesList = [{{INSTALLPYTHONPACKAGESLIST}}];
5+
6+
// Check to see if we have an empty array, if we do set to skip the installation.
7+
globalThis.qpyodideSetupPythonPackages = !(qpyodideInstallPythonPackagesList.indexOf("") !== -1);
8+
9+
// Display a startup message?
10+
globalThis.qpyodideShowStartupMessage = {{SHOWSTARTUPMESSAGE}};
11+
12+
// Describe the webR settings that should be used
13+
globalThis.qpyodideCustomizedPyodideOptions = {
14+
"baseURL": "{{BASEURL}}",
15+
"serviceWorkerUrl": "{{SERVICEWORKERURL}}",
16+
"homedir": "{{HOMEDIR}}",
17+
"channelType": "{{CHANNELTYPE}}"
18+
};
19+
20+
// Store cell data
21+
globalThis.qpyodideCellDetails = {{QPYODIDECELLDETAILS}};

_extensions/pyodide/qpyodide.lua

+6-20
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,6 @@ function readTemplateFile(template)
210210
return content
211211
end
212212

213-
-- Obtain the initialization template file at pyodide-init.html
214-
function initializationTemplateFile()
215-
return readTemplateFile("pyodide-init.html")
216-
end
217-
218-
219-
-- Obtain the editor template file at pyodide-context-interactive.html
220-
function interactiveTemplateFile()
221-
return readTemplateFile("pyodide-context-interactive.html")
222-
end
223-
224-
-- Cache a copy of each public-facing templates to avoid multiple read/writes.
225-
-- interactive_template = interactiveTemplateFile()
226-
227213
-- Define a function that escape control sequence
228214
function escapeControlSequences(str)
229215
-- Perform a global replacement on the control sequence character
@@ -243,16 +229,16 @@ function initializationPyodide()
243229
["BASEURL"] = baseUrl,
244230
["HOMEDIR"] = homeDir,
245231
["INSTALLPYTHONPACKAGESLIST"] = installPythonPackagesList,
232+
["QPYODIDECELLDETAILS"] = quarto.json.encode(qPyodideCapturedCodeBlocks),
246233
}
247234

248235
-- Make sure we perform a copy
249-
--local initializationTemplate = initializationTemplateFile()
236+
local initializationTemplate = readTemplateFile("qpyodide-document-settings.js")
250237

251238
-- Make the necessary substitutions
252-
--local initializedPyodideConfiguration = substitute_in_file(initializationTemplate, substitutions)
239+
local initializedPyodideConfiguration = substitute_in_file(initializationTemplate, substitutions)
253240

254-
--return initializedPyodideConfiguration
255-
return "Placeholder"
241+
return initializedPyodideConfiguration
256242
end
257243

258244
-- Setup Pyodide's pre-requisites once per document.
@@ -275,10 +261,10 @@ function ensurePyodideSetup()
275261
--quarto.doc.include_file("in-header", "pyodide-styling.html")
276262

277263
-- Insert the Pyodide initialization routine
278-
--quarto.doc.include_text("in-header", initializedConfigurationPyodide)
264+
quarto.doc.include_text("in-header", initializedConfigurationPyodide)
279265

280266
-- Insert the Monaco Editor initialization
281-
--quarto.doc.include_file("before-body", "monaco-editor-init.html")
267+
quarto.doc.include_file("before-body", "monaco-editor-init.html")
282268

283269
end
284270

0 commit comments

Comments
 (0)