-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for child documents #261
Comments
Yes, so
We don't have a way to do that unless I'm overlooking something. Once QNR gets hold of the document source it doesn't then have a way to recursively call into itself and I'd prefer that we don't add a mechanism to do that unless absolutely needed, it would add a large additional complexity.
It may be able to approximate the behaviour you're looking for, though it's not going to be a one-to-one mapping and can't replicate normal qmd source code exactly. I did just open source https://github.com/PumasAI/QuartoTools.jl which builds on top of @jkrumbiegel you have any thoughts on this? |
So for the specific example you gave something like ```{julia}
#| echo: false
QuartoTools.Expand([
QuartoTools.MarkdownCell(
"""
# Heading $i
$i
"""
) for i in 1:3
])
``` will work, but perhaps your real use case is more complex than this and QT's current options won't work? |
Yes, in practice the partial documents are basically fully fledged quarto reports without front matter. So I need to be able to evaluate inline code, code chunks and access variables from the parent document. Like you said, to make this work there probably needs to be some kind of recursive rendering strategy which seems exactly what knitr is doing. I'll take a took at QuartoTools and the functions in QuartoNotebookRunner / QuartoNotebookWorker. Maybe I can figure something out to make this work. |
I agree with @MichaelHatherly that because quarto does a transformation step before it even passes markdown to us, we cannot fully recreate inclusion of partial documents within QuartoNotebookRunner. For example, a partial cannot again use But I assume that knitr can also not do this, so it probably expects markdown without those special commands. |
I am not too concerned about the quarto specific syntax. You are probably right wrt knitr. I already was able to execute basic inline code as well as code blocks by manually calling |
Have you looked into trying this with https://quarto.org/docs/extensions/filters.html? |
I was wondering if the complexity of this would really be that large. Suppose there was a special type defined in the worker code which when returned from a cell would trigger a special branch in the results handling and send the filename(s) to include back to the server where otherwise it would get the dictionary of resolved MIME outputs. Then within QuartoNotebookRunner.jl/src/server.jl Line 655 in a1bf209
evaluate_raw_cells! again, but with slightly different input data. We'd reuse the metadata of the main file because an included file is not allowed to have its own frontmatter. Instead of the File struct we'd create something like Subfile or so which holds a reference to the same worker as the main File , but to the included file instead of the main one. The methods for refresh! etc. would do nothing on the subfile, and I think the remaining code in evaluate_raw_cells! would then work as is.
All the cells that the inner So the difference to knitr would be that one wouldn't expose a function in the worker that can suddenly directly affect the execution pipeline, but instead signal via the type of returned objects that this other branch should be taken in the server. |
That code in We already have a feature that provides arbitrary nesting and creation of fake cells, But we now have In That avoids adding complexity directly to the server code for a feature that isn't a core requirement and leaves it as an opt-in extra for the users that do want it. I'll note that neither of these approaches seem to be able to handle quarto shortcodes etc that run on files prior to us parsing them, so notebook "inclusion" isn't going to be an exact duplication of running the file directly. If we're fine with that that's fine, but it's worth noting. |
That would also be an option, yes. I thought that it might be nice to just reuse all the machinery so we don't have it in two places, but factoring it out could also work. I guess even inline code would not really be a problem in this case as it could be detected and evaluated on the worker as well. |
I am not quite sure how this applies here. There is https://github.com/pandoc/lua-filters/tree/master/include-files but I don't see how that is any different than With regards to the proposed feature I obviously don't know the code in QuartoNotebookRunner well enough to make any suggestions for the implementation. But if you want to move forward with it, I am glad to help in some capacity. |
Was asking whether what you wanted to achieve was doable by writing yourself a custom Pandoc filter that would pre-process your document to insert all the extra content you wanted to. If what you want to add is dependent on runtime information that is only available inside the
I've been planning on refactoring that server code anyway, so if I do get around to it, I'll keep this feature request in mind and see what can be done to get it working. |
Hi,
I am trying to figure out if child documents are supported by QuartoNotebookRunner.
The following simple example is supported by quartos native include mechanism.
The complex example I could not get to work yet.
Simple example
I want to render the top-level document defined below.
where
_partial.qmd
is defined as follows.Crucially the partial document has some code in it.
Including it evaluates the code and produces the correct output.
Complex example
In this example the I have the same setup as before, but the partial document is included/evaluated several times with different parameters.
For example,
and the child document references the variable
i
.Clearly the child documents have to be rendered using the current value of
i
in the parent document.I am not sure how I can render the child documents dynamically and include them in the top-level document.
The knitr engine provides the
knit_child
function that does exactly that.Maybe the
expand
mechanism can already be used to achieve this goal?Happy to get some suggestions.
The text was updated successfully, but these errors were encountered: