@@ -108,14 +108,14 @@ end
108108
109109-- Skylighting mode: emit a Typst comment that the TS post-processor
110110-- will merge into the Skylighting call site.
111- local function typstAnnotationMarker (annotations )
111+ local function typstAnnotationMarker (annotations , cellId )
112112 local dict = typstAnnotationsDict (annotations )
113- return pandoc .RawBlock (" typst" , " // quarto-code-annotations: " .. dict )
113+ return pandoc .RawBlock (" typst" , " // quarto-code-annotations: " .. ( cellId or " " ) .. " " .. dict )
114114end
115115
116116-- Native/none mode: wrap a CodeBlock in #quarto-code-annotation(annotations)[...].
117117-- raw.line numbers always start at 1 regardless of startFrom, so adjust keys.
118- local function wrapTypstAnnotatedCode (codeBlock , annotations )
118+ local function wrapTypstAnnotatedCode (codeBlock , annotations , cellId )
119119 local startFrom = tonumber (codeBlock .attr .attributes [' startFrom' ]) or 1
120120 local adjustedAnnotations = {}
121121 for annoteId , lineNumbers in pairs (annotations ) do
@@ -126,14 +126,18 @@ local function wrapTypstAnnotatedCode(codeBlock, annotations)
126126 adjustedAnnotations [annoteId ] = adjusted
127127 end
128128 local dict = typstAnnotationsDict (adjustedAnnotations )
129+ local cellIdParam = " "
130+ if cellId and cellId ~= " " then
131+ cellIdParam = " , cell-id: \" " .. cellId .. " \" "
132+ end
129133 local lang = codeBlock .attr .classes [1 ] or " "
130134 local code = codeBlock .text
131135 local maxBackticks = 2
132136 for seq in code :gmatch (" `+" ) do
133137 maxBackticks = math.max (maxBackticks , # seq )
134138 end
135139 local fence = string.rep (" `" , maxBackticks + 1 )
136- local raw = " #quarto-code-annotation(" .. dict .. " )[" .. fence .. lang .. " \n " .. code .. " \n " .. fence .. " ]"
140+ local raw = " #quarto-code-annotation(" .. dict .. cellIdParam .. " )[" .. fence .. lang .. " \n " .. code .. " \n " .. fence .. " ]"
137141 return pandoc .RawBlock (" typst" , raw )
138142end
139143
@@ -497,9 +501,9 @@ function code_annotations()
497501 and pendingAnnotations and next (pendingAnnotations ) ~= nil then
498502 if param (constants .kSyntaxHighlighting , true ) then
499503 block .content [1 ].content [1 ] = codeCell
500- block .content [1 ].content :insert (1 , typstAnnotationMarker (pendingAnnotations ))
504+ block .content [1 ].content :insert (1 , typstAnnotationMarker (pendingAnnotations , pendingCellId ))
501505 else
502- block .content [1 ].content [1 ] = wrapTypstAnnotatedCode (codeCell , pendingAnnotations )
506+ block .content [1 ].content [1 ] = wrapTypstAnnotatedCode (codeCell , pendingAnnotations , pendingCellId )
503507 end
504508 else
505509 block .content [1 ].content [1 ] = codeCell
@@ -535,10 +539,10 @@ function code_annotations()
535539 and codeAnnotations ~= constants .kCodeAnnotationStyleNone
536540 and pendingAnnotations and next (pendingAnnotations ) ~= nil then
537541 if param (constants .kSyntaxHighlighting , true ) then
538- outputBlock (typstAnnotationMarker (pendingAnnotations ))
542+ outputBlock (typstAnnotationMarker (pendingAnnotations , pendingCellId ))
539543 outputBlock (codeCell )
540544 else
541- outputBlock (wrapTypstAnnotatedCode (codeCell , pendingAnnotations ))
545+ outputBlock (wrapTypstAnnotatedCode (codeCell , pendingAnnotations , pendingCellId ))
542546 end
543547 else
544548 outputBlock (codeCell )
@@ -560,7 +564,7 @@ function code_annotations()
560564 if pendingAnnotations [annoteId ] then
561565 local content = pandoc .write (pandoc .Pandoc ({v [1 ]}), " typst" )
562566 annotationBlocks :insert (pandoc .RawBlock (" typst" ,
563- " #quarto-annotation-item(" .. tostring (annotationNumber ) .. " , [" .. content .. " ])" ))
567+ " #quarto-annotation-item(\" " .. ( pendingCellId or " " ) .. " \" , " .. tostring (annotationNumber ) .. " , [" .. content .. " ])" ))
564568 end
565569 end
566570
@@ -574,7 +578,7 @@ function code_annotations()
574578 if useSkylighting then
575579 return nil
576580 else
577- return wrapTypstAnnotatedCode (el , pendingAnnotations )
581+ return wrapTypstAnnotatedCode (el , pendingAnnotations , pendingCellId )
578582 end
579583 end
580584 end
@@ -584,12 +588,12 @@ function code_annotations()
584588 if is_custom_node (resolvedCell ) then
585589 local custom = _quarto .ast .resolve_custom_data (resolvedCell ) or pandoc .Div ({})
586590 if useSkylighting then
587- custom .content :insert (1 , typstAnnotationMarker (pendingAnnotations ))
591+ custom .content :insert (1 , typstAnnotationMarker (pendingAnnotations , pendingCellId ))
588592 end
589593 custom .content :insert (dlDiv )
590594 else
591595 if useSkylighting then
592- resolvedCell .content :insert (1 , typstAnnotationMarker (pendingAnnotations ))
596+ resolvedCell .content :insert (1 , typstAnnotationMarker (pendingAnnotations , pendingCellId ))
593597 end
594598 resolvedCell .content :insert (dlDiv )
595599 end
0 commit comments