Skip to content

Commit

Permalink
fix: append content inside the element, not after it
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Mar 22, 2024
1 parent 1102d43 commit 357f3c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/pipelines/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ impl HtmlPipeline {
let mut target_html = Document(raw_html);
let mut partial_assets = vec![];

// Since the `lol_html` doesnt provide an iterator for elements, we must use our own id.
// Since the `lol_html` doesn't provide an iterator for elements, we must use our own id.
let mut id = 0;

// Setting, and removing attributes could be implemented as a method for `Document`.
// However each selection performed causes a full rewrite of the Html content.
// However, each selection performed causes a full rewrite of the Html content.
// Doing things this way is likely to be better performing for larger files.
//
// This is the first parsing of the Html meaning it is pretty likely to receive
// invalid Html at this stage.
// This is the first parsing of the HTML meaning it is pretty likely to receive
// invalid HTML at this stage.
target_html
.select_mut(r#"link[data-trunk], script[data-trunk]"#, |el| {
'l: {
Expand All @@ -106,7 +106,7 @@ impl HtmlPipeline {
let asset_constructor = match el.tag_name().as_str() {
"link" => TrunkAssetReference::Link,
"script" => TrunkAssetReference::Script,
// Just an early break since we wont do anything else.
// Just an early break since we won't do anything else.
_ => break 'l,
};

Expand All @@ -131,7 +131,7 @@ impl HtmlPipeline {
id += 1;
Ok(())
})
.context("error parsing Hmtl, check Html validity")?;
.context("error parsing HTML, check HTML validity")?;

let mut assets: Vec<TrunkAsset> = futures_util::future::join_all(partial_assets)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Document {

fn append_html(&mut self, selector: &str, html: &str) -> Result<()> {
self.select_mut(selector, |el| {
el.after(html, lol_html::html_content::ContentType::Html);
el.append(html, lol_html::html_content::ContentType::Html);
Ok(())
})
}
Expand Down

0 comments on commit 357f3c0

Please # to comment.