-
DescriptionThe problemPre-render lua script is not running. What I am trying to achieveI'm looking at the feasibility of creating an extention that injects React components using a custom extension. You can find it here It essentially follows the process defined in the documentation to create a custom format The idea being that A pre-render script is used to look for a React shortcode, in the md/qmd, replacing the shortcode to be just a div with a unique id for injecting the react component later. Then creating a list of components to "render" with their corresponding div ids, and saving the list to a tmp file, A include-header script that inject the correct React dependencies (react.min ect) and another include-header that reads through the tmp file we created earlier, finding the user's components and essentially dumping them in a header script. then for each one, injecting div id to the ReactDOM.render call. EG: ReactDOM.render(
React.createElement(MyComponent),
document.getElementById('correspondingcomponentid')
); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Why are you using a pre-render script? Take a look at the following extensions which inject HTML/CSS when encountering a shortcode using Lua filter.
I suggest you go through Quarto documentation on creating extensions, see https://quarto.org/docs/extensions/filters.html and https://quarto.org/docs/extensions/shortcodes.html. |
Beta Was this translation helpful? Give feedback.
-
I have found the answer, but would like to give context in case people are having the same issue as me. So in order to achieve what I wanted, I created an extension following the documentation: quarto create extension format:html this sets up the project for you. then in my _extension.yml, i had some scripts, one was a hello world that just generated a .txt file and printed hello world. But the yml file looked like this: title: Qreact
author: Jay Martin
version: 0.0.1
quarto-required: ">=1.3.0"
contributes:
project:
project:
type: website
pre-render:
- find-react-components.lua
format: react-html <-- make a note of this
formats:
html:
include-in-header:
- react-scripts.html
Where the pre-render is a simple lua script that creates the file i mentioned above. But whenever i ran Anyway, long story short, it turns out that because the project is an extension and not a "proper" project, it's not running those pre-render scripts. Although the above statement is not quite true, because the The fix, was to run project:
type: "qreact" Notes for the Quarto teamImproved documentationThis quirk should be mentioned in the documentation (if it is mentioned, it should really be around the "creating an extension" section.), If you're wondering what it should say. It should simply be. Your extension will only work when hooked up to a project not when you run quarto render/preview on template.qmd. Although, this is not quite true, because include-in-header stuff did work... Improved debuggingPerhaps when quarto render/runs, some flag for debugging would help, whereby while it is compiling it says what its doing. For example "extension.yml found".... "looking in pre-render list".... "scripts found: find-react-components.lua". Stuff to make debugginq quarto render/preview scripts easier. |
Beta Was this translation helpful? Give feedback.
Pre-render and post-render scripts are a project level features (this is why the page title is "Project Scripts", see https://quarto.org/docs/projects/scripts.html), thus the requirement to be in such setup.
Here your extension is defining two things: a project template and an html format template which are not tied together in the extension, so you have to use your extension to setup the project (thus have access to pre-render) then use the extension to have the html format, which requires the project in which it is used to be the one from the extension.
This setup is not really straightforward if I may.
I don't see (I might be missing something) why you need to have a pre-render and not…