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

Cannot use feature css #143

Closed
weezy20 opened this issue Apr 6, 2024 · 6 comments
Closed

Cannot use feature css #143

weezy20 opened this issue Apr 6, 2024 · 6 comments

Comments

@weezy20
Copy link

weezy20 commented Apr 6, 2024

I am trying to render some css in the HTML, and I believe I need the feature css for this to work but I cannot add it in my toml file due to this :

# Cargo.toml
html2text = { version = "0.12.4", features = ["css"]}
error: failed to select a version for the requirement `lightningcss = "^1.0.0-alpha.54"`
candidate versions found which didn't match: 1.0.0-alpha.52, 1.0.0-alpha.51, 1.0.0-alpha.50, ...
location searched: crates.io index
required by package `html2text v0.12.4`
    ... which satisfies dependency `html2text = "^0.12.4"` (locked to 0.12.4) of package `weather v0.1.0 (/home/abhishek/quick-test/weather-rs)`
if you are looking for the prerelease package it needs to be specified explicitly
    lightningcss = { version = "1.0.0-alpha.52" }
perhaps a crate was updated and forgotten to be re-vendored?

Here's my code which isn't working due to the above:

let s = config::rich()
        .add_css()
        .string_from_read(&mut reader, 150)
        .context("Render failed")?;
@weezy20
Copy link
Author

weezy20 commented Apr 6, 2024

Update: Seems to be building now, but add_css isn't what I was looking for.

@jugglerchris
Copy link
Owner

I'm in the process of replacing that dependency (it's pretty big compared to the rest of the library, and I'm only using a small fraction of the functionality)!

What were you hoping you would be able to do?

@weezy20
Copy link
Author

weezy20 commented Apr 6, 2024

So the html that I'm converting to text has some styling. When I use curl I can easily see the styles which I believe are ansi encoded color sequences. I'm trying to replicate that with your html2text library. Here's my repo:
https://github.com/weezy20/weather-rs

It works but there's no terminal colors and that's the problem i'm trying to solve. Enabled use_doc_css on the config as well, but that wasn't it.

@jugglerchris
Copy link
Owner

I fetched https://wttr.in/london and what I got back was just plain text with terminal sequences, not HTML - just writing it straight to the terminal shows the colours - there's no HTML involved (at least with what I got back), so html2text doesn't help you.

If you've also got some HTML with CSS styles you want to turn into terminal colours, then try the html2text example program, which can turn the styles into terminal sequences - something like (from the html2text source tree)

cargo run --features=css --example html2text --colour -css foo.html

(or stdin by default)

@weezy20
Copy link
Author

weezy20 commented Apr 6, 2024

@jugglerchris did you use curl? Because that does indeed print colors on my terminal.

If you check the default response, from reqwest you can see the full html + styles.

@jugglerchris
Copy link
Owner

jugglerchris commented Apr 7, 2024

Ok, I used a web browser to get the HTML (I assume it's different Accept: headers or similar).

The styles seem to work for me - I used:

cargo run --features=css --example html2text -- --css --colour london.html --width=160

That was ok, but had a lot of extra blue (because there are some default styles, in this case <pre> contents in blue). I added a --only-css option in #144 to only use the CSS colours and I think it looks right.

To do this from the library, it's something like:

let coloured_text = html2text::config::rich()
       .use_doc_css()
       .coloured(my_html, 160 /* width */, my_colour_map)?;

where my_colour_map can be a cut down version of default_colour_map in examples/html2text.rs which only pays attention to RichAnnotation::Colour(c).

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

No branches or pull requests

2 participants