Skip to content

vovanre/gulp-html-sugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-html-sugar

Extendable html syntax sugar Gulp plugin.

Install

Install with npm

npm install gulp-html-sugar --save-dev

Example

gulpfile.js

const htmlSugar = require('gulp-html-sugar');

return gulp.src('src/example.html').pipe(htmlSugar({
    'icon': function ($, element) {
        const iconName = element.html().trim();
        element.replaceWith($(`<svg class="icon ${iconName}"><use xlink:href="sprite.svg#${iconName}"/></svg>`));
     }
})).pipe(gulp.dest('build/'));

example.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example page</title>
  </head>
  <body>
    <icon>trash</icon>
  </body>
</html>

Result:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example page</title>
  </head>
  <body>
    <svg class="icon trash"><use xlink:href="sprite.svg#trash"/></svg>
  </body>
</html>

API

htmlSugar(options)

options.[selector]

Type: function(document, element)

document and element is cheerio objects.

License

MIT © vovanre

About

Extendable html syntax sugar plugin

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published