Skip to content

Instantly share code, notes, and snippets.

@praveensewak
Created June 18, 2019 01:37
Show Gist options
  • Save praveensewak/2d23227cb3546c45580373e7e0290e20 to your computer and use it in GitHub Desktop.
Save praveensewak/2d23227cb3546c45580373e7e0290e20 to your computer and use it in GitHub Desktop.
var fs = require('fs')
var cleaner = require('clean-html')
function readFiles(dir, onFileContent, onError) {
fs.readdir(dir, function (err, filenames) {
if (err) {
onError(err)
return
}
filenames.forEach(function (filename) {
fs.readFile(dir + filename, 'utf-8', function (err, content) {
if (err) {
onError(err)
return
}
onFileContent(filename, content)
})
})
})
}
var data = {}
var options = {
'add-remove-tags': ['html', 'head', 'meta', 'style', 'body', 'span', 'div'],
'remove-empty-tags': ['div', 'p'],
'replace-nbsp': true,
'add-remove-attributes': ['class', 'id']
}
readFiles('source\\', function (filename, content) {
data[filename] = content
console.log(filename)
cleaner.clean(content, options, function (html) {
fs.writeFile('output\\' + filename, html, function (err) {
if (err) {
console.log(err)
return
}
})
})
}, function (err) {
throw err
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment