Replies: 2 comments 3 replies
-
Come across this excellent extension when browsing vscode#5953, thank you for your work! Since vscode has introduced its web version, I tried to use the browser's printing button on the vscode workspace web page, and it turns out that we CAN print the same syntax colouring as the editor if we are using the web. However, it still lacks customized uploaded font, so we cannot create a 100% same pdf as it looks in the vscode application. I am not fully aware of how vscode differs in application mode and web mode, and I wonder if we can leverage some of steps how web version does printing to print a 100% same pdf as what it looks in application? |
Beta Was this translation helpful? Give feedback.
-
One comment ... use of a dark theme. I'm 60+, and I find the dark theme a big strain on my eyesight ... I've mentioned this to my other coder friends, and they've got similar experiences |
Beta Was this translation helpful? Give feedback.
-
Paper is white
Many people use a dark theme. If you simply change the background colour from black to white (or transparent) the contrast ratios are inappropriate and the colour scheme is pale and washed out and looks completely different. Theoretically you could write a transformation to adjust the colours but you would have to solve 2 n non-linear equations in 2 n variables to preserve relative hue and saturation, where n is the number of language part styles.
It's not supported by VS Code
For printing you need to pass a big string containing source code to a function that parses it to identify the language parts, then marks it up as HTML with the language parts wrapped in spans applying CSS classes so we can apply a colour scheme. That's what highlightjs does for us. We pass source code and it returns HTML ready for a stylesheet.
VS Code does not export its syntax colouring logic in a form we can use. It works by callbacks each of which processes a language part. It's done like this for performance, so that it only has to process the code that's in the visible part of the screen. Due to the way syntax colouring is done by editor callbacks there isn't a single coherent CSS stylesheet resource.
Could we ask for support from the VS Code team?
They won't even put something on the backlog without 20 upvotes for the issue within 60 days of the issue opening. This won't happen without widespread support or a coordinated effort. Printing is too niche for that kind of support.
We asked for help putting "Print" in the File menu five years ago. It hasn't happened. We asked for help getting a reference to the internal Markdown rendering pipeline too, and they were equally unresponsive (we found an unsupported hack that works).
So emulate the editor with a tall viewport
If that's as easy as it sounds we can expect a PR soon.
and use the callbacks to compile a stylesheet
The documentation is thin and the API is designed to support the editor receiving information (from a language server) not handing it out. It would be a big job and probably impossible without the VS Code team providing a new API.
But, but, but...
If you think we're wrong about this the best counterargument is a working PR, which will be very warmly received and integrated as soon as possible provided that it also addresses the unsuitability of dark themes.
We'd use the editor colour scheme if we could. That was the original plan, and it's no fun having to refuse every time someone asks for it.
What about mapping editor colour schemes to near match highlightjs schemes?
That would work, but only sometimes. It wouldn't work for schemes added by extensions, and not all the baked in schemes have direct equivalents. Inconsistent success would produce an endless stream of unhappy users, and someone would have to maintain the mappings forever.
Beta Was this translation helpful? Give feedback.
All reactions