diff --git a/core/src/renderer/css/cssom.rs b/core/src/renderer/css/cssom.rs index 80406a4..6dc254c 100644 --- a/core/src/renderer/css/cssom.rs +++ b/core/src/renderer/css/cssom.rs @@ -154,7 +154,7 @@ impl Declaration { pub fn new() -> Self { Self { property: String::new(), - value: ComponentValue::Keyword(String::new()), + value: ComponentValue::Ident(String::new()), } } @@ -169,17 +169,7 @@ impl Declaration { /// https://www.w3.org/TR/css-syntax-3/#component-value /// https://www.w3.org/TR/css-values-4/#component-types -#[derive(Debug, Clone, PartialEq)] -pub enum ComponentValue { - /// https://www.w3.org/TR/css-values-3/#keywords - Keyword(String), - /// https://www.w3.org/TR/css-values-3/#numeric-types - /// This is one of basic data types. - Number(f64), - /// https://www.w3.org/TR/css-syntax-3/#preserved-tokens - /// The token from the list of tokens produced by the tokenizer. - PreservedToken(CssToken), -} +pub type ComponentValue = CssToken; #[derive(Debug, Clone)] pub struct CssParser { @@ -211,16 +201,9 @@ impl CssParser { /// https://www.w3.org/TR/css-syntax-3/#consume-component-value fn consume_component_value(&mut self) -> ComponentValue { - let token = match self.t.next() { - Some(t) => t, - None => panic!("should have a token but got None"), - }; - - match token { - CssToken::Ident(ident) => ComponentValue::Keyword(ident.to_string()), - CssToken::Number(num) => ComponentValue::Number(num), - _ => ComponentValue::PreservedToken(token), - } + self.t + .next() + .expect("should have a token in consume_component_value") } /// https://www.w3.org/TR/css-syntax-3/#qualified-rule @@ -267,8 +250,6 @@ impl CssParser { /// https://www.w3.org/TR/css-syntax-3/#consume-a-declaration fn consume_declaration(&mut self) -> Option { - self.t.peek()?; - // Create a new declaration with its name set to the value of the current input token. let mut declaration = Declaration::new(); declaration.set_property(self.consume_ident()); @@ -284,6 +265,7 @@ impl CssParser { // "4. As long as the next input token is anything other than an , consume a // component value and append it to the declaration’s value." + // TODO: support multiple values in one declaration. declaration.set_value(self.consume_component_value()); Some(declaration) @@ -315,25 +297,16 @@ impl CssParser { CssToken::Ident(ref _ident) => { if let Some(declaration) = self.consume_declaration() { declarations.push(declaration); - if self.t.peek() == Some(&CssToken::Delim(',')) { - self.t.next(); - } - } - } - CssToken::StringToken(_) => { - self.t.next(); - if self.t.peek() == Some(&CssToken::Delim(',')) { - self.t.next(); - } - } - CssToken::Number(_) => { - self.t.next(); - if self.t.peek() == Some(&CssToken::Delim(',')) { - self.t.next(); } } _ => { - console_warning(&self.browser, format!("unexpected token {:?}", token)); + console_warning( + &self.browser, + format!( + "unexpected token in consume_list_of_declarations {:?}", + token + ), + ); self.t.next(); } } @@ -478,7 +451,7 @@ mod tests { rule.set_selector(Selector::TypeSelector("p".to_string())); let mut declaration = Declaration::default(); declaration.set_property("color".to_string()); - declaration.set_value(ComponentValue::Keyword("red".to_string())); + declaration.set_value(ComponentValue::Ident("red".to_string())); rule.set_declarations(vec![declaration]); let expected = [rule]; @@ -502,7 +475,7 @@ mod tests { rule.set_selector(Selector::IdSelector("id".to_string())); let mut declaration = Declaration::default(); declaration.set_property("color".to_string()); - declaration.set_value(ComponentValue::Keyword("red".to_string())); + declaration.set_value(ComponentValue::Ident("red".to_string())); rule.set_declarations(vec![declaration]); let expected = [rule]; @@ -526,7 +499,7 @@ mod tests { rule.set_selector(Selector::ClassSelector("class".to_string())); let mut declaration = Declaration::default(); declaration.set_property("color".to_string()); - declaration.set_value(ComponentValue::Keyword("red".to_string())); + declaration.set_value(ComponentValue::Ident("red".to_string())); rule.set_declarations(vec![declaration]); let expected = [rule]; @@ -550,9 +523,7 @@ mod tests { rule1.set_selector(Selector::TypeSelector("p".to_string())); let mut declaration1 = Declaration::default(); declaration1.set_property("content".to_string()); - declaration1.set_value(ComponentValue::PreservedToken(CssToken::StringToken( - "Hey".to_string(), - ))); + declaration1.set_value(ComponentValue::StringToken("Hey".to_string())); rule1.set_declarations(vec![declaration1]); let mut rule2 = QualifiedRule::default(); @@ -562,7 +533,7 @@ mod tests { declaration2.set_value(ComponentValue::Number(40.0)); let mut declaration3 = Declaration::default(); declaration3.set_property("color".to_string()); - declaration3.set_value(ComponentValue::Keyword("blue".to_string())); + declaration3.set_value(ComponentValue::Ident("blue".to_string())); rule2.set_declarations(vec![declaration2, declaration3]); let expected = [rule1, rule2]; diff --git a/core/src/renderer/css/token.rs b/core/src/renderer/css/token.rs index 9a8a030..aefd145 100644 --- a/core/src/renderer/css/token.rs +++ b/core/src/renderer/css/token.rs @@ -177,6 +177,7 @@ impl Iterator for CssTokenizer { // returned value, and return it. if self.input[self.pos + 1].is_ascii_alphabetic() && self.input[self.pos + 2].is_alphanumeric() + && self.input[self.pos + 3].is_alphanumeric() { // skip '@' self.pos += 1; diff --git a/core/src/renderer/dom/node.rs b/core/src/renderer/dom/node.rs index 113173a..068865a 100644 --- a/core/src/renderer/dom/node.rs +++ b/core/src/renderer/dom/node.rs @@ -16,7 +16,8 @@ use alloc::rc::{Rc, Weak}; use alloc::string::String; use alloc::vec::Vec; use core::cell::RefCell; -use core::fmt::{Display, Formatter}; +use core::fmt::Display; +use core::fmt::Formatter; use core::str::FromStr; #[derive(Debug, Clone)] diff --git a/core/src/renderer/html/parser.rs b/core/src/renderer/html/parser.rs index 5fdc3ff..aa7873e 100644 --- a/core/src/renderer/html/parser.rs +++ b/core/src/renderer/html/parser.rs @@ -213,6 +213,13 @@ impl HtmlParser { match self.mode { // https://html.spec.whatwg.org/multipage/parsing.html#the-initial-insertion-mode InsertionMode::Initial => { + // Ignore . + // is generated as a Char token. + if let Some(HtmlToken::Char(_)) = token { + token = self.t.next(); + continue; + } + self.mode = InsertionMode::BeforeHtml; continue; } @@ -296,7 +303,6 @@ impl HtmlParser { match token { Some(HtmlToken::Char(c)) => { if c == ' ' || c == '\n' { - self.insert_char(c); token = self.t.next(); continue; } @@ -534,7 +540,7 @@ impl HtmlParser { _ => { console_warning( &self.browser, - format!("unknown tag {:?}", tag), + format!("unsupported start tag in InBody {:?}", tag), ); token = self.t.next(); } @@ -616,7 +622,7 @@ impl HtmlParser { _ => { console_warning( &self.browser, - format!("unknown tag {:?}", tag), + format!("unsupported end tag InBody {:?}", tag), ); token = self.t.next(); } diff --git a/core/src/renderer/layout/layout_object.rs b/core/src/renderer/layout/layout_object.rs index 1d73758..2968c8e 100644 --- a/core/src/renderer/layout/layout_object.rs +++ b/core/src/renderer/layout/layout_object.rs @@ -11,7 +11,6 @@ use crate::renderer::css::cssom::ComponentValue; use crate::renderer::css::cssom::Declaration; use crate::renderer::css::cssom::Selector; use crate::renderer::css::cssom::StyleSheet; -use crate::renderer::css::token::CssToken; use crate::renderer::dom::node::ElementKind; use crate::renderer::dom::node::Node; use crate::renderer::dom::node::NodeKind; @@ -208,7 +207,7 @@ impl LayoutObject { for declaration in declarations { match declaration.property.as_str() { "background-color" => { - if let ComponentValue::Keyword(value) = &declaration.value { + if let ComponentValue::Ident(value) = &declaration.value { let color = match Color::from_name(value) { Ok(color) => color, Err(e) => { @@ -220,9 +219,7 @@ impl LayoutObject { continue; } - if let ComponentValue::PreservedToken(CssToken::HashToken(color_code)) = - &declaration.value - { + if let ComponentValue::HashToken(color_code) = &declaration.value { let color = match Color::from_code(color_code) { Ok(color) => color, Err(e) => { @@ -235,7 +232,7 @@ impl LayoutObject { } } "color" => { - if let ComponentValue::Keyword(value) = &declaration.value { + if let ComponentValue::Ident(value) = &declaration.value { let color = match Color::from_name(value) { Ok(color) => color, Err(e) => { @@ -246,9 +243,7 @@ impl LayoutObject { self.style.set_color(color); } - if let ComponentValue::PreservedToken(CssToken::HashToken(color_code)) = - &declaration.value - { + if let ComponentValue::HashToken(color_code) = &declaration.value { let color = match Color::from_code(color_code) { Ok(color) => color, Err(e) => { @@ -260,7 +255,7 @@ impl LayoutObject { } } "display" => { - if let ComponentValue::Keyword(value) = declaration.value { + if let ComponentValue::Ident(value) = declaration.value { let display_type = match DisplayType::from_str(&value) { Ok(display_type) => display_type, Err(e) => { diff --git a/net/wasabi/src/http.rs b/net/wasabi/src/http.rs index 40318ea..ee9d180 100644 --- a/net/wasabi/src/http.rs +++ b/net/wasabi/src/http.rs @@ -17,6 +17,54 @@ use noli::net::TcpStream; use saba_core::error::Error; use saba_core::http::HttpResponse; +static FAKE_RESPONSE_BODY: &str = r#" + + + Example Domain title + + + + + + + +
+

Example Domain

+

This domain is for use in illustrative examples in documents. You may use this + domain in literature without prior coordination or asking for permission.

+

More information...

+
+ + +"#; + +/* static FAKE_RESPONSE_BODY: &str = r#" Example Domain Response @@ -60,6 +108,7 @@ static FAKE_RESPONSE_BODY: &str = r#" "#; +*/ pub struct HttpClient {}