diff --git a/README.md b/README.md index 0264fc3..da73631 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,41 @@ Results in: ``` +#### options.strictCssXML + +Type: `Boolean` +Defaul: `false` + +Adds `/` self closure to the `link` tag to make it strict XML compliant to prevent some XML parsers from failing to properly parse and validate the document. + +```html + + + + +``` + +```html + +``` + +#### options.strictScriptXML + +Type: `Boolean` +Defaul: `false` + +Adds `//` block to the script tag to prevent some XML parsers from changing the empty tag (``) into a self-closed tag (``). This can be an issue with pre-processed HTML in JSPX. + +```html + + + + +``` + +```html + +``` ## Contributing @@ -197,4 +232,4 @@ See the [CONTRIBUTING Guidelines](https://github.com/jonkemp/useref/blob/master/ ## License -MIT © [Jonathan Kemp](http://jonkemp.com) +MIT © [Jonathan Kemp](http://jonkemp.com) \ No newline at end of file diff --git a/lib/refManager.js b/lib/refManager.js index d723ef2..b0d6fef 100644 --- a/lib/refManager.js +++ b/lib/refManager.js @@ -12,6 +12,10 @@ module.exports = { bb.type = props.type; bb.attbs = props.attbs; bb.alternateSearchPaths = props.alternateSearchPaths; + bb.strictCssXML = + options && options.strictCssXML; + bb.strictScriptXML = + options && options.strictScriptXML; }, transformCSSRefs: function (block, target, attbs) { @@ -21,12 +25,21 @@ module.exports = { // TODO: Determine if 'href' attribute is present. var regcss = /|\))/gmi; + // end closing tag for the link element + var closingTag = '>'; + // Check to see if there are any css references at all. if (block.search(regcss) !== -1) { + if (bb && bb.strictCssXML) { + // make end closing tag self closing + // if strict XML type needed + closingTag = '/>'; + } + if (attbs) { - ref = ''; + ref = ''; + ref = '|\))<[^<]*)*(?:<\/script>|\))/gmi; + // general closing for a script tag + var closingTag = ''; + // Check to see if there are any js references at all. if (block.search(regscript) !== -1) { + if (bb && bb.strictScriptXML) { + // append cdata block to script element + // if strict XML type needed + closingTag = '//' + closingTag; + } + if (attbs) { - ref = ''; + ref = ''; + ref = ' - - + +
+ + \ No newline at end of file diff --git a/test/testfiles/16-win.html b/test/testfiles/16-win.html index 36fb715..8e32ea5 100644 --- a/test/testfiles/16-win.html +++ b/test/testfiles/16-win.html @@ -1,10 +1,10 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/test/testfiles/28-strictCssXML-expected.html b/test/testfiles/28-strictCssXML-expected.html new file mode 100644 index 0000000..781d97a --- /dev/null +++ b/test/testfiles/28-strictCssXML-expected.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/test/testfiles/28-strictCssXML.html b/test/testfiles/28-strictCssXML.html new file mode 100644 index 0000000..cdb330d --- /dev/null +++ b/test/testfiles/28-strictCssXML.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/testfiles/29-strictScriptXML-expected.html b/test/testfiles/29-strictScriptXML-expected.html new file mode 100644 index 0000000..a790c7a --- /dev/null +++ b/test/testfiles/29-strictScriptXML-expected.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/testfiles/29-strictScriptXML.html b/test/testfiles/29-strictScriptXML.html new file mode 100644 index 0000000..9fe298e --- /dev/null +++ b/test/testfiles/29-strictScriptXML.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file