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

Discuss: Restricting language subset used for sublanguage detection #1212

Closed
chrisvfritz opened this issue Jun 12, 2016 · 7 comments · Fixed by #2444
Closed

Discuss: Restricting language subset used for sublanguage detection #1212

chrisvfritz opened this issue Jun 12, 2016 · 7 comments · Fixed by #2444
Labels
bug help welcome Could use help from community parser

Comments

@chrisvfritz
Copy link

When limiting auto highlight to a language subset, it only works for top-level languages. So when parsing some HTML with JavaScript inside with:

hljs.highlightAuto(
  code,
  [ 'html', 'css', 'javascript' ]
).value

the JavaScript may still be interpreted as ActionScript, for example. 😕

@Sannis Sannis added the bug label Jun 12, 2016
@isagalaev
Copy link
Member

Good catch, thanks. And that should be fixable in a fairly straightforward way. I'll try to get to this one before the next release.

@isagalaev isagalaev self-assigned this Jun 12, 2016
@chrisvfritz
Copy link
Author

😄 Thanks!

@joshgoebel joshgoebel added the help welcome Could use help from community label Oct 25, 2019
@joshgoebel
Copy link
Member

I think the problem here is misstated - or at least the implied solution is not correct. If the same filters used for language were applied to sublanguage someone could easily break many grammars without realizing it. I don't think this is how users would expect things to behave in general.

Perhaps this merely requires a documentation fix, but I'm not so sure. Many languages are vitally dependent on particular sublanguages and if I only specified the parent language in the subset I would NOT expect that to restrict the sublanguage subset - hence badly breaking the parent language.

Some examples:

  • xml/php
  • xml/vbscript_html
  • many of the templating languages that require xml
  • javascript/xml (for JSX support)

I'm not sure what the proper solution here is, but I wanted to add these notes.

@joshgoebel joshgoebel changed the title Specifying language subset not respected by sublanguage detection Discuss: Restricting language subset used for sublanguage detection Feb 18, 2020
@joshgoebel
Copy link
Member

the JavaScript may still be interpreted as ActionScript, for example.

Was that the real problem here? I wonder if we couldn't simply remove ActionScript completely (from the autodetect list for <script> tags in xml)... isn't flash pretty much dead now? No one else has commented on this issue so I'd be happy to lose actionscript as a sublanguage for script tags and close this out with that.

Thoughts?

CC @egor-rogov @marcoscaceres

@egor-rogov
Copy link
Collaborator

I wonder if we couldn't simply remove ActionScript completely (from the autodetect list for <script> tags in xml)... isn't flash pretty much dead now? No one else has commented on this issue so I'd be happy to lose actionscript as a sublanguage for script tags and close this out with that.

I think it can be a solution for this particular issue.

In general we lack a mechanism to limit sublanguages (outside from the grammar). I agree that

if I only specified the parent language in the subset I would NOT expect that to restrict the sublanguage subset

but could a separate restriction of sublanguage subset be convenient in some cases?

@joshgoebel
Copy link
Member

but could a separate restriction of sublanguage subset be convenient in some cases?

Perhaps. Though I think it'd be very hacky and still subject to the caveats I mentioned above (far more likely to break things than to fix things). If you're fine will removing ActionScript from the auto-detection for <script> then I say we do that for now, close this - and see if it ever comes up again or not.

If so perhaps when/if it does we'll have more information and perhaps that'll lead to better ideas.

@egor-rogov
Copy link
Collaborator

I'm fine with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants