Skip to content

[feat]: Self closing tags support ? #221

@gucong3000

Description

@gucong3000

I was try to use gulp-posthtml, to converting URLs in XML files.
But it looks like not support self closing tags <image/>
source:
image
result:
image

This is part of my gulp configuration:

function wxml() {
  return gulp.src(['src/**/*.wxml'], {
    base: projRootDir,
  }).pipe(plumber()).pipe(posthtml([
    function postHTMLReplaceUrl (tree) {
      var baseDir = path.dirname(path.relative(projRootDir, tree.options.from));
      tree.walk(node => {
        let src = node.attrs && node.attrs.src;
        if (!src || /^(?:\w+?:)?\/\//.test(src)) {
          return node;
        } else if (/^\//.test(src)) {
          src = src.slice(1);
        } else {
          src = path.join(baseDir, src);
        }
        if (/^images/.test(src)) {
          node.attrs.src = cdnUrl(src);
        }
        return node;
      });
    }

  ])).pipe(gulp.dest('dist'));
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions