Skip to content

Commit

Permalink
Merge pull request #38 from haensl/37
Browse files Browse the repository at this point in the history
#37: Add option to set htmlparser xml mode.
  • Loading branch information
haensl committed Mar 19, 2021
2 parents 857dd56 + 9ed2196 commit 45d0a32
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 159 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.4.0
* [#37: Add option to set htmlparser xml mode.](https://github.com/haensl/gulp-embed-svg/issues/37)
* Update dependencies.

## 1.3.2
* [#35: Update dependencies.](https://github.com/haensl/gulp-embed-svg/issues/35)

Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ This gulp task will inline/embed any images with an SVG source attribute (i.e. `

## Options

* [`selectors`](#selectors): Provide custom CSS selectors to specify which tags should be replaced by embedded SVGs.
* [`attrs`](#attrs): Provide a regular expression to transfer select attributes from matched tags to embedded `<svg>`s.
* [`createSpritesheet`](#create-spritesheet): Set to `true` to embed SVGs via a spritesheet. This reduces generated HTML filesize if you use the same SVG several times on a page.
* [`decodeEntities`](#decode-entities): Set to `true` to decode HTML entities within the document.
* [`root`](#root): Provide the root folder where SVG source images are located.
* [`createSpritesheet`](#create-spritesheet): Set to `true` to embed SVGs via a spritesheet. This reduces generated HTML filesize if you use the same SVG several times on a page.
* [`spritesheetClass`](#spritesheet-class): Customize the CSS class assigned to the generated spritesheet.
* [`selectors`](#selectors): Provide custom CSS selectors to specify which tags should be replaced by embedded SVGs.
* [`spriteIdFn`](#sprite-id-fn): Customize the `id` assigned to the sprites by providing a function that resolves path and index to a string.
* [`spritesheetClass`](#spritesheet-class): Customize the CSS class assigned to the generated spritesheet.
* [`xmlMode`](#xmlmode): Whether or not to read files in xml mode.

### selectors `string | Array<string>`<a name="selectors"></a>

Expand Down Expand Up @@ -464,6 +465,12 @@ gulp.task('embedSvgs', () =>
</html>
```

### xmlMode `boolean` <a name="xmlmode"></a>

Flag to toggle [xml mode](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode).

#### default: `true`

## [Changelog](CHANGELOG.md)

## [License](LICENSE)
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const defaults = {
attrs: /^(?!src).*$/,
root: __dirname,
decodeEntities: false,
xmlMode: true,
createSpritesheet: false,
spritesheetClass: 'svg-sprites',
spriteIdFn: (path, i) => `svg-sprite-${i}`
Expand Down Expand Up @@ -70,7 +71,7 @@ module.exports = (opts = {}) =>

const $ = cheerio.load(file.contents.toString(), {
decodeEntities: options.decodeEntities,
xmlMode: true
xmlMode: options.xmlMode
});
let didInline = false;
let error;
Expand Down
Loading

0 comments on commit 45d0a32

Please sign in to comment.