Ho bisogno di una Boccata di attività che passerà attraverso tutti ricevuto i documenti HTML e rimuovere alcuni attributi (come style=""). Ho pensato che avrei potuto farlo allo stesso modo, io lo faccio attraverso il browser, ma sembra non. Qui è quello che sto cercando di fare:
// function to take multiple attributes from an element
const discardAttributes = (element, ...attributes) =>
attributes.forEach((attribute) => element.removeAttribute(attribute));
// run the function on multiple elements
document.querySelectorAll("table, thead, tbody, tr, th, td").forEach((elem) => {
discardAttributes(elem, "cellspacing", "cellpadding", "width", "style");
});
Vorrei quindi prendere la formula sopra e crea un sol boccone.compito in questo modo:
const gulp = require("gulp");
gulp.task("clean", async () => {
gulp.src("src/*.html")
.pipe(discardAttributes())
.pipe(gulp.dest("dist"));
});
Se c'è un plug-in che posso utilizzare per fare questo, si prega di condividere, ma anche, mi piacerebbe imparare a farlo manualmente come questo.
Avrei bisogno di utilizzare through2?
Grazie.