Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
orium committed Sep 16, 2024
1 parent a26caf0 commit eaa561a
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ pub use self::rewriter::{
pub use self::selectors_vm::Selector;
pub use self::transform_stream::OutputSink;

// WIP! also instructiojn in the readme
// WIP! also instruction for `Send` in the readme.

// WIP! having to typre Element<HandlerSendTypes> is a major pain
/// WIP! doc
pub mod send {
use crate::rewriter::{
CommentHandlerSend, DoctypeHandlerSend, ElementHandlerSend, EndHandlerSend,
EndTagHandlerSend, HandlerSendTypes, TextHandlerSend,
};
use crate::OutputSink;

pub type HtmlRewriter<'h, O: OutputSink> = crate::HtmlRewriter<'h, O, HandlerSendTypes>;
pub type HtmlRewriter<'h, O> = crate::HtmlRewriter<'h, O, HandlerSendTypes>;
pub type Settings<'h, 's> = crate::Settings<'h, 's, HandlerSendTypes>;
pub type RewriteStrSettings<'h, 's> = crate::RewriteStrSettings<'h, 's, HandlerSendTypes>;

Expand Down
4 changes: 4 additions & 0 deletions src/rewritable_units/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
|| modified_end_tag_name.is_some()
|| !end_tag_handlers.is_empty()
{
/* WIP!
end_tag_handlers.insert(
0,
H::new_end_tag_handler(|end_tag: &mut EndTag| {
Expand All @@ -567,6 +568,9 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
);
Some(H::tricky_2(end_tag_handlers))
*/
todo!()
} else {
None
}
Expand Down
37 changes: 36 additions & 1 deletion src/rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ impl<'h, O: OutputSink, H: HandlerTypes> Debug for HtmlRewriter<'h, O, H> {
}
}

// WIP! Can we static?
fn handler_adjust_charset_on_meta_tag<'h, H: HandlerTypes>(
encoding: SharedEncoding,
) -> (Cow<'h, crate::Selector>, ElementContentHandlers<'h, H>) {
Expand Down Expand Up @@ -286,6 +285,8 @@ fn handler_adjust_charset_on_meta_tag<'h, H: HandlerTypes>(
text: None,
};

// WIP!now ElementContentHandlers::default().element(H::new_element_handler(handler));

(
Cow::Owned("meta".parse::<crate::Selector>().unwrap()),
content_handlers,
Expand Down Expand Up @@ -344,10 +345,12 @@ mod tests {
use super::*;
use crate::html_content::ContentType;
use crate::test_utils::{Output, ASCII_COMPATIBLE_ENCODINGS, NON_ASCII_COMPATIBLE_ENCODINGS};
use crate::Selector;
use encoding_rs::Encoding;
use itertools::Itertools;
use static_assertions::assert_impl_all;
use std::convert::TryInto;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};

// Assert that HtmlRewriter with `HandlerSendTypes` is `Send`.
Expand Down Expand Up @@ -378,6 +381,38 @@ mod tests {
out
}

// WIP! covariant handler creation
#[test]
fn handlers_covariance() {
let mut x = AtomicUsize::new(0);

let el_handler_static = element!("foo", |_| Ok(()));
let el_handler_local = element!("foo", |_| {
x.fetch_add(1, Ordering::Relaxed);
Ok(())
});

let doc_handler_static = end!(|_| Ok(()));
let doc_handler_local = end!(|_| {
x.fetch_add(1, Ordering::Relaxed);
Ok(())
});

let settings = Settings {
document_content_handlers: vec![doc_handler_static, doc_handler_local],
element_content_handlers: vec![el_handler_static, el_handler_local],
encoding: AsciiCompatibleEncoding::utf_8(),
strict: false,
adjust_charset_on_meta_tag: false,
..Settings::new()
};
let rewriter = HtmlRewriter::new(settings, |_: &[u8]| ());

drop(rewriter);

drop(x);
}

#[test]
fn rewrite_html_str() {
let res = rewrite_str::<HandlerNormalTypes>(
Expand Down
Loading

0 comments on commit eaa561a

Please sign in to comment.