node.js - Remove tags without removing content -


i'm looking gulp module capable of deleting <div> tags , closing tags, without removing content/children of said <div>.

does such thing exist?

example code:

<div id="macontainer" contenteditable="true" maconstraint="item.image1 <> ''" mashowalllanguages="false">    <tr>      <td class="img">        <div id="masection" contenteditable="true" maconstraint="item.url1 <> '' , item.promocode1 <> ''" mashowalllanguages="false">          <a href="~probe(101)~" title="~item.alt1~">            <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />          </a>        </div>        <div id="masection" contenteditable="true" maconstraint="item.url1 <> '' , item.promocode1 = ''" mashowalllanguages="false">          <a href="~probe(105)~" title="~item.alt1~">            <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />          </a>        </div>        <div id="masection" contenteditable="true" maconstraint="item.url1 = ''" mashowalllanguages="false">          <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />        </div>      </td>    </tr>  </div>

desired code:

<tr>    <td class="img">      <a href="~probe(101)~" title="~item.alt1~">        <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />      </a>      <a href="~probe(105)~" title="~item.alt1~">        <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />      </a>      <img width="580" height="~item.image1height~" alt="~item.alt1~" src="~item.image1~" />    </td>  </tr>

you use plugins gulp-replace uses regexes:

var gulp = require('gulp'),     replace = require('gulp-replace');  gulp.task('strip-tags', function() {     return gulp.src('template.html')         .pipe(replace(/<div.*?id=.macontainer..*>((?:.|\s)+)<\/div>/im, '$1'))         .pipe(gulp.dest('./dist')); }); 

but regexes bit brittle kind of task imho...

you roll own "plugin" , way :

var gulp = require('gulp'),     through = require('through2'),     cheerio = require('cheerio');  gulp.task('strip-tags2', function() {     return gulp.src('template.html')         .pipe(through.obj(function(file, enc, cb) {             var $ = cheerio.load(file.contents),                 extract = $('#macontainer').children().html();              file.contents = new buffer(extract);              cb(null, file);         }))         .pipe(gulp.dest('./dist')); }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -