index.js 789 B

12345678910111213141516171819202122232425
  1. /*globals module*/
  2. var escapeString = function (str) {
  3. 'use strict';
  4. return str.replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n \'');
  5. };
  6. var createPreprocessor = function (logger, basePath) {
  7. 'use strict';
  8. return function (content, file, done) {
  9. var xmlPath = file.originalPath.replace(basePath + '/', ''),
  10. filename = xmlPath;
  11. file.path = file.path + '.js';
  12. done("window.__xml__ = window.__xml__ || {};\nwindow.__xml__['" +
  13. filename + "'] = new DOMParser().parseFromString('" + escapeString(content) +
  14. "', 'text/xml');\n"
  15. );
  16. };
  17. };
  18. createPreprocessor.$inject = ['logger', 'config.basePath'];
  19. module.exports = {
  20. 'preprocessor:musicxml2js': ['factory', createPreprocessor]
  21. };