diff --git a/lib/extract.js b/lib/extract.js index fa41af6..acab5c5 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -64,6 +64,7 @@ var Extractor = (function () { this.options = _.extend({ startDelim: '{{', endDelim: '}}', + idTransform: function (s) { return s.trim(); }, markerName: 'gettext', markerNames: [], lineNumbers: true, @@ -97,7 +98,7 @@ var Extractor = (function () { reference = { file: reference }; } - string = string.trim(); + string = this.options.idTransform(string); if (string.length === 0) { return; diff --git a/test/extract.js b/test/extract.js index 52ce38a..3fa10d9 100644 --- a/test/extract.js +++ b/test/extract.js @@ -109,6 +109,20 @@ describe('Extract', function () { assert.deepEqual(catalog.items[0].references, ['test/fixtures/ngif.html:3']); }); + it('Can customize trimming whitespace around strings', function () { + var files = [ + 'test/fixtures/strip-custom.html' + ]; + var catalog = testExtract(files, { + idTransform: function (s) { return s.replace(/\s+/g,' '); } + }); + + assert.equal(catalog.items.length, 1); + assert.equal(catalog.items[0].msgid, ' Hello strip custom '); + assert.equal(catalog.items[0].msgstr, ''); + assert.deepEqual(catalog.items[0].references, ['test/fixtures/strip-custom.html:3']); + }); + it('Can customize delimiters', function () { var files = [ 'test/fixtures/delim.html' diff --git a/test/fixtures/strip-custom.html b/test/fixtures/strip-custom.html new file mode 100644 index 0000000..6e1a755 --- /dev/null +++ b/test/fixtures/strip-custom.html @@ -0,0 +1,8 @@ + +
+Hello + strip custom +
+ + +