jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

Can't echo strings with minus (-) sign #45

Closed Juriy closed 9 years ago

Juriy commented 9 years ago

Hello guys,

Have a look at the following code:

var pp = require('preprocess');
var text = 'Hello <!-- @echo "minus-world" -->';
var out = pp.preprocess(text, {}, 'html');
console.log(out);

I expect it to print

Hello minus-world

But I get back an unprocessed value

Hello <!-- @echo "minus-world" -->

If you remove the minus sign inside of an echo value everything's working fine.

wardpeet commented 9 years ago

It's because of this regex "" not sure why the - is not allowed by the regex. using the following regex instead will make it work. ""

BendingBender commented 9 years ago

Duplicate of #21.

BendingBender commented 9 years ago

Well, atm it is possible to have multiple @echo rules in one line separated by multiple comment blocks like this:

<!-- @echo 'hello' --><!-- @echo 'world' -->

The minus sign is therefore needed in the regex as a delimiter for the otherwise greedy regex search to catch exactly this case

Any ideas on how to achieve the same effect without forbidding the minus sign in echoed strings?