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

Create RenameAttr plugin #1514

Closed
mateuscdomingos opened this issue Aug 10, 2021 · 2 comments
Closed

Create RenameAttr plugin #1514

mateuscdomingos opened this issue Aug 10, 2021 · 2 comments

Comments

@mateuscdomingos
Copy link

mateuscdomingos commented Aug 10, 2021

I need to change maskType to mask-type in mask element.
<svg_ width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="a" maskType="alpha" maskUnits="userSpaceOnUse" x="1" y="1" width="14" height="14">
[...]</svg_>

Create a plugin to rename attributes
I wish I could rename attributes

Alternative: addAttributesToMARKElement
I wish I could add attributes to the MARK element (I can remove the maskType attribute and add mask-type to the MARK element)

@TrySound
Copy link
Member

TrySound commented Aug 10, 2021

Hey, I wouldn't like to add plugins not related to optimisations. Though you can write the plugin by yourself. See

const renameMaskType = {
  name: 'renameMaskType',
  type: 'visitor',
  fn: () => {
    return {
      element: {
        enter: node => {
          node.attributes['mask-type'] = node.attributes.maskType
          delete node.attributes.maskType
        }
      }
    }
  }
}

@mateuscdomingos
Copy link
Author

Thank you very much @TrySound!

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

No branches or pull requests

2 participants