Skip to content

Commit

Permalink
Allow injection into the document
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless committed Feb 13, 2024
1 parent 8b0cebd commit b0e0860
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
21 changes: 21 additions & 0 deletions _extensions/pyodide/qpyodide-document-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Document level settings ----

// Determine if we need to install R packages
globalThis.qpyodideInstallPythonPackagesList = [{{INSTALLPYTHONPACKAGESLIST}}];

// Check to see if we have an empty array, if we do set to skip the installation.
globalThis.qpyodideSetupPythonPackages = !(qpyodideInstallPythonPackagesList.indexOf("") !== -1);

// Display a startup message?
globalThis.qpyodideShowStartupMessage = {{SHOWSTARTUPMESSAGE}};

// Describe the webR settings that should be used
globalThis.qpyodideCustomizedPyodideOptions = {
"baseURL": "{{BASEURL}}",
"serviceWorkerUrl": "{{SERVICEWORKERURL}}",
"homedir": "{{HOMEDIR}}",
"channelType": "{{CHANNELTYPE}}"
};

// Store cell data
globalThis.qpyodideCellDetails = {{QPYODIDECELLDETAILS}};
26 changes: 6 additions & 20 deletions _extensions/pyodide/qpyodide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,6 @@ function readTemplateFile(template)
return content
end

-- Obtain the initialization template file at pyodide-init.html
function initializationTemplateFile()
return readTemplateFile("pyodide-init.html")
end


-- Obtain the editor template file at pyodide-context-interactive.html
function interactiveTemplateFile()
return readTemplateFile("pyodide-context-interactive.html")
end

-- Cache a copy of each public-facing templates to avoid multiple read/writes.
-- interactive_template = interactiveTemplateFile()

-- Define a function that escape control sequence
function escapeControlSequences(str)
-- Perform a global replacement on the control sequence character
Expand All @@ -243,16 +229,16 @@ function initializationPyodide()
["BASEURL"] = baseUrl,
["HOMEDIR"] = homeDir,
["INSTALLPYTHONPACKAGESLIST"] = installPythonPackagesList,
["QPYODIDECELLDETAILS"] = quarto.json.encode(qPyodideCapturedCodeBlocks),
}

-- Make sure we perform a copy
--local initializationTemplate = initializationTemplateFile()
local initializationTemplate = readTemplateFile("qyodide-document-settings.js")

-- Make the necessary substitutions
--local initializedPyodideConfiguration = substitute_in_file(initializationTemplate, substitutions)
local initializedPyodideConfiguration = substitute_in_file(initializationTemplate, substitutions)

--return initializedPyodideConfiguration
return "Placeholder"
return initializedPyodideConfiguration
end

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

-- Insert the Pyodide initialization routine
--quarto.doc.include_text("in-header", initializedConfigurationPyodide)
quarto.doc.include_text("in-header", initializedConfigurationPyodide)

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

end

Expand Down

0 comments on commit b0e0860

Please sign in to comment.