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

Clean up "html" pseudo-mode hacks #12247

Open
core-ai-bot opened this issue Aug 31, 2021 · 6 comments
Open

Clean up "html" pseudo-mode hacks #12247

core-ai-bot opened this issue Aug 31, 2021 · 6 comments

Comments

@core-ai-bot
Copy link
Member

Issue by peterflynn
Wednesday Feb 27, 2013 at 00:34 GMT
Originally opened as adobe/brackets#2965


We have a number of hacks to deal with the fact that the tokens "htmlmixed" mode generates for HTML content actually say their mode is "xml". (We care about the mode of individual tokens so as to distinguish JS, CSS, etc. that might be embedded in the HTML).

  • TokenUtils.getModeAt() has a hardcoded special case for this
  • LanguageManager constructs a fake "html" mode through a back channel (see _setLanguageForMode("html", html) at bottom)
  • Language has a special override of the main mode->language mapping just to support this case (see html._setLanguageForMode("xml", html) at bottom -- the only usage of this mechanism).

There are several ways we could fix this & remove those hacks:

a) Make HTMLUtils and other code handle seeing "xml" tokens. Dennis pointed out that much of the functionality there should be callable on any XML content anyway (e.g. getTagAttributes(), getTagInfo()). Cons: tokens remain seemingly confusing; would never be able to distinguish any sort of non-HTML XML embedded inside HTML; we're basically leaving an implementation detail of htmlmixed mode exposed; may break extensions.

b) Change htmlmixed to pull in XML mode by a mimetype alias, which is increasingly becoming the "official" way to reference modes with non-default configurations. So instead of CodeMirror.getMode(config, {name: "xml", htmlMode: true}) it would do CodeMirror.getMode(config, "text/html")). But we'd either have to change all our code that looks for a mode name "html" to look for "text/html" instead, or use "html" as the mime name even though it's not in mimetype format. Cons: requires CodeMirror changes; may involve nonstandard usage of CM's mimetype facility.

For original discussion, see these threads:

https://github.com/adobe/brackets/pull/2844#discussion_r3075488
https://github.com/adobe/brackets/pull/2844#discussion_r3147278
@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Feb 27, 2013 at 00:34 GMT


Not part of Sprint 21

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Friday Mar 01, 2013 at 19:17 GMT


reviewed,@gruehle,@peterflynn I wonder if this is worth a x point improvement story?

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Friday Mar 01, 2013 at 19:18 GMT


Made it a medium priority, pending further review

@core-ai-bot
Copy link
Member Author

Comment by DennisKehrig
Monday Mar 04, 2013 at 18:15 GMT


Actually the "xml" mode would already register a "text/html" mode:

if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});

But it's already taken by "htmlmixed":

CodeMirror.defineMIME("text/html", "htmlmixed");

So there's a conflict here.

@core-ai-bot
Copy link
Member Author

Comment by DennisKehrig
Monday Mar 04, 2013 at 18:18 GMT


Regarding using "html" as the MIME mode, either this was overlooked or MIME modes don't need a slash, but the "gfm" mode does this:

CodeMirror.defineMIME("gfmBase", { ... })

This might indicate we could just use "html" as a MIME mode, requiring fewer changes indeed. However, we'd still need to map the mode "html" for the language "HTML" to itself, as we now do with "xml". The latter currently doesn't even have an effect, that's just a preparation for when we remove the hack in getModeAt.

@core-ai-bot
Copy link
Member Author

Comment by DennisKehrig
Monday Mar 04, 2013 at 18:21 GMT


Regarding a) - how are we leaving anything exposed there? Nobody tells HTMLUtils to do something with "xml", it just does this internally, right?

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

1 participant