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

Java syntax highlighting doesn't work #4845

Closed
stockiNail opened this issue May 25, 2021 · 13 comments · Fixed by #4849
Closed

Java syntax highlighting doesn't work #4845

stockiNail opened this issue May 25, 2021 · 13 comments · Fixed by #4849
Labels
bug An error in the Docusaurus core causing instability or issues with its execution external This issue is caused by an external dependency and not Docusaurus.

Comments

@stockiNail
Copy link

🐛 Bug Report

(A clear and concise description of what the bug is)

Have you read the Contributing Guidelines on issues?

YES

To Reproduce

To see that is not working, you can go to Docusaurus site (beta.0 or 1):

  1. Go to https://docusaurus.io/docs/next/markdown-features/code-blocks#multi-language-support-code-blocks
  2. Go down to see multiple language sample

Expected behavior

The expected behavior is to have the syntax highlighting on java source code.
I have the same problem in my project. When I was in version alpha.74, it worked, now on beta.0 doesn't work.

The bad thing is falling back to alpha.74, it doesn't work anymore....

Actual Behavior

Screenshot 2021-05-25 121850

Your Environment

@stockiNail stockiNail added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels May 25, 2021
@HonkingGoose
Copy link
Contributor

You'll need to manually setup Java syntax highlighting.

Quote from the Docusaurus docs (emphasis mine):

Some popular languages like Java, C#, or PHP are not enabled by default.

Read https://docusaurus.io/docs/markdown-features/code-blocks#syntax-highlighting to learn how to setup syntax highlighting. 😉

@stockiNail
Copy link
Author

@HonkingGoose thank you but I have already done it (I have created another issue about that some days ago #4720).
As you can see, this is the config of my project:

https://github.com/pepstock-org/Charba-Wiki/blob/fa8ed9e34e19f11c0cb2e8ff455e384835efcf58/docusaurus.config.js#L25-L28

    prism: {
       additionalLanguages: ['java'],
       theme: require('prism-react-renderer/themes/github'),
    },

I have published here some days ago based on alpha.74 and works:

Screenshot 2021-05-25 125303

Now, after the upgrade to beta.0, this is the result:

Screenshot 2021-05-25 125227

@HonkingGoose
Copy link
Contributor

@HonkingGoose thank you but I have already done it (I have created another issue about that some days ago #4720).

Whoops, I did not see that you opened that prior issue, sorry! 😄

@stockiNail
Copy link
Author

stockiNail commented May 25, 2021

Created also a sandbox where https://codesandbox.io/s/eloquent-yonath-7spwh?file=/docs/intro.md
and it works here.... uhm....

EDIT: removing theme: require('prism-react-renderer/themes/github'), and using default, works also locally.

@Josh-Cena
Copy link
Collaborator

Is the highlight only broken when using the github theme? It could be because of the latest prism-react-renderer update...

@lex111
Copy link
Contributor

lex111 commented May 25, 2021

This is actually because the GitHub theme changed in prism-react-renderer (see FormidableLabs/prism-react-renderer#115 for more details).

However you can again return to previous syntax highlighting -- for this in src directory of your website you need to create new file (eg. github.js) with the following content , and then in prism field of config file specify path to this file, something like that:

prism: require.resolve('./src/github.js')

@stockiNail
Copy link
Author

@Josh-Cena @lex111 THANK YOUU! Let me test it and then I'm gonna close the issue.

@Josh-Cena
Copy link
Collaborator

Interesting because the Docusaurus site is also broken 😅 We may need to fix that

@stockiNail
Copy link
Author

Interesting because the Docusaurus site is also broken 😅 We may need to fix that

yes, for this reason I thought it was an issue.

@stockiNail
Copy link
Author

prism: require.resolve('./src/github.js')

Does not work.

@lex111
Copy link
Contributor

lex111 commented May 25, 2021

Forgot to mention that you need to use the CommonJS format, so just copy-paste this gist to make things work.

@stockiNail
Copy link
Author

stockiNail commented May 26, 2021

@lex111 I tested with last gist you gave me and it WORKS!!! Thank you!

Only 1 thing, to correct your post. The config (beta.0) is the following (assuming to store github theme in ./src/github.js):

  prism: {
    additionalLanguages: ['java'],
    theme: require('./src/github.js'),
  },

@Josh-Cena Josh-Cena added external This issue is caused by an external dependency and not Docusaurus. and removed status: needs triage This issue has not been triaged by maintainers labels Feb 25, 2022
@kebetsi
Copy link

kebetsi commented Sep 30, 2024

You only need to add additionalLanguages: ['java'] to themeConfig:prism with docusaurus v3.5.2. There is an entry theme: prismThemes.github, by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution external This issue is caused by an external dependency and not Docusaurus.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants