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
Optimize code printing #2445
Optimize code printing #2445
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2445 +/- ##
==========================================
+ Coverage 49.04% 51.22% +2.17%
==========================================
Files 124 124
Lines 5262 5281 +19
Branches 1118 1121 +3
==========================================
+ Hits 2581 2705 +124
+ Misses 2376 2290 -86
+ Partials 305 286 -19 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be necessary to override the default code highlight color scheme for dark themes when printing. Otherwise, the color seems to be slightly muted.
Hi @itsyme and @Tim-Siu thank you for the work on reviewing! I have made some changes accordingly. Do you mind helping me check on Mac again? I'm not sure what's with the highlighting not appearing on the print preview despite it being on the emulator.. Could you help me check if thats the case on Safari and etc as well? |
Hi @yucheng11122017 , |
On which browser? Could you check the emulator as well? |
May I know what is the emulator? Do you mean the preview before printing? The code highlighting isn't working on either Safari or Chrome in both preview and actual printed files. |
You can try to open dev tools -> rendering -> print emulation. |
Hi @yucheng11122017 , |
I tried it on the emulator and it works for me as well however I'm not sure if it working on the emulator may be a reliable indicator of it working when printing in the physical form (https://stackoverflow.com/questions/26123622/print-preview-not-the-same-as-print-emulation-in-chrome) as when I downloaded to PDF (below) the highlights were still not appearing for me. To be 100% sure I can try printing a physical copy out to check if the highlights work. |
I think its cool @itsyme. I tried printing out that day but it doesn't work as well.. Let me see if there's a workaround |
I believe the generated pdf (print to pdf) would be the source of truth, if it has highlight, then the printed version will do too.
Different browsers might have different implementations hence affecting the outcome. We should highlight the recommended (and maybe the unsupported browsers) if we couldn't make it work for all. |
Perhaps it would be good to include the findings in the user guide about which browsers are the most optimal for printing so that users interested in printing can refer to it! |
Sorry about the delay on this issue. I have asked @Tim-Siu to try to investigate this issue on Mac. I suspect that there might not be a workaround but he will update on what he has tried and research :) |
HI @yucheng11122017 , I found this discussion to be relevant. It appears that adding Example: .hljs span.highlighted{
-webkit-print-color-adjust:exact;
background:#e6e6fa !important;
} Output: Alternatively, users can also choose to print background colour themselves in Chrome settings under more settings -> options. You may refer to my branch which seems to have resolved the issue! |
might want to make sure it "works" on safari and firefox also - i believe they use the non-prefixed css (stack overflow link) |
Hi @kaixin-hc , This approach works for Safari as well. (Maybe because Safari is also based on WebKit) It doesn't work for Firefox though. From my observations, there seem to have been many other bugs when printing with Firefox. I am not sure if it is necessary to fix them all. Imag: printing result with firefox and current master branch |
Great investigation! @yucheng11122017 - perhaps you can implement the fix @Tim-Siu suggests, and then include a documentation note that there are known errors with printing on Edge and Firefox? In terms of if we should fix it for Firefox/Edge, though it would be nice to figure out why and support it, if printing is OK on Chrome and Safari I think it is OK to deprioritise this (since a brief google search claims 70% of people are on Chrome or safari, with only 7% on Edge or Firefox) Maybe can discuss in #2397 - probably related |
Apologies for the late response! I missed this in the slew of emails.. I will push the fix and also add a caveat about Firefox in that case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just a small nit in the wording of the documentation.
What is the purpose of this pull request?
Resolves #2438
Overview of changes:
Add CSS which
Anything you'd like to highlight/discuss:
If anyone can help to test on Mac, that will be great.
There seems to be some issue with printing on Edge.. the CSS isnt applied on the preview even though the emulator reflects the changes..
TLDR: Don;t use Edge to print
Testing instructions:
Make code theme dark
Notice that code wrap and code copy buttons are gone
Code highlight is printed
Code theme is light
Proposed commit message: (wrap lines at 72 characters)
Optimize code blocks for printing
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major
,r.Minor
,r.Patch
.Breaking change release note preparation (if applicable):