How are code cells represented in the AST when using layouts? #10174
Unanswered
andrewpbray
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I've run into an unexpected structure in the AST when using
layout-ncol
on code cells. Namely, why aren't the blocks corresponding to that code cell (CodeBlock and Divs with images) nested within a.cell
Div in the same manner as code cells withoutlayout-ncol
? This has caused a bug in a filter that I've written. I can fix it with a post-render filter but figured I'd check in to see if this is the intended structure.Let me build up to the
layout-ncol
from simpler two simpler examples.Examples
If you have a qmd that only has a code cell like the following,
It gets rendered to native as:
If you add a second plot to that code cell like this,
it will render to native like:
So it interleaves CodeBlock and Divs holding the image for each image thats is produced. This is stored as a list of blocks under a .cell Div that inherits the attributes (myattr: apple) of the original code cell, same as the first example. This makes sense to me.
Now if we add
layout-ncol: 2
,and render to HTML, it no longer interleaves, it puts a single CodeBlock before the images:
Rendered to native no longer works, but we can peek at the AST at various points in the process. Here is a simplified glimpse at
quarto.log.output(pandoc.blocks)
when run atpost-quarto
(this is very similar topre-quarto
):This looks very similar to the second example: the blocks are nested under a .cell Div that inherits the attributes (
myattr: apple
) of the original code cell. So the layouts must be done during the render filters (which makes sense). If I runquarto.log.output(pandoc.blocks)
post-render, I get:This does a few things:
Question
It is 3 that's causing a problem in my filter. Any attributes on the original code cell in the qmd will be transfered to the .cell Div that, unlike code cells without
layout-ncol
, is not a parent block to the CodeBlock showing the source code. In the render filter that processes these layouts, can those attributes be transferred instead to the parent block with the.quarto-scaffold
class? (it may make sense to transfer the.cell
class there too).Beta Was this translation helpful? Give feedback.
All reactions