Skip to content

feat(typst): add code annotation and filename support#14170

Open
mcanouil wants to merge 19 commits intoquarto-dev:mainfrom
mcanouil:feat/typst-annotation-filename
Open

feat(typst): add code annotation and filename support#14170
mcanouil wants to merge 19 commits intoquarto-dev:mainfrom
mcanouil:feat/typst-annotation-filename

Conversation

@mcanouil
Copy link
Collaborator

@mcanouil mcanouil commented Mar 6, 2026

Introduce a unified wrapper for code blocks and skylighting transformed code blocks in Typst.

Add filename processing (lua/Typst) and code-annotation processing (lua/Typst).

A rendered PDF document titled "Code Annotations & Filename" showing three sections.
The first section, "Code Cell with Filename and Annotations", displays an R code block with a "hello.R" filename tab above it, containing `print("Hello, world!")` with a circled annotation marker (1) on the right, followed by output `[1] "Hello, world!"` and annotation text "This is a comment in R. It will not be executed as code."
The second section, "Code Cell with Annotations", shows the same R code and output but without the filename tab.
The third section, "Code Cell with Filename", shows the same R code and output with the "hello.R" filename tab but without any annotation marker.
A rendered PDF document showing three sections on page 2.
The first section, "Code Block with Filename and Annotations", displays a Python code block with a "hello.R" filename tab, containing `print("Hello, world!")` with a circled annotation marker (1), and annotation text "This is a comment in R. It will not be executed as code."
The second section, "Code Block with Annotations", shows two lines of Python code (`print("Hello, world!")` and `print("Bye, world!")`) each with a circled annotation marker (1), followed by annotation text "This is a comment in Python. It will not be executed as code."
The third section, "Code Block with Filename", shows a Typst code block with a "hello.typ" filename tab containing `#let hello = "Hello, world!"`.

---
title: "Code Annotations & Filename"
format:
  typst:
    keep-typ: true
    pdf-standard: ua-1
syntax-highlighting: github-dark
code-annotations: true
engine: knitr
---

## Code Cell with Filename and Annotations

```{r}
#| filename: "hello.R"
print("Hello, world!") # <1>
```

1. This is a comment in R. It will not be executed as code.

## Code Cell with Annotations

```{r}
print("Hello, world!") # <1>
```

1. This is a comment in R. It will not be executed as code.

## Code Cell with Filename

```{r}
#| filename: "hello.R"
print("Hello, world!")
```

{{< pagebreak >}}

## Code Block with Filename and Annotations

```{.r filename="hello.R"}
print("Hello, world!") # <1>
```

1. This is a comment in R. It will not be executed as code.

## Code Block with Annotations

```{.python}
print("Hello, world!") # <1>
print("Bye, world!") # <1>
```

1. This is a comment in Python. It will not be executed as code.

## Code Block with Filename

```{.typst filename="hello.typ"}
#let hello = "Hello, world!"
```

To-Do:

  • Investigate the "test-bundle" CI/CD failures
  • Create changelog-1.10.md and add entry

mcanouil added 9 commits March 6, 2026 10:15
Add quarto-circled-number, quarto-code-block, and quarto-annotation-item
functions for code annotation support and filename bar in Typst output.
Route all native raw code blocks through the unified wrapper.
Lua filters need to know whether Skylighting is active to choose
between emitting annotation markers (Skylighting) or wrapping
CodeBlocks directly (native/none highlighting).
Add helper functions for Typst annotation data (typstAnnotationsDict,
typstAnnotationMarker, wrapTypstAnnotatedCode), register Typst
annotation processor, and handle standalone CodeBlock,
DecoratedCodeBlock, and OL paths for Typst output.

Skylighting mode emits a comment marker for the TS post-processor.
Native mode wraps CodeBlocks in quarto-code-block with annotations.
OL items become quarto-annotation-item raw Typst blocks.
Patch Skylighting function to accept annotations parameter, track line
position unconditionally, render circled annotation numbers per line,
and route output through quarto-code-block wrapper. Merge Lua-emitted
annotation comment markers into Skylighting call sites.
Wrap code blocks with filename attribute in quarto-code-block(filename: ...)
for Typst output, rendering a simple filename bar above the code.
Add smoke-all tests for:
- Code annotations with Skylighting (default)
- Code annotations with native highlighting
- Code annotations disabled (none)
- Filename bar on code blocks
@mcanouil mcanouil self-assigned this Mar 6, 2026
@mcanouil mcanouil changed the title feat(typst)= Add code annotation and filename support feat(typst): add code annotation and filename support Mar 6, 2026
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Mar 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mcanouil mcanouil marked this pull request as ready for review March 9, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants