PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.33k stars 1.29k forks source link

Some tokens have different background color #3822

Closed ruslaniv closed 3 weeks ago

ruslaniv commented 2 months ago

Information

Description Some tokens have background color that is different from the background color of the page proper which does not make for a good reading experience

Code snippet

import functools  
import time  
from typing import Callable, Any  
</br>
def async_timed():  
    def wrapper(func: Callable) -> Callable:  
    @functools.wraps(func)  
        async def wrapped(*args, **kwargs) -> Any:  
            print(f'starting {func} with args {args} {kwargs}') start = time.time()  
            try:  
                return await func(*args, **kwargs) finally:  
                end = time.time()  
                total = end - start  
                print(f'finished {func} in {total:.4f} second(s)')  
            return wrapped  
        return wrapper  

[Test page](https://prismjs.com/test.html#language=python&text=import%20functools%20%20%0Aimport%20time%20%20%0Afrom%20typing%20import%20Callable%2C%20Any%20%20%0A%3C%2Fbr%3E%0Adef%20async_timed()%3A%20%20%0A%09def%20wrapper(func%3A%20Callable)%20-%3E%20Callable%3A%20%20%0A%09%40functools.wraps(func)%20%20%0A%09%09async%20def%20wrapped(*args%2C%20**kwargs)%20-%3E%20Any%3A%20%20%0A%09%09%09print(f'starting%20%7Bfunc%7D%20with%20args%20%7Bargs%7D%20%7Bkwargs%7D')%20start%20%3D%20time.time()%20%20%0A%09%09%09try%3A%20%20%0A%09%09%09%09return%20await%20func(*args%2C%20**kwargs)%20finally%3A%20%20%0A%09%09%09%09end%20%3D%20time.time()%20%20%0A%09%09%09%09total%20%3D%20end%20-%20start%20%20%0A%09%09%09%09print(f'finished%20%7Bfunc%7D%20in%20%7Btotal%3A.4f%7D%20second(s)')%20%20%0A%09%09%09return%20wrapped%20%20%0A%09%09return%20wrapper%20%20%0A)

This is from the test page. As you can see some tokens have background color that is different the page background color ![CleanShot 2024-09-02 at 14 27 54](https://github.com/user-attachments/assets/76dfd6d8-260f-4028-b5b5-ab03033b8dc7) This is my own local installation, and also some tokens have their own background color ![CleanShot 2024-09-02 at 14 30 32](https://github.com/user-attachments/assets/27f2238b-6604-4f25-abf9-01ea57edbe98) I tried to tinker with prism.css but I could not solve this problem
Golmote commented 3 weeks ago

Hello,

The default theme indeed uses a background-color for some tokens: https://github.com/PrismJS/prism/blob/master/themes/prism.css#L109-L110

You should be able to easily override that CSS rule to remove the background on your end.