Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andrey-hohlov/posthtml-inline-svg

PostHTML plugin that inline svg icons in HTML
https://github.com/andrey-hohlov/posthtml-inline-svg

posthtml posthtml-plugin svg-icons

Last synced: about 1 month ago
JSON representation

PostHTML plugin that inline svg icons in HTML

Awesome Lists containing this project

README

        

# posthtml-inline-svg

[PostHTML](https://github.com/posthtml/posthtml) plugin that inline svg icons in HTML. Like GitHub [does](https://github.blog/2016-02-22-delivering-octicons-with-svg/) with Octicons.

### Before

```html

```

### After

```html

```

## Install

```bash
npm i -D posthtml posthtml-inline-svg
```

## Usage

```js
const path = require('path')
const fs = require('fs')
const posthtml = require('posthtml');
const inlineSVG = require('posthtml-inline-svg');

posthtml(inlineSVG({
cwd: path.resolve('src'),
tag: 'icon',
attr: 'src',
}))
.process(fs.readFileSync('index.html', 'utf8'))
.then((result) => console.log(result.html));
```

## Options

|Option|Default|Description|
|:-:|:--|:--|
| **cwd** | `process.cwd()` | Path icon source related to |
| **tag** | `icon` | HTML-tag to process |
| **attr** | `src` | Attribute to get icon path |
| **comment** | `false` | Render HTML comment with icon source before icon markup |
| **svgo** `since 0.2.0` | `null` | Custom [SVGO](https://github.com/svg/svgo) config |