External `<use>` elements don't reference external elements correctly (only checks including document's defs)
Note: this is cross-posted from https://inkscape.org/forums/beyond/embedded-svg-does-not-display-markers/ - I have cross-posted it here because 1) this may be a bug in 0.92, <strike>and 2) when I try to open `foo.svg` in Inkscape 1.0 beta, Inkscape crashes (which is definitely a bug)</strike> Edit: crash fixed, bug in 0.92 still occurs in 1.0
It was also reported in https://bugs.launchpad.net/inkscape/+bug/1777984
#### Steps to replicate
1. Open [foo.svg](https://gitlab.com/inkscape/inbox/uploads/3c57ab2c85058a26271250de1c3a64ad/foo.svg) in inkscape (contains a `<use>` that references the root element of `bar.svg`
2. Compare to [bar.svg](https://gitlab.com/inkscape/inbox/uploads/b49a05219c82a7b6c0bde1365764a3ae/bar.svg) in Inkscape (contains elements that have markers. These markers are defined in the `<defs>` of `bar.svg`)
#### What happened?
- the marker don't display in `foo.svg`, but do when `bar.svg` is opened directly.
Generally, what is happening is that
- If your document has a `<use>` element that references an element from a separate document, use directives or markers (basically just links) in that external document will not function properly (except for further external <use> elements).
- The links in the external document will match the original document instead (if there is a matching id)
- Even if the xlink:hrefs in the external document refer to elements that are nested within the <use>'d entity, those will not function correctly.
#### What should have happened?
- the marker should have displaced
- more generally, `<use>` elements should deeply clone the contents of the referenced element (see https://www.w3.org/TR/SVG11/struct.html#UseElement). Thus links inside the referenced elements should still work.
#### Attachments
[foo.svg](https://gitlab.com/inkscape/inbox/uploads/3c57ab2c85058a26271250de1c3a64ad/foo.svg) and [bar.svg](https://gitlab.com/inkscape/inbox/uploads/b49a05219c82a7b6c0bde1365764a3ae/bar.svg) from this case
and from the launchpad issue (shows example where the referenced document links to a gradient and a shape, rather than a marker)
snippet from [file.svg](/uploads/6243e9fed13d6b269a4b4053a72e5399/file.svg)
```xml
<use xlink:href="external.svg#use-me" />
```
snippet from [external.svg](/uploads/a9c131471dc438be583f5dcfe86f4966/external.svg)
```xml
<g id="use-me">
<circle id="path815" cx="32" cy="32" r="24"
style="fill:url(#linearGradient1758);fill-opacity:1" />
<use xlink:href="#path815" transform="translate(64)"
style="stroke:#800000" />
</g>
```
and another minimal case from the comments below:
[ink-linker.svg](/uploads/90bedcc82483153005c880267c7f594d/ink-linker.svg)
```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="ink-linked.svg#root" />
</svg>
```
[ink-linked.svg](https://gitlab.com/inkscape/inbox/uploads/7682ea1fe0900a3700b413dc862df57b/ink-linked.svg)
```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="root" viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="0" y="0" width="50" height="50" id="original_object" />
<use xlink:href="#original_object" id="clone" fill="blue" />
</svg>
```
We expect the blue clone to be visible, as it is if we explicitly reference the document the reference is from for all links. So ink-linked.svg is changed to
```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="root" viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="0" y="0" width="50" height="50" id="original_object" />
<use xlink:href="ink-linked.svg#original_object" id="clone" fill="blue" />
</svg>
```
This doesn't work with markers afaik.
#### Version info
1.0beta and 0.92 and 0.92.2 2405546, 2018-03-11
Search terms: (launchpad, gitlab: inkscape/inkscape, gitlab: inkscape/inbox)
"external reference"
"external link"
"reference file"
"link file"
issue