@@ -386,25 +386,28 @@ function code_annotations()
386386
387387 local resolveCellId = function (identifier )
388388 if identifier ~= nil and identifier ~= ' ' then
389- -- Typst fails on duplicate labels, so make repeated ids unique
390- if _quarto .format .isTypstOutput () and usedCellIds [identifier ] then
391- local count = usedCellIds [identifier ] + 1
392- usedCellIds [identifier ] = count
393- local uniqueId = identifier .. ' -' .. tostring (count )
394- usedCellIds [uniqueId ] = 1
395- warn (" Duplicate code cell id '" .. identifier .. " '; using '" .. uniqueId .. " ' for its annotations." )
396- return uniqueId
397- end
398- usedCellIds [identifier ] = 1
399389 return identifier
400390 else
401391 local cellId = ' annotated-cell-' .. tostring (idCounter )
402392 idCounter = idCounter + 1
403- usedCellIds [cellId ] = 1
404393 return cellId
405394 end
406395 end
407396
397+ -- Typst fails on duplicate labels, so make repeated ids of annotated cells unique
398+ local uniqueCellId = function (identifier )
399+ if _quarto .format .isTypstOutput () and usedCellIds [identifier ] then
400+ local count = usedCellIds [identifier ] + 1
401+ usedCellIds [identifier ] = count
402+ local uniqueId = identifier .. ' -' .. tostring (count )
403+ usedCellIds [uniqueId ] = 1
404+ warn (" Duplicate code cell id '" .. identifier .. " '; using '" .. uniqueId .. " ' for its annotations." )
405+ return uniqueId
406+ end
407+ usedCellIds [identifier ] = 1
408+ return identifier
409+ end
410+
408411 local processCodeCell = function (el , identifier )
409412
410413 -- select the process for this format's annotations
@@ -420,7 +423,7 @@ function code_annotations()
420423 if annotations and next (annotations ) ~= nil then
421424 -- store the annotations and cell info
422425 pendingAnnotations = annotations
423- pendingCellId = identifier
426+ pendingCellId = uniqueCellId ( identifier )
424427 pendingOffset = annotationOffset or 1
425428 pendingStartFrom = tonumber (el .attr .attributes [' startFrom' ]) or 1
426429
@@ -456,7 +459,7 @@ function code_annotations()
456459 if codeCell then
457460 processedAnnotation = true
458461 if codeAnnotations ~= _quarto .modules .constants .kCodeAnnotationStyleNone then
459- codeCell .attr .identifier = cellId ;
462+ codeCell .attr .identifier = pendingCellId ;
460463 end
461464 end
462465 return codeCell
@@ -486,7 +489,7 @@ function code_annotations()
486489 if codeCell then
487490 processedAnnotation = true
488491 if codeAnnotations ~= _quarto .modules .constants .kCodeAnnotationStyleNone then
489- codeCell .attr .identifier = cellId ;
492+ codeCell .attr .identifier = pendingCellId ;
490493 end
491494 end
492495 return codeCell
@@ -515,7 +518,7 @@ function code_annotations()
515518 local codeCell = processCodeCell (codeblock , cellId )
516519 if codeCell then
517520 if codeAnnotations ~= _quarto .modules .constants .kCodeAnnotationStyleNone then
518- codeCell .attr .identifier = cellId ;
521+ codeCell .attr .identifier = pendingCellId ;
519522 end
520523 -- Typst DecoratedCodeBlock: embed annotation data inside the block
521524 -- so the marker stays adjacent to the Skylighting call after rendering
@@ -554,7 +557,7 @@ function code_annotations()
554557 local codeCell = processCodeCell (block , cellId )
555558 if codeCell then
556559 if codeAnnotations ~= _quarto .modules .constants .kCodeAnnotationStyleNone then
557- codeCell .attr .identifier = cellId ;
560+ codeCell .attr .identifier = pendingCellId ;
558561 end
559562 -- Typst standalone CodeBlock: emit annotation data alongside
560563 -- the code block. The OL handler will emit annotation items.
0 commit comments