Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore certain blocks from minification? #50

Open
canebat opened this issue Jun 6, 2015 · 3 comments
Open

Ignore certain blocks from minification? #50

canebat opened this issue Jun 6, 2015 · 3 comments

Comments

@canebat
Copy link

canebat commented Jun 6, 2015

I have a large block of static markdown text that later gets parsed by my javascript.

ie,

<span id="code demo">
    **Test**

    blah blah blah
    ---

    ```
    // This is how to print to console:
    console.log(myvariable);
    ```

    > He said, She said.

</span>

When I minify this, all the spacing gets removed and so the resulting markdown looks all squished when rendered.

Specifying empty: true, loose: true, spare: true does not help.

Is there a way I can keep my markdown text in HTML, but tell minimize to ignore this block?

@Swaagie
Copy link
Owner

Swaagie commented Jun 8, 2015

You could use the defaults blocks of code and/or pre which will not be stripped from spaces. See, https://github.com/Moveo/minimize/blob/master/lib/list.js#L36-L39, the mentioned options only work on attributes. Let me know if this works, PR to improve the docs are always welcome :)

@virgofx
Copy link

virgofx commented Aug 3, 2015

@Swaagie I know you've mentioned in the README.md that PHP inline templates are not supported but adding functionality that would allow for certain start/end blocks to be ignored would solve that as well.

I was thinking about trying to implement this actually and perhaps it would require up to 2 passes where you don't actually ignore certain blocks but replace them with placeholders {{$1}} as necessary prior to the current HTML minification logic and restoring the map subsequently afterwards. Would this be possible? I'm desperately trying to achieve minification of PHTML for the HTML only portion (while ignoring PHP) --- <div>Hello <?php echo 'John'; ?></div>

Would this be possible or easy to integrate?

@Swaagie
Copy link
Owner

Swaagie commented Aug 12, 2015

Sorry for the slow response, the only proper way to implement this would be by providing a custom DOM parser. Currently the domparser of htmlparser2 is used by default. This parser confuses the <?php ?> of PHP with HTML. So parsing PHP templates would require a custom parser that understands these PHP tags. Minimize already supports custom parsers as argument of the constructor. But I think the simpler route is probably processing the templates after the PHP parser has inserted the variables and just before the content is send of the wire to the browser.

edit: as for replacing, that could be done probably as {{$1}} would be seen as text by the parser. That is outside the scope of this module though. But it is something you could probably achieve reasonably simple yourself. By simply replacing the PHP tags before the template is run through minimize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants