Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions tests/_data_/svg/svg_inline_symbol_use.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="icon-1" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 20h4V10h3l-5-6.5L7 10h3v10Z" />
</symbol>
<symbol id="icon-2" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 20h4V10h3l-5-6.5L7 10h3v10Z" />
</symbol>
</defs>
</svg>

<button class="tm-votes-lever__button" data-test-id="votes-lever-upvote-button" title="Like" type="button">
<svg class="icon">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-1" href="#icon-1">
</use>
</svg>
</button>
</body>
</html>
48 changes: 48 additions & 0 deletions tests/cli/local_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,54 @@ document.body.style.color = "red";
</button>


</body></html>
"##
);

// 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##"<html><head><meta name="robots" content="none"></meta></head><body>
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="icon-1" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 20h4V10h3l-5-6.5L7 10h3v10Z"></path>
</symbol>
<symbol id="icon-2" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 20h4V10h3l-5-6.5L7 10h3v10Z"></path>
</symbol>
</defs>
</svg>

<button class="tm-votes-lever__button" data-test-id="votes-lever-upvote-button" title="Like" type="button">
<svg class="icon">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-1" href="#icon-1">
</use>
</svg>
</button>

</body></html>
"##
);
Expand Down