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

add colored text blocks #237

Closed
wants to merge 4 commits into from
Closed

add colored text blocks #237

wants to merge 4 commits into from

Conversation

miguelraz
Copy link
Contributor

@miguelraz miguelraz commented Dec 18, 2024

Fixes #232.

Draft mode while checking out the proof of principle, once that's OK'd I'll go and change the other text blocks, of which there are only 12.

Proposed solution:

Insert raw HTML under <code no-escape> so that the HTML color codes aren't escaped. To get said raw HTML, you can use gnome-terminal, right-clicking Copy as HTML and pasting that.

On macOS, I found VSCode lets you select, then right -click Copy as HTML when the error is output from the integrated terminal, and then selecting Paste As > Insert HTML.

Downside:

The source code looks uuuuuugly 🤮 .

Picture 1: What it looks like in browser.

image

Picture 2: What it looks like as slides

image

Alternative solution

Use this crate (which is what the compiler team uses) https://docs.rs/anstyle-svg/latest/anstyle_svg/#example, though I don't see how serving SVGs is much better as an overall workflow.

Copy link

cloudflare-workers-and-pages bot commented Dec 18, 2024

Deploying ferrous-systems-rust-training with  Cloudflare Pages  Cloudflare Pages

Latest commit: 73940fc
Status: ✅  Deploy successful!
Preview URL: https://762a9f5a.ferrous-systems-rust-training.pages.dev
Branch Preview URL: https://colored-text.ferrous-systems-rust-training.pages.dev

View logs

@miguelraz miguelraz changed the title add colored text slides add colored text blocks Dec 18, 2024
@miguelraz
Copy link
Contributor Author

miguelraz commented Dec 18, 2024

Updating top post:

Aha, Gnome terminal allows one to Copy as HTML which looks ugly as hell but works for fishing out all the examples we want.

@miguelraz
Copy link
Contributor Author

miguelraz commented Jan 3, 2025

Got some feedback from others since JP and Andrei are off:

  • How to get said output from VSCode itself, not just gnome-terminal
  • Trying out different HackMD colorschemes as a check

Not too shabby even on darker schemes:

image

@miguelraz miguelraz mentioned this pull request Jan 6, 2025
@listochkin
Copy link
Member

If I understand correctly, the colors are set to whatever the code editor or terminal have been set to when the author presses "Copy", and text blocks from different authors would have different colors if their local editor / terminal themes do not match.

Maybe we have to have a standardized set of colors to use for different roles in text and do a manual after pass to fix them before publishing. Using Ferrous palette would be preferable. Definitely needs an internal discussion.

@jonathanpallant
Copy link
Member

I think using HTML is OK - these blocks will not change often. Although it might be better to use a style sheet, and then we can have different light-mode/dark-mode versions. You can insert the styles into template.html and use them on any slide.

@jonathanpallant
Copy link
Member

jonathanpallant commented Jan 6, 2025

Also <font> is deprecated. You should use a <span style="..."> tag instead (although it's even less readable).

The other option, which I regret even as I type it out, is to store the text as plain text with ANSI escape codes on disk, use something like {{ #include ./error_1.txt }} in the source, and have both mdslides and an mdbook pre-processor convert it to HTML at compile time. Does mean you can't easily view the error on Github though.

@miguelraz
Copy link
Contributor Author

Now that #242 is ready for review, I'm closing this PR in favor of that fully fleshed out one.

@miguelraz miguelraz closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support colourised text blocks
3 participants