@@ -74,20 +74,109 @@ local function def_columns()
7474
7575 -- for html output that isn't reveal...
7676 if _quarto .format .isHtmlOutput () and not _quarto .format .isHtmlSlideOutput () then
77-
77+
7878 -- For HTML output, note that any div marked an aside should
79- -- be marked a column-margin element (so that it is processed
80- -- by post processors).
79+ -- be marked a column-margin element (so that it is processed
80+ -- by post processors).
8181 -- For example: https://github.com/quarto-dev/quarto-cli/issues/2701
8282 if el .classes and tcontains (el .classes , ' aside' ) then
8383 noteHasColumns ()
84- el .classes = el .classes :filter (function (attr )
84+ el .classes = el .classes :filter (function (attr )
8585 return attr ~= " aside"
8686 end )
8787 tappend (el .classes , {' column-margin' , " margin-aside" })
8888 return el
8989 end
90-
90+
91+ elseif _quarto .format .isTypstOutput () then
92+ -- For Typst output, detect column classes to trigger margin layout setup
93+ -- Actual margin note rendering is handled in quarto-post/typst.lua
94+ if hasMarginColumn (el ) or hasColumnClasses (el ) then
95+ noteHasColumns ()
96+ end
97+ -- Convert aside class to column-margin for consistency
98+ if el .classes and tcontains (el .classes , ' aside' ) then
99+ el .classes = el .classes :filter (function (attr )
100+ return attr ~= " aside"
101+ end )
102+ tappend (el .classes , {' column-margin' })
103+ return el
104+ end
105+ -- Handle full-width classes with wideblock
106+ local side , clz = getWideblockSide (el .classes )
107+ if side then
108+ noteHasColumns () -- Ensure margin layout is activated for wideblock
109+ el .classes = el .classes :filter (function (c ) return c ~= clz end )
110+ return make_typst_wideblock {
111+ content = el .content ,
112+ side = side ,
113+ }
114+ end
115+ -- Handle intermediate width classes (body-outset, page-inset, screen-inset)
116+ local intermediateInfo , intermediateClz = getIntermediateWidthClass (el .classes )
117+ if intermediateInfo then
118+ noteHasColumns () -- Ensure margin layout is activated
119+ el .classes = el .classes :filter (function (c ) return c ~= intermediateClz end )
120+ return make_typst_intermediate_width {
121+ content = el .content ,
122+ func = intermediateInfo .func ,
123+ side = intermediateInfo .side ,
124+ }
125+ end
126+ -- Handle margin figures/tables: propagate .column-margin class to FloatRefTarget
127+ -- so they render with notefigure() instead of being wrapped in #note()
128+ if hasMarginColumn (el ) then
129+ local floatRefTargets = el .content :filter (function (contentEl )
130+ return is_custom_node (contentEl , " FloatRefTarget" )
131+ end )
132+ if # floatRefTargets > 0 then
133+ -- Propagate margin class and attributes to each FloatRefTarget and return unwrapped
134+ local result = pandoc .Blocks ({})
135+ for _ , contentEl in ipairs (el .content ) do
136+ if is_custom_node (contentEl , " FloatRefTarget" ) then
137+ local custom = _quarto .ast .resolve_custom_data (contentEl )
138+ if custom ~= nil then
139+ -- Add column-margin class to the float
140+ if custom .classes == nil then
141+ custom .classes = pandoc .List ({' column-margin' })
142+ else
143+ custom .classes :insert (' column-margin' )
144+ end
145+ -- Propagate margin-related attributes (shift, alignment, dy)
146+ if el .attributes then
147+ if custom .attributes == nil then
148+ custom .attributes = {}
149+ end
150+ if el .attributes .shift then
151+ custom .attributes .shift = el .attributes .shift
152+ end
153+ if el .attributes .alignment then
154+ custom .attributes .alignment = el .attributes .alignment
155+ end
156+ if el .attributes .dy then
157+ custom .attributes .dy = el .attributes .dy
158+ end
159+ end
160+ result :insert (contentEl )
161+ end
162+ else
163+ -- Non-float content stays wrapped in margin note
164+ local inner_div = pandoc .Div ({contentEl }, pandoc .Attr (" " , {' column-margin' }))
165+ result :insert (inner_div )
166+ end
167+ end
168+ return result
169+ else
170+ -- For cell-output-display divs with column-margin, the parent FloatRefTarget
171+ -- will handle margin placement. Strip the class to prevent quarto-post from
172+ -- wrapping it in #note() (which would cause double-wrapping with notefigure).
173+ if el .classes :includes (" cell-output-display" ) then
174+ removeColumnClasses (el )
175+ return el
176+ end
177+ end
178+ end
179+
91180 elseif el .identifier and el .identifier :find (" ^lst%-" ) then
92181 -- for listings, fetch column classes from sourceCode element
93182 -- and move to the appropriate spot (e.g. caption, container div)
@@ -175,7 +264,7 @@ local function def_columns()
175264 -- It also means that divs that want to be both a figure* and a table*
176265 -- will never work and we won't get the column-* treatment for
177266 -- everything, just for the table.
178- el .classes = el .classes :filter (function (clz )
267+ el .classes = el .classes :filter (function (clz )
179268 return not isStarEnv (clz )
180269 end )
181270 end
@@ -185,14 +274,14 @@ local function def_columns()
185274 -- the general purpose `sidenote` processing from capturing this
186275 -- element (since floats know how to deal with margin positioning)
187276 local custom = _quarto .ast .resolve_custom_data (contentEl )
188- if custom ~= nil then
277+ if custom ~= nil then
189278 floatRefTarget = true
190279 removeColumnClasses (el )
191280 add_column_classes_and_attributes (columnClasses , columnAttributes , custom )
192281 end
193- end
282+ end
194283 end
195-
284+
196285 if not figOrTable and not floatRefTarget then
197286 processOtherContent (el .content )
198287 end
@@ -267,17 +356,29 @@ local function def_columns()
267356
268357 Span = function (el )
269358 -- a span that should be placed in the margin
270- if _quarto .format .isLatexOutput () and hasMarginColumn (el ) then
359+ if _quarto .format .isLatexOutput () and hasMarginColumn (el ) then
271360 noteHasColumns ()
272361 tprepend (el .content , {latexBeginSidenote (false )})
273362 tappend (el .content , {latexEndSidenote (el , false )})
274363 removeColumnClasses (el )
275364 return el
276- else
365+ elseif _quarto .format .isTypstOutput () and hasMarginColumn (el ) then
366+ -- For Typst, detect margin spans to trigger margin layout setup
367+ -- Actual margin note rendering is handled in quarto-post/typst.lua
368+ noteHasColumns ()
369+ -- Convert aside class to column-margin for consistency
370+ if el .classes and tcontains (el .classes , ' aside' ) then
371+ el .classes = el .classes :filter (function (attr )
372+ return attr ~= " aside"
373+ end )
374+ tappend (el .classes , {' column-margin' })
375+ end
376+ return el
377+ else
277378 -- convert the aside class to a column-margin class
278379 if el .classes and tcontains (el .classes , ' aside' ) then
279380 noteHasColumns ()
280- el .classes = el .classes :filter (function (attr )
381+ el .classes = el .classes :filter (function (attr )
281382 return attr ~= " aside"
282383 end )
283384 tappend (el .classes , {' column-margin' , ' margin-aside' })
0 commit comments