Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marker tags removed despite being used #2079

Open
kv-bh opened this issue Sep 30, 2024 · 1 comment
Open

Marker tags removed despite being used #2079

kv-bh opened this issue Sep 30, 2024 · 1 comment
Labels

Comments

@kv-bh
Copy link

kv-bh commented Sep 30, 2024

Simple optimize command can result in markers being removed:
svgo -i input.svg -o output.svg

Input file:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <style>
.line {
  fill: none;
  stroke: #f00;
  stroke-width: 4px;
  marker-end: url(#arrow);
}
#arrow {}
  </style>
  <defs>
    <marker id="arrow" class="arrow" overflow="visible" markerHeight="1" markerWidth="1" orient="auto-start-reverse" preserveAspectRatio="xMidYMid" viewBox="0 0 1 1">
      <path d="M-3-3 0 0l-3 3"/>
    </marker>
  </defs>
  <path d="M 0 50 H 100" class="line"/>
</svg>

Output file:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M0 50h100" style="fill:none;stroke:red;stroke-width:4px;marker-end:url(#arrow)"/></svg>

Note that the arrow marker is missing in the output.

In the input file, if #arrow {} is either removed or changed to .arrow {}, the problem doesn't occur.

SVGO 3.3.2
Node 20.10.0

@kv-bh kv-bh added the bug label Sep 30, 2024
@johnkenny54
Copy link
Contributor

SVGO doesn't handle <style> elements well. I've been working on a version that addresses some of the limitations of SVGO, at https://www.npmjs.com/package/svgo-ll

svgo-ll keeps the <marker> element, though I did notice that it fails to delete class="line" (which doesn't cause any display problems, but it should be removed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants