Swaagie / minimize

Minimize HTML
MIT License
163 stars 18 forks source link

non-callback API #8

Closed su9204 closed 10 years ago

su9204 commented 10 years ago

Can we have a API like this var Minimize = require('minimize') , minimize = new Minimize({});

var resultData = minimize.parse(content);

The reason is, in some situation, it needs to be in a callback which is expected to return a result from the parser, For example, the string replace in place, String.replace(Regex, callback_function(rawhtml_snippet_match) { return minimize.parse(rawhtml_snippet_match); });

Thanks.

su9204 commented 10 years ago

By the way, it is very nice that "this module parses the DOM as string as opposes to an object.", which I think make it possible to minify html templates.

Swaagie commented 10 years ago

This is a bit tricky, the callback is required by the htmlparser2 module, that module parses the DOM async. I'm not sure if that module has a sync procedure, i'll check it. Would it be possible to turn that logic around, like parse the rawhtml_snippet_match first and replace against that string after

Swaagie commented 10 years ago

As far as I can tell a fully sync method is not possible atm due to htmlparser2 using domHandler which is completely async, closing this for now. Feel free to re-open when you have an awesome idea to do this.