8000 Update README to propose automatic fix for `clipPath` issues · Issue #98 · w0rm/gulp-svgstore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Update README to propose automatic fix for clipPath issues #98
Closed
@stowball

Description

@stowball

I've just ran in to the clipPath issue which is mentioned in the README, so came up with a solution using cheerio which I feel would be good to add to the docs.

The following caters for multiple or no <defs> and <clipPath>s existing within <defs> or not, and combines them all in to 1 <defs> if necessary

.pipe(cheerio({
  run: function ($) {
    const defs = Array.from($('defs').map((i, el) => {
      const html = $(el).html();

      $(el).remove();

      return html;
    })).join('');
    
    const clipPaths = Array.from($('clipPath').map((i, el) => {
        const html = $.html(el);

        $(el).remove();

        return html;
    })).join('');
    
    if (defs.length || clipPaths.length) {
      $('svg').prepend(`<defs>${defs}${clipPaths}</defs>`);
    }
  },
  parserOptions: { xmlMode: true }
}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0