Skip to content

Recognize more embedded modes in htmlmixed mode #1198

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

Closed
wants to merge 2 commits into from
Closed

Recognize more embedded modes in htmlmixed mode #1198

wants to merge 2 commits into from

Conversation

redmunds
Copy link
Contributor

This is code we've been running in Brackets for a long time but never pushed it back.

This recognizes more modes in HTML mixed mode files:

  • CSS in <style> blocks
  • mustache and handlebars HTML in <script> blocks
  • PLAIN text of unknown script types

@marijnh
Copy link
Member

marijnh commented Jan 30, 2013

The existing htmlmixed mode already parses the content of style blocks as css.

Does anyone really use handlebars/mustache script tags? (Why? Isn't the point of those templating languages that they are mixed into the actual document, rather than contained in a script tag that the browser won't render?)

@leeoniya
Copy link
Contributor

Does anyone really use handlebars/mustache script tags?

i believe it's actually fairly common.

@redmunds
Copy link
Contributor Author

The existing htmlmixed mode already parses the content of style blocks as css

Yes. We added the mode to the state for easily detecting mode anywhere in htmlmixed document.

@marijnh
Copy link
Member

marijnh commented Jan 30, 2013

You'll want to use CodeMirror.innerMode for that. The mode property hack has been abandoned in favor of that -- it works on all modes and is easier to use.

@marijnh
Copy link
Member

marijnh commented Jan 30, 2013

Same for compareStates, actually, that isn't a thing anymore in CM 3.

@njx
Copy link

njx commented Jan 30, 2013

@marijnh - templates are put in <script> tags so they can be kept in the main HTML file without actually being rendered directly; typically, the app's JS code pulls the text of the template out of the <script> tag as a string, then passes it to the template framework (Handlebars, Mustache, etc.) to compile it into a template function. (This is considered nicer than having the template string as a literal in the JS itself since it keeps all the HTML-like content together.) Later, it calls the template function to merge data into the template, which produces another HTML string that is then shoved into the DOM programmatically via innerHTML, jQuery, etc.

@redmunds
Copy link
Contributor Author

state.mode is still referenced in copyState. Let me know if I should also remove that.

@marijnh
Copy link
Member

marijnh commented Jan 30, 2013

I've already removed that reference earlier today, when I noticed it while
checking whether the property had really been removed.

@redmunds
Copy link
Contributor Author

Removed state.mode and compareStates.

@marijnh
Copy link
Member

marijnh commented Jan 31, 2013

Merged, and followed up with a few modifications. Please verify that I didn't break anything in my patch (attached).

@marijnh
Copy link
Member

marijnh commented Feb 14, 2013

@redmunds A heads-up: I've made the script handling in htmlmixed mode configurable in ed02c83 , and removed the hard-coded handling of mustache and handlebars. See the changes to mode/htmlmixed/index.html in that patch for an example of how to re-enable your mustache behavior again.

@njx
Copy link

njx commented Feb 14, 2013

Nice. @redmunds -- let's coordinate on the next merge from upstream (hopefully near the beginning of this sprint).

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

Successfully merging this pull request may close these issues.

4 participants