diff options
-rw-r--r-- | src/servo/parser/html.rs | 15 | ||||
-rw-r--r-- | src/servo/parser/html_builder.rs | 3 | ||||
-rw-r--r-- | src/test/about-mozilla.html | 54 |
3 files changed, 67 insertions, 5 deletions
diff --git a/src/servo/parser/html.rs b/src/servo/parser/html.rs index 7e472081de2..13c9273dc92 100644 --- a/src/servo/parser/html.rs +++ b/src/servo/parser/html.rs @@ -15,6 +15,7 @@ enum token { to_start_opening_tag(str), to_end_opening_tag, to_end_tag(str), + to_self_close_tag, to_text(str), to_attr(str, str), to_doctype, @@ -131,10 +132,13 @@ impl methods for parser { coe_eof { ret to_eof; } } - ret alt self.state { + let token = alt self.state { ps_normal { self.parse_in_normal_state(ch) } ps_tag { self.parse_in_tag_state(ch) } - } + }; + + #debug["token=%?", token]; + ret token; } fn parse_in_normal_state(c: u8) -> token { @@ -195,8 +199,13 @@ impl methods for parser { ret to_end_opening_tag; } + if ch == ('/' as u8) { + self.state = ps_normal; + ret to_self_close_tag; + } + if !ch.is_alpha() { - fail "expected alphabetical in tag"; + fail #fmt("expected alphabetical in tag but found %c", ch as char); } // Parse an attribute. diff --git a/src/servo/parser/html_builder.rs b/src/servo/parser/html_builder.rs index f5545b8d8c4..93c77e5046e 100644 --- a/src/servo/parser/html_builder.rs +++ b/src/servo/parser/html_builder.rs @@ -47,7 +47,6 @@ fn build_dom(scope: dom::node_scope, let mut cur = scope.new_node(dom::nk_element(element("html", ~es_div))); loop { let token = stream.recv(); - #debug["token=%?", token]; alt token { parser::to_eof { break; } parser::to_start_opening_tag("div") { @@ -80,7 +79,7 @@ fn build_dom(scope: dom::node_scope, parser::to_end_opening_tag { #debug("end opening tag"); } - parser::to_end_tag(_) { + parser::to_end_tag(_) | parser::to_self_close_tag { // TODO: Assert that the closing tag has the right name. // TODO: Fail more gracefully (i.e. according to the HTML5 // spec) if we close more tags than we open. diff --git a/src/test/about-mozilla.html b/src/test/about-mozilla.html new file mode 100644 index 00000000000..b392ddcad61 --- /dev/null +++ b/src/test/about-mozilla.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<html> +<head> +<title>The Book of Mozilla, 11:9</title> +<style type="text/css"> +html { + background: maroon; + color: white; + font-style: italic; +} + +#moztext { + margin-top: 15%; + font-size: 1.1em; + font-family: serif; + text-align: center; + line-height: 1.5; +} + +#from { + font-size: 1.95em; + font-family: serif; + text-align: right; +} + +em { + font-size: 1.3em; + line-height: 0; +} + +a { + text-decoration: none; + color: white; +} +</style> +</head> +<body> + +<p id="moztext"> +Mammon slept. And the <em>beast reborn</em> spread over the earth and its numbers +grew legion. And they proclaimed the times and <em>sacrificed</em> crops unto the +fire, with the <em>cunning of foxes</em>. And they built a new world in their own +image as promised by the <em><a href="http://www.mozilla.org/about/mozilla-manifesto.html"> +sacred words</a></em>, and <em><a href="http://wiki.mozilla.org/About:mozilla">spoke +</a></em> of the beast with their children. Mammon awoke, and lo! it was +<em>naught</em> but a follower. +</p> + +<p id="from"> +from <strong>The Book of Mozilla,</strong> 11:9<br/><small>(10th Edition)</small> +</p> + +</body> +</html> |