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

Parsing of inline <script> #20

Closed
mdix opened this issue Sep 17, 2013 · 6 comments
Closed

Parsing of inline <script> #20

mdix opened this issue Sep 17, 2013 · 6 comments

Comments

@mdix
Copy link

mdix commented Sep 17, 2013

Hi,

I wonder if it's my fault or if it's currently not supported:

I have an *.html document with some inline < script >, and I tried to remove a block:

//@ifdef DEBUG
< some js here >
//@endif

but it just doesn't work. Is js-parsing deactivated when parsing *.html-files? Are you planning to support inlined scripts?

Kind regards
Marc

@drkibitz
Copy link

You may be able to do it like this:

<script>
//<!-- @ifdef DEBUG -->
var blah = 1 + 2;
//<!-- @endif -->
</script>

If you can't it may be route to allow support for it.

@jsoverson
Copy link
Owner

Yeah, the format for mixed source in a file is not intelligent, it doesn't differentiate between languages embedded within a parent source, so @drkibitz's method should work.

@mdix
Copy link
Author

mdix commented Sep 26, 2013

Hi,

umm, nope, doesn't work. It removes the code but keeps the // from the last //

Kind regards
Marc

Edit: Ok, so I got it, at least functional, working.

Won't work

var toBeKept1;
//<!-- @ifdef DEBUG -->
var toBeRemoved;
//<!-- @endif -->
var toBeKept2;
will be rendered to:
var toBeKept1;
// var toBeKept2;

Works:

var toBeKept1;
//<!-- @ifdef DEBUG -->
var toBeRemoved;
//<!-- @endif -->


var toBeKept2;
will be rendered to:
var toBeKept1;
// 

var toBeKept2;

So... it works, but it should remove the //, too.

Kind regards
Marc

Edit: And finally another update: It either works when removing the code or when keeping the code, but not in both cases.

@mdix
Copy link
Author

mdix commented Sep 26, 2013

Hi,

ugh, got it working:

//<!-- @ifdef DEBUG -->//
var code;
//<!-- @endif -->//

Either leaves you with one line '////' (code removed) or code between lines of '////' (code kept). Looks funny, but works. Don't know what happens when the code gets minified, so it might be a cool idea (and I'd be very happy) to fix it.

Kind regards
Marc

@jsoverson
Copy link
Owner

Sorry, should have reviewed the example code above, it should work with straight html syntax, eg do this (remote, can't verify)

<!-- @ifdef DEBUG -->
var code;
<!-- @endif -->

@mdix
Copy link
Author

mdix commented Sep 27, 2013

Hi,

I totally forgot that it's possible to use HTML comments inside the <script>-Tag. Thank you so much for your help, it's working now and also thanks for writing and maintaining it!

Kind regards
Marc

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