Fix html to rsx conversions
This commit is contained in:
1 parent
459d8d69a7
commit
7be8ec3467
3 files changed
+77
-7
No files matched your search
@@ -276,13 +276,12 @@ impl Writer<'_> {
|
|||||||
let start = location.start();
|
let start = location.start();
|
||||||
let line_start = start.line - 1;
|
let line_start = start.line - 1;
|
||||||
|
|
||||||
let this_line = self.src[line_start];
|
let beginning = self
|
||||||
|
.src
|
||||||
let beginning = if this_line.len() > start.column {
|
.get(line_start)
|
||||||
this_line[..start.column].trim()
|
.filter(|this_line| this_line.len() > start.column)
|
||||||
} else {
|
.map(|this_line| this_line[..start.column].trim())
|
||||||
""
|
.unwrap_or_default();
|
||||||
};
|
|
||||||
|
|
||||||
beginning.is_empty()
|
beginning.is_empty()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,3 +25,6 @@ convert_case = "0.5.0"
|
|||||||
# default = ["html"]
|
# default = ["html"]
|
||||||
|
|
||||||
# eventually more output options
|
# eventually more output options
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
pretty_assertions = "1.2.1"
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
use html_parser::Dom;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple_elements() {
|
||||||
|
let html = r#"
|
||||||
|
<div>
|
||||||
|
<div class="asd">hello world!</div>
|
||||||
|
<div id="asd">hello world!</div>
|
||||||
|
<div id="asd">hello world!</div>
|
||||||
|
<div for="asd">hello world!</div>
|
||||||
|
<div async="asd">hello world!</div>
|
||||||
|
<div LargeThing="asd">hello world!</div>
|
||||||
|
<ai-is-awesome>hello world!</ai-is-awesome>
|
||||||
|
</div>
|
||||||
|
"#
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
let dom = Dom::parse(html).unwrap();
|
||||||
|
|
||||||
|
let body = rsx_rosetta::rsx_from_html(&dom);
|
||||||
|
|
||||||
|
let out = dioxus_autofmt::write_block_out(body).unwrap();
|
||||||
|
|
||||||
|
let expected = r#"
|
||||||
|
div {
|
||||||
|
div { class: "asd", "hello world!" }
|
||||||
|
div { id: "asd", "hello world!" }
|
||||||
|
div { id: "asd", "hello world!" }
|
||||||
|
div { r#for: "asd", "hello world!" }
|
||||||
|
div { r#async: "asd", "hello world!" }
|
||||||
|
div { large_thing: "asd", "hello world!" }
|
||||||
|
ai_is_awesome { "hello world!" }
|
||||||
|
}"#;
|
||||||
|
pretty_assertions::assert_eq!(&out, &expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deeply_nested() {
|
||||||
|
let html = r#"
|
||||||
|
<div>
|
||||||
|
<div class="asd">
|
||||||
|
<div class="asd">
|
||||||
|
<div class="asd">
|
||||||
|
<div class="asd">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"#
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
let dom = Dom::parse(html).unwrap();
|
||||||
|
|
||||||
|
let body = rsx_rosetta::rsx_from_html(&dom);
|
||||||
|
|
||||||
|
let out = dioxus_autofmt::write_block_out(body).unwrap();
|
||||||
|
|
||||||
|
let expected = r#"
|
||||||
|
div {
|
||||||
|
div { class: "asd",
|
||||||
|
div { class: "asd",
|
||||||
|
div { class: "asd", div { class: "asd" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
pretty_assertions::assert_eq!(&out, &expected);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user