Permalink
Browse files

account for the extra length of html comments

  • Loading branch information...
1 parent a82a12f commit 242fbd80eeb56e202b17a3d7c8d08303eeff16d9 @joshwnj joshwnj committed with Jul 30, 2013
Showing with 29 additions and 0 deletions.
  1. +4 −0 lib/tokenize.js
  2. +25 −0 test/comment.js
View
@@ -43,6 +43,10 @@ module.exports = function (opts) {
if (evname === 'text' || evname === 'script') {
len = arg.length;
}
+ else if (evname === 'comment') {
+ // accomodate for the length of '<!--' and '-->'
+ len = arg.length + 7;
+ }
else {
len = parser._parser.position - position;
}
View
@@ -0,0 +1,25 @@
+var trumpet = require('../');
+var through = require('through');
+var test = require('tape');
+var concat = require('concat-stream');
+
+test('write stream', function (t) {
+ t.plan(1);
+
+ var tr = trumpet();
+ var html = tr.select('html');
+ var ws = html.createWriteStream();
+
+ var s = through();
+ s.pipe(ws);
+ s.end();
+
+ var res = '<!-- test --><html></html>';
+ tr.pipe(concat(function (body) {
+ t.equal(
+ body.toString(),
+ res
+ );
+ }));
+ tr.end(res);
+});

0 comments on commit 242fbd8

Please sign in to comment.