내가 쓸 필요가 있는 사용자 정의 꿀꺽 작업을 제거하는 특성에서 내 HTML

0

질문

내가 필요로 하는 꿀꺽이 될 것입니다 작업을 통해 이동 할당된 모든 HTML 문서 및 제거를 특정 속성(예:스타일을=""). 생각할 수 있습을 할 수 있었 같은 방법으로 나는 그것을 통해 브라우저지만,처럼 보이지 않습니다. 여기에 내가 무엇을 하려고:

// 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");
});

내가 좋아하는 다음 공식을 만들고 꿀꺽.과 같은 작업,그래서:

const gulp = require("gulp");

gulp.task("clean",  async () => {
 gulp.src("src/*.html")
  .pipe(discardAttributes())
    .pipe(gulp.dest("dist"));
});

이 있을 경우 플러그인 사용할 수 있는 것이다 이렇게 공유하십시오,하지만 또한,배우고 싶은 그것을 어떻게 수동으로 다음과 같다.

것을 사용할 필요가 through2?

감사합니다.

gulp javascript npm
2021-11-20 16:26:41
1

최고의 응답

0

당신이 일부를 사용할 수 있는 노드 dom 라이브러리,그리고 포장을 꿀꺽. 예를 들어 당신이 시도할 수 있습 jsdom 및 포장재 삼-스:

const gulp = require('gulp');
const dom = require("gulp-dom");

gulp.task("default", async () => {
 gulp.src("src/*.html")
  .pipe(dom(function() {

      // function to take multiple attributes from an element
      const discardAttributes = (element, ...attributes) =>
        attributes.forEach((attribute) => element.removeAttribute(attribute));

      // run the function on multiple elements
      return this.querySelectorAll("table, thead, tbody, tr, th, td").forEach((elem) => {
       discardAttributes(elem, "cellspacing", "cellpadding", "width", "style");
    });

  }))
  .pipe(gulp.dest("dist"));
});
2021-11-21 17:18:21

이 유망 보인다,내가 그것을 시도하십시오. 질문:나는 보지 않 jsdom 어디서나 코드에서 어떻게 와서 놀이까요? 내 멍청한 질문은 하지만 나는 새로운 노드입니다. 업데이트:에 따라 고궁 문서,"[삼-dom]플러그인 랩 jsdom. 하지만,이 플러그인을 사용하지 않는 모든 기능에 의해 제공됩 jsdom. 유일한 목적에 대한 jsdom 이 플러그인에서는 구문 분석하여 HTML 문서로 DOM 그래서 우리는 작업을 실행할 수 있습니다."
desert_dweller

그것은 작품! 대단히 감사합니다. 여기에 무엇을 했습니다. (1)저는 설치 jsdom 로 devDependancy(2)나는 설치된 삼-dom 로 devDependancy(3)붙여 위의 코드와 실행을 꿀꺽. 죄송할 수 없 투표 아직입니다.
desert_dweller

꿀꺽-dom 플러그인이 포함되어 있 jsdom,을 설치할 필요가 없습니다. 는 경우에 당신은 행복한 대답을 수락할 수 있습니다.
Nikolay

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................