-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Support HTML output #74
Comments
There is currently no support for HTML output. Always happy to accept PRs though! If you want something a little more sensible, you can run it through an ANSI escape sequence stripped like this and then just write it out as text with a monospace font. |
I achieved the output html in my fork by changing the formatting here Line 199 in ccd4651
write!(f, "<span style=\color: "{:x}\">{}</span>", col, Paint::new(&self.0).fg(col)) But the original stderr write can't be used, here should provide an injection mechanism. And I feel that the Color function of |
I thought of a mechanism like this to support different output formats: trait SpanFormatter {
fn write_lhs(&self, w: impl Write) -> std::fmt::Result;
fn write_rhs(&self, w: impl Write) -> std::fmt::Result;
}
impl SpanFormatter for Color {
fn write_lhs(&self, w: impl Write) -> std::fmt::Result {
// Write the ANSI escape code for this color.
write!("\x1b[38;2;{};{};{}m", self.r, self.g, self.b)
}
fn write_rhs(&self, w: impl Write) -> std::fmt::Result {
// recover the default colour
write!(w, "\x1b[0m")
}
}
impl SpanFormatter for HTML {
fn write_lhs(&self, w: impl Write) -> std::fmt::Result {
// Write the HTML span tag for this color.
write!(w, "<span style=\"color: #{:x}\">", self.0)
}
fn write_rhs(&self, w: impl Write) -> std::fmt::Result {
// recover the default colour
write!(w, "</span>")
}
} One of the more complicated aspects of html is that it also needs to support escape |
FWIW we've done this in PRQL with |
Is there any way to render output as html?
I want to render error report in jupyter, but if read
stderr
directly to it will look like this:The text was updated successfully, but these errors were encountered: