From 5376a8c79176c3f00f63a51245acddbbcf59265c Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Sat, 23 Mar 2024 18:32:25 +0300 Subject: [PATCH 1/5] fix: make manually inserted HTML, spec compliant. --- src/pipelines/js.rs | 4 ++-- src/pipelines/mod.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pipelines/js.rs b/src/pipelines/js.rs index 61bf2f30..31d1f7e0 100644 --- a/src/pipelines/js.rs +++ b/src/pipelines/js.rs @@ -134,13 +134,13 @@ pub struct JsOutput { impl JsOutput { pub async fn finalize(self, dom: &mut Document) -> Result<()> { - let mut attrs = self.attrs.clone(); + let mut attrs = self.attrs; self.integrity.insert_into(&mut attrs); dom.replace_with_html( &super::trunk_script_id_selector(self.id), &format!( - r#""#, attrs = AttrWriter::new(&attrs, AttrWriter::EXCLUDE_SCRIPT), base = &self.cfg.public_url, file = self.file diff --git a/src/pipelines/mod.rs b/src/pipelines/mod.rs index 8fc87a28..a5445b6e 100644 --- a/src/pipelines/mod.rs +++ b/src/pipelines/mod.rs @@ -457,6 +457,8 @@ impl Document { }) } + /// When manually inserting any HTML into the document, the inserted HTML must be HTML + /// compliant. Otherwise the change is ignored. fn replace_with_html(&mut self, selector: &str, html: &str) -> Result<()> { self.select_mut(selector, |el| { el.replace(html, lol_html::html_content::ContentType::Html); From 6aaf2d4e8d2daf12aadff75a6d56ea0de5b0a0f4 Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Sat, 23 Mar 2024 20:18:59 +0300 Subject: [PATCH 2/5] docs: remove incorrect comment. --- src/pipelines/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pipelines/mod.rs b/src/pipelines/mod.rs index a5445b6e..8fc87a28 100644 --- a/src/pipelines/mod.rs +++ b/src/pipelines/mod.rs @@ -457,8 +457,6 @@ impl Document { }) } - /// When manually inserting any HTML into the document, the inserted HTML must be HTML - /// compliant. Otherwise the change is ignored. fn replace_with_html(&mut self, selector: &str, html: &str) -> Result<()> { self.select_mut(selector, |el| { el.replace(html, lol_html::html_content::ContentType::Html); From d80208c66387a69c4a7bae0d6e191f2e5ead236d Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Sat, 23 Mar 2024 20:19:55 +0300 Subject: [PATCH 3/5] docs: add docstring for Document::append_html --- src/pipelines/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pipelines/mod.rs b/src/pipelines/mod.rs index 8fc87a28..63d3c4e0 100644 --- a/src/pipelines/mod.rs +++ b/src/pipelines/mod.rs @@ -450,6 +450,7 @@ impl Document { Ok(()) } + /// Will silently fail when attempting to append to [Void Element](https://developer.mozilla.org/en-US/docs/Glossary/Void_element). fn append_html(&mut self, selector: &str, html: &str) -> Result<()> { self.select_mut(selector, |el| { el.append(html, lol_html::html_content::ContentType::Html); From 4d91bba70775e035318450e63cdd93cf863cd746 Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Mon, 25 Mar 2024 21:42:18 +0300 Subject: [PATCH 4/5] chore: update error message to be spec compliant. --- src/pipelines/js.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipelines/js.rs b/src/pipelines/js.rs index 31d1f7e0..dbb4124d 100644 --- a/src/pipelines/js.rs +++ b/src/pipelines/js.rs @@ -45,7 +45,7 @@ impl Js { // Build the path to the target asset. let src_attr = attrs .get(ATTR_SRC) - .context(r#"required attr `src` missing for `. All `` HTML elements will be replaced with the output HTML of the associated pipeline. Trunk will copy script files found in the source HTML without content modification. This content is hashed for cache control. The `src` attribute must be included in the script pointing to the script file to be processed.