diff --git a/src/html.rs b/src/html.rs index d2c64496..ccc2d1b2 100644 --- a/src/html.rs +++ b/src/html.rs @@ -989,6 +989,13 @@ pub fn walk(session: &mut Session, document_url: &Url, node: &Handle) { if let Some(use_attr_href_value) = get_node_attr(node, attr_name) { if session.options.no_images { set_node_attr(node, attr_name, None); + } else if use_attr_href_value.clone().starts_with('#') { + // Relative symbol that resolves to its own URL; keep as-is. + set_node_attr( + node, + attr_name, + Some(use_attr_href_value), + ); } else { let image_asset_url: Url = resolve_url(document_url, &use_attr_href_value); diff --git a/tests/_data_/svg/svg_inline_symbol_use.html b/tests/_data_/svg/svg_inline_symbol_use.html new file mode 100644 index 00000000..1a82ff12 --- /dev/null +++ b/tests/_data_/svg/svg_inline_symbol_use.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/cli/local_files.rs b/tests/cli/local_files.rs index 9c7b3785..06d29272 100644 --- a/tests/cli/local_files.rs +++ b/tests/cli/local_files.rs @@ -252,6 +252,54 @@ document.body.style.color = "red"; + +"## + ); + + // Exit code should be 0 + out.assert().code(0); + } + + #[test] + fn embed_svg_symbol_asset_via_use() { + let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); + let path_html: &Path = Path::new("tests/_data_/svg/svg_inline_symbol_use.html"); + + let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap(); + + // STDERR should list files that got retrieved (only 1; no self-embedding for the relative xlink) + assert_eq!( + String::from_utf8_lossy(&out.stderr), + format!( + r#"{file_url_html} +"#, + file_url_html = Url::from_file_path(fs::canonicalize(path_html).unwrap()).unwrap(), + ) + ); + + // STDOUT should contain HTML with the use id kept the same because it + // references an inlined SVG symbol in the same document + assert_eq!( + String::from_utf8_lossy(&out.stdout), + r##" + + + + + + + + + + + + + "## );