diff --git a/hubbub.rs b/hubbub.rs index 16a48bf..4e2b94c 100644 --- a/hubbub.rs +++ b/hubbub.rs @@ -74,7 +74,8 @@ pub struct TreeHandler { add_attributes: ~fn(node: NodeDataPtr, attributes: ~[Attribute]), set_quirks_mode: ~fn(mode: QuirksMode), encoding_change: ~fn(encname: ~str), - complete_script: ~fn(script: NodeDataPtr) + complete_script: ~fn(script: NodeDataPtr), + complete_style: ~fn(style: NodeDataPtr), } pub struct TreeHandlerPair { @@ -131,7 +132,8 @@ impl Parser { set_quirks_mode: tree_callbacks::set_quirks_mode, encoding_change: tree_callbacks::encoding_change, complete_script: tree_callbacks::complete_script, - ctx: unsafe { cast::transmute(to_unsafe_ptr(&self.tree_handler)) } + complete_style: tree_callbacks::complete_style, + ctx: unsafe { cast::transmute(to_unsafe_ptr(&self.tree_handler)) }, } }); @@ -166,6 +168,16 @@ impl Parser { } } + pub fn enable_styling(&self, enable: bool) { + unsafe { + debug!("enabling styling"); + let hubbub_error = ll::parser::hubbub_parser_setopt(self.hubbub_parser, + ll::PARSER_ENABLE_STYLING, + cast::transmute(&enable)); + assert!(hubbub_error == ll::OK); + } + } + pub fn parse_chunk(&self, data: &[u8]) { unsafe { debug!("parsing chunk"); @@ -490,6 +502,15 @@ pub mod tree_callbacks { (this.tree_handler.complete_script)(from_hubbub_node(script)); return ll::OK; } + + pub extern fn complete_style(ctx: *c_void, style: *c_void) -> ll::Error { + debug!("ll complete style"); + + let self_opt: &Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_ref(); + (this.tree_handler.complete_style)(from_hubbub_node(style)); + return ll::OK; + } } pub extern fn allocator(ptr: *mut c_void, len: size_t, _pw: *c_void) -> *mut c_void { diff --git a/ll.rs b/ll.rs index a528634..73e0f9f 100644 --- a/ll.rs +++ b/ll.rs @@ -51,6 +51,7 @@ pub static PARSER_TREE_HANDLER: c_int = 3; pub static PARSER_DOCUMENT_NODE: c_int = 4; pub static PARSER_ENABLE_SCRIPTING: c_int = 5; pub static PARSER_PAUSE: c_int = 6; +pub static PARSER_ENABLE_STYLING: c_int = 7; pub struct ParserOptParamsTokenHandler { handler: *u8, @@ -109,7 +110,8 @@ pub struct TreeHandler { set_quirks_mode: *u8, encoding_change: *u8, complete_script: *u8, - ctx: *c_void + complete_style: *u8, + ctx: *c_void, } // types.h