quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.78k stars 309 forks source link

Python code highlighting not identifying variables, modules, methods, or arguments #10488

Open nickvigilante opened 1 month ago

nickvigilante commented 1 month ago

Bug description

One of our users reported they were seeing some not very colorful examples of Python code, and I didn't think much of it until this moment. I tried creating a custom theme with a bunch of jarring colors, and I observed that a similar script in R is able to highlight much more than what Python is able to highlight, including the function names and parameters.

I'm not sure if this is a Quarto bug or a Skylighting bug, but I thought I would start the conversation here in case it's an issue with the way Quarto implements Skylighting.

Steps to reproduce

  1. Clone https://github.com/nickvigilante/code-highlighting-issue
  2. quarto preview

Expected behavior

All code elements, including import tokens, variables, modules, methods, and arguments, should be highlighted.

Actual behavior

Some elements are missing highlighting.

Your environment

Quarto check output

Quarto 1.5.56 [✓] Checking versions of quarto binary dependencies... Pandoc version 3.2.0: OK Dart Sass version 1.70.0: OK Deno version 1.41.0: OK Typst version 0.11.0: OK [✓] Checking versions of quarto dependencies......OK [✓] Checking Quarto installation......OK Version: 1.5.56 Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK Tex: (not detected)

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

[✓] Checking Python 3 installation....OK Version: 3.10.14 (Conda) Path: /Users/nickv/miniforge3/bin/python Jupyter: 5.7.2 Kernels: ir, python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK Version: 4.4.1 Path: /opt/homebrew/Cellar/r/4.4.1/lib/R LibPaths:

[✓] Checking Knitr engine render......OK

mcanouil commented 1 month ago

Highlighting is not handle by Quarto. It's from Pandoc/Skylighting as documented: https://quarto.org/docs/output-formats/html-code.html#highlighting

quarto pandoc index.qmd --from markdown --to html --highlight-style ugly.theme -o index.html -s
InputOutput
````qmd --- title: Pandoc Skylighting --- ```py from math import factorial as fac def nameAge(name, age): print("Hi, I am", name) print("My age is ", age) print("Factorial of my age is ", fac(age)) nameAge(name="Prince", age=20) for i in range(0, 10): if i % 2 == 0: print(f"{i} is even") ``` ```` image
nickvigilante commented 1 month ago

Thanks, will log there.

cscheid commented 1 month ago

@mcanouil, in the future can you make sure to ask our folks to create a Quarto-less repro when we move bugs to Pandoc? I really want to minimize the disruption on third-party repos. Thanks.