Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code annotations do not work for ojs cells #7537

Closed
homerhanumat opened this issue Nov 10, 2023 · 4 comments · Fixed by #7608
Closed

code annotations do not work for ojs cells #7537

homerhanumat opened this issue Nov 10, 2023 · 4 comments · Fixed by #7608
Assignees
Labels
bug Something isn't working ojs-engine Issues with the ojs engine triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone.
Milestone

Comments

@homerhanumat
Copy link

Bug description

Annotations work for R code cells, but not for ojs code cells.

Steps to reproduce

Render this example .qmd file:

---
code-annotations: hover
---

```{r}
2 + 2   # <1>
cat("hello")  # <2>
```

1. adding
2. greeting

```{ojs}
Inputs.table(olympians)  // <1>
```

1. displaying

Expected behavior

Annotation for ojs cell should show on hover.

Actual behavior

No annotation appears on hover, and the annotation is shown as an ordered list below the cell in the rendered output.

Your environment

  • OS: MacOS Ventura 13.5.2
  • VS Code 1.84.0

Quarto check output


Quarto 1.4.489
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.8: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.4: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.489
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /Library/TeX/texbin
      Version: 2021

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.8
      Path: /usr/local/opt/python@3.10/bin/python3.10
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
      knitr: 1.44
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK
@homerhanumat homerhanumat added the bug Something isn't working label Nov 10, 2023
@cscheid cscheid self-assigned this Nov 10, 2023
@cscheid cscheid added the ojs-engine Issues with the ojs engine label Nov 10, 2023
@cscheid cscheid added the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Nov 15, 2023
@cscheid
Copy link
Collaborator

cscheid commented Nov 15, 2023

@dragonstyle I looked at a filter trace and at the end of the filter chain, to my eye the OJS annotations match the R annotations. I've tagged you here in case you can easily figure out what's happening in the TS side, but I'm happy to pair with you over this as well.

@cderv
Copy link
Collaborator

cderv commented Nov 16, 2023

@cscheid I believe this is because of the line counter.

See in the HTML produced, we have for OJS code source cell <span id="annotated-cell-1-5"> but the target annotation does not adapt to that counter

<dl>
<dt data-target-cell="annotated-cell-1" data-target-annotation="1">1</dt>
<dd>
<span data-code-cell="annotated-cell-1" data-code-lines="1" data-code-annotation="1">displaying</span>
</dd>
</dl>

So it will look for <span id="annotated-cell-1-1"> which does not exist.

Not sure exactly why the different counter (as if there was 4 more lines), but I believe this is because OJS does set a startFrom attributes for highlighting, which will make Pandoc creates <span id="annotated-cell-1-5"> on the line

This is the intermediate Markdown

```{.js .cell-code startFrom="5" source-offset="0"}
Inputs.table(olympians)  // <1>
```

Like this one
https://github.com/quarto-dev/quarto-cli/blob/main/src/execute/ojs/compile.ts#L585-L589
Or another startFrom in the file.

I think the annotation processing needs to be aware of this line offsetting

@cderv
Copy link
Collaborator

cderv commented Nov 16, 2023

As example to reproduce without OJS, you'll get the same if you apply the offset a the code cell

---
code-annotations: true
---

```{r}
#| code-line-numbers: true
#| attr-source: "startFrom=5"
1 + 1 # <1>
2 + 2
3 + 3 # <2>
```

1. displaying
2. displaying

image

I think I know where this needs to be taken into account

@cderv
Copy link
Collaborator

cderv commented Nov 16, 2023

I have made a PR to fix this specific case.

I believe code annotation and OJS is more complex, because it seems OJS will output results under each line, with no possible grouping.

---
code-annotations: true
---

```{ojs}
1 + 1 // <1>
2 + 2
3 + 3 // <2>
```

1. test
2. test

```{r}
1 + 1 # <1>
2 + 2
3 + 3 # <2>
```

1. test
2. test

image

but this is another issue because in this case the ordered List is not even processed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ojs-engine Issues with the ojs engine triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone.
Projects
None yet
4 participants