diff --git a/examples/html2text.rs b/examples/html2text.rs
index 88bd8fd..8f26668 100644
--- a/examples/html2text.rs
+++ b/examples/html2text.rs
@@ -126,7 +126,14 @@ where
.unwrap();
}
}
- if literal {
+ if flags.show_dom {
+ let conf = config::plain();
+ let conf = update_config(conf, &flags);
+ let dom = conf.parse_html(input).unwrap();
+ dom.as_dom_string()
+ } else if flags.show_render {
+ todo!()
+ } else if literal {
let conf = config::with_decorator(TrivialDecorator::new());
let conf = update_config(conf, &flags);
conf.string_from_read(input, flags.width).unwrap()
@@ -148,6 +155,8 @@ struct Flags {
ignore_css_colours: bool,
#[cfg(feature = "css")]
use_only_css: bool,
+ show_dom: bool,
+ show_render: bool,
}
fn main() {
@@ -166,6 +175,8 @@ fn main() {
ignore_css_colours: false,
#[cfg(feature = "css")]
use_only_css: false,
+ show_dom: false,
+ show_render: false,
};
let mut literal: bool = false;
@@ -214,6 +225,16 @@ fn main() {
StoreTrue,
"Don't use default non-CSS colours",
);
+ ap.refer(&mut flags.show_dom).add_option(
+ &["--show-dom"],
+ StoreTrue,
+ "Show the parsed HTML DOM instead of rendered output",
+ );
+ ap.refer(&mut flags.show_render).add_option(
+ &["--show-render"],
+ StoreTrue,
+ "Show the computed render tree instead of the rendered output",
+ );
ap.parse_args_or_exit();
}
diff --git a/src/css/parser.rs b/src/css/parser.rs
index 607c341..0419d6b 100644
--- a/src/css/parser.rs
+++ b/src/css/parser.rs
@@ -385,7 +385,7 @@ pub(crate) fn parse_color_attribute(
text: &str,
) -> Result>> {
let (_rest, value) = parse_value(text).map_err(|_| empty_fail())?;
- parse_color(&value)
+ parse_color(&value.tokens)
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -404,11 +404,15 @@ pub fn parse_declaration(text: &str) -> IResult<&str, Option> {
))(text)?;
let decl = match prop.0.as_str() {
"background-color" => {
- let value = parse_color(&value)?;
+ let value = parse_color(&value.tokens)?;
Decl::BackgroundColor { value }
}
+ "background" => match parse_background_color(&value)? {
+ Some(value) => Decl::BackgroundColor { value },
+ _ => Decl::Unknown { name: prop },
+ },
"color" => {
- let value = parse_color(&value)?;
+ let value = parse_color(&value.tokens)?;
Decl::Color { value }
}
"height" => {
@@ -457,12 +461,12 @@ fn empty_fail() -> nom::Err> {
nom::Err::Error(nom::error::Error::new("", ErrorKind::Fail))
}
-fn parse_color(value: &RawValue) -> Result>> {
+fn parse_color(tokens: &[Token]) -> Result>> {
let fail_error = empty_fail();
- if value.tokens.is_empty() {
+ if tokens.is_empty() {
return Err(fail_error);
}
- match &value.tokens[..] {
+ match tokens {
[Token::Ident(c)] => {
let colour = match c.deref() {
"aqua" => Colour::Rgb(0, 0xff, 0xff),
@@ -492,7 +496,7 @@ fn parse_color(value: &RawValue) -> Result {
- let rgb_args = &value.tokens[1..value.tokens.len() - 1];
+ let rgb_args = &tokens[1..tokens.len() - 1];
match rgb_args {
[Number(r), Comma, Number(g), Comma, Number(b)] => {
let r = r.parse().map_err(|_e| empty_fail())?;
@@ -527,6 +531,22 @@ fn parse_color(value: &RawValue) -> Result Result