jonkemp / useref

Parse build blocks in HTML files to replace references
MIT License
51 stars 13 forks source link

Add Feature: strictXML Add options for working with a strict XML parser… #13

Closed slickplaid closed 7 years ago

slickplaid commented 8 years ago

... such as jspx which can mangle code and cause browsers to improperly format it to the user.

The Problem

I'm working on a project that utilizes Java's JSPX format which pre-processes HTML files served to the user. I am working on integrating a front-end build process to their workflow, but the JSPX processing is so heavy handed that there is absolutely no option for disabling some "features" that force empty tags into self terminating tags.

<script src="..."></script> turns into <script src="..." />, <link ...> without a self terminated / completely breaks compilation. I have looked into patching the behavior on the pre-processors end, but they give no options or concessions on that it needs to work that way.

Proposed Solution

Add two options:

I have included a proper fix for pull request #12 and made it an option rather than forcing it for the user.

All tests and linting should be passing, although I had to make a concession to not pass the options object to the formatter and instead pass it to the bb object because of some linting rules that were violated with number of arguments and number of statements in a function. Hopefully these are to the project's standards.

Let me know if there's anything else I can do to get these options into the package. I'd prefer to use this widely accepted package vs. my one-off branch that includes these options for the small (but non-zero, if myself and #12 's show) amount of users who have this same problem.

coveralls commented 8 years ago

Coverage Status

Changes Unknown when pulling 8b5b7336abb106283985ca9cd4ac520e807977fb on slickplaid:slickplaid-patch-2 into \ on jonkemp:master**.

slickplaid commented 8 years ago

Just to comment on the 8b5b733 commit: I have no idea how those files weren't included in my original fork from your project. I've included them now.

jonkemp commented 8 years ago

Sorry it's taken so long to get to this. For what you are wanting, you may be able to use custom blocks. Documentation is here:

https://github.com/jonkemp/useref#custom-blocks

I was able to get your test passing this way without using your code changes.

var useref = require('useref');
var result = useref(inputHtml, {
  test: function (content, target, options) {
    return '<link rel="stylesheet" href="/css/combined.css"/>';
  }
});
var useref = require('useref');
var result = useref(inputHtml, {
  test: function (content, target, options) {
    return '<script src="scripts/combined.concat.min.js">//<![CDATA[ //]]></script>';
  }
});