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 7076a20
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.html
!_extensions/*/*/*
*.pdf
*_files/
/.luarc.json
/.luarc.json
19 changes: 19 additions & 0 deletions _extensions/pyodide/qpyodide-document-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Document level settings ----

// Determine if we need to install python 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}}",
"homedir": "{{HOMEDIR}}",
};

// Store cell data
globalThis.qpyodideCellDetails = {{QPYODIDECELLDETAILS}};
10 changes: 10 additions & 0 deletions _extensions/pyodide/qpyodide-monaco-editor-init.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs/loader.js"></script>
<script id="qpyodide-monaco-editor-init">

// Configure the Monaco Editor's loader
require.config({
paths: {
'vs': 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs'
}
});
</script>
28 changes: 7 additions & 21 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 @@ -239,20 +225,20 @@ function initializationPyodide()

-- Setup different Pyodide specific initialization variables
local substitutions = {
["SHOWSTARTUPMESSAGE"] = showStartUpMessage,
["BASEURL"] = baseUrl,
["HOMEDIR"] = homeDir,
["SHOWSTARTUPMESSAGE"] = showStartUpMessage,
["INSTALLPYTHONPACKAGESLIST"] = installPythonPackagesList,
["QPYODIDECELLDETAILS"] = quarto.json.encode(qPyodideCapturedCodeBlocks),
}

-- Make sure we perform a copy
--local initializationTemplate = initializationTemplateFile()
local initializationTemplate = readTemplateFile("qpyodide-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 "<script type='text/javascript'>" .. initializedPyodideConfiguration .. "</script>"
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", "qpyodide-monaco-editor-init.html")

end

Expand Down
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
*_site/

0 comments on commit 7076a20

Please sign in to comment.