Skip to content

Add support for multiple comment formats #10

Open
@JacobDB

Description

@JacobDB

Took me a while to figure out why this wasn't working with my PHP files, but I realized it's because PHP wasn't being recognized as using "HTML-style" comments. I rectified it by using the commentStart and commentEnd parameters, but then I got thinking.

What if I needed to remove blocks of HTML code in one part of a PHP file, and PHP code in another part? I suppose I could wrap the HTML parts in <?php /*removeIf(condition)*/ ?> ... <?php /*endRemoveIf(condition)*/ ?>, but then I'd be stuck with an empty <?php ?>, which isn't ideal.

Additionally, what if I want to search multiple file types for the same condition? For example, remove all PHP, HTML, JS, and CSS for a module. I'd have to duplicate a lot of code in my task, saying "check this format, and then this format, and then this one," which again, isn't ideal.

I'd really like to see an option to set commentStart and commentEnd as arrays, something like the following:

gulp.task("init", function () {
    return gulp.src(src + "/**/*")
        // remove login HTML code if --remove --login is passed
        .pipe(gulpif(argv.remove && argv.login, removeCode({no_login: true, commentStart: ["<!--", "/*", "//"], commentEnd: ["-->", "*/", ""]})))
        // return to the source directory
        .pipe(gulp.dest(src));
});

That way you could parse multiple file types at once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions