highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.31k stars 3.52k forks source link

bash doesn't include `zsh` alias despite docs saying so #3942

Closed vndroid closed 4 months ago

vndroid commented 6 months ago

Describe the issue

Example code:

<code class="lang-zsh">sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/Mojave /Applications/Install\ macOS\ Mojave.app --nointeraction</code>

According to the Official Docs:

Language Aliases Package
Bash bash, sh, zsh

I had already loaded the js and depends.

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" crossorigin="anonymous"
        referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/apache.min.js" crossorigin="anonymous"
        referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js" crossorigin="anonymous"
        referrerpolicy="no-referrer"></script>
...

Which language seems to have the issue?

Other languages seem to work well. Only the 'zsh' can not be rendered. What is wrong with it?

Java: worked CleanShot 2023-12-16 at 15 40 44@2x

Zsh: not work CleanShot 2023-12-16 at 15 41 02@2x

The console output:

WARN: Could not find the language 'zsh', did you forget to load/include a language module?
WARN: Falling back to no-highlight mode for this block. <code class=​"lang-zsh">​…​</code>​

Are you using highlight or highlightAuto?

Yes

Additional context

Do you need to add any other information?

joshgoebel commented 6 months ago

Looks like the docs are just wrong. That alias isn't mentioned in the source, so I'll leave this as an open issue. Should be easy for anyone wanting to make a PR to fix.

vndroid commented 6 months ago

Is it possible to add this alias manually? Otherwise, I need to make changes in multiple places in multiple documents. It is too complicated, the Best solution is for the project to add this alias as that documentation. I hope so.

joshgoebel commented 6 months ago

Is it possible to add this alias manually?

https://highlightjs.readthedocs.io/en/latest/api.html#registerlanguage

Sure, use registerLanguage and getLanguage... just get it, then re-register it with whatever aliases you like.

the Best solution is for the project to add this alias as that documentation.

Or remove the mention of it entirely... my worry is if we add zsh we then have to add a zillion other aliases to sh... we may want to do that, or not. I'm thinking on it.

vndroid commented 6 months ago

Okay, I see, but I would still suggest adding the common few sh aliases, such as 'sh', otherwise it should be named shell.

joshgoebel commented 6 months ago

https://github.com/highlightjs/highlight.js/blob/063876f86c53713a665de0b17b8d795ae5fce0a1/src/languages/bash.js#L371

sh is already an alias

vndroid commented 6 months ago

https://github.com/highlightjs/highlight.js/blob/063876f86c53713a665de0b17b8d795ae5fce0a1/src/languages/bash.js#L371

sh is already an alias

Sorry, I meant other common shells like sh, zsh, ash and so on. But it's unnecessary to include all the shells, just a few of the most commonly used ones.

noraj commented 4 months ago

This issue can be closed, it was fixed in #3945.

But as ZSH and BASH can have different syntaxes, I wonder if a separate config should be required or if it's similar enough 99% of the time.

joshgoebel commented 4 months ago

I'd say similar enough - for now at least.