Skip to content

Made it work the way it works with other languages. (Edited module.exports) #10

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Pacifist-Penguin
Copy link

@Pacifist-Penguin Pacifist-Penguin commented Oct 11, 2021

Hi! Yesterday I tried to get it to work in my project but couldn't. It took me a while and I ended up making these changes. Sorry if I only made things worse.

@Pacifist-Penguin Pacifist-Penguin changed the title I'm not sure if it will be hlpfull I'm not sure if it will be helpfull Oct 11, 2021
@Pacifist-Penguin Pacifist-Penguin changed the title I'm not sure if it will be helpfull Made it work the way it works with other languages. (Edited module.exports) Oct 11, 2021
@joshgoebel
Copy link
Member

Were you using the definer function that the file exports? How were you trying to use it in your project exactly?

@Pacifist-Penguin
Copy link
Author

Were you using the definer function that the file exports? How were you trying to use it in your project exactly?

Hi. I wasnt able to use definer function due to lack of knowledge. Since there's no instructions on how to use this specific language pack i was trying to import it as a module, following this instructions: https://highlightjs.org/usage/

import hljs from 'highlight.js/lib/core';
import gdscript from './includes/gdscript.js'; //I've imported it this way since i couldnt find npm package for this language
hljs.registerLanguage('gdscript', gdscript);

So I decided to see how this is implemented. When comparing gdscript.js with other languages that, unlike GDScript, come bundled with highlight.js (specifically HTML, CSS, and JS), i noticed that the module is exported differently. For this reason, i decided to edit it, so i could import it the way i did it to highlight HTML/CSS/JS. I wasnt able to find how to use definer function either.

@joshgoebel
Copy link
Member

Yeah, you'd have to understand the JS import/require system and actually use the code as written. gdscript should probably either apply this PR [my recommendation] (because it's the convention used by almost all other 3rd party grammars) or if not, should add documentation (specific examples of how to import the library for Node.js, etc).

Thanks for the contribution!

@Pacifist-Penguin
Copy link
Author

(because it's the convention used by almost all other 3rd party grammars)

Exactly! IMHO the way of importing modules should be consistent across grammars.
Hope this was helpful and I wasn't wasting your time.

Thank you for the attention!

@dsaltares
Copy link

I tried to follow the official guide to add extra languages here https://github.com/highlightjs/highlight.js/blob/main/extra/3RD_PARTY_QUICK_START.md and highlight.js fails to build with the current GDScript support from this repo. The PR indeed fixes it.

Perhaps a new highlight.js major version broke it?

@joshgoebel
Copy link
Member

Perhaps a new highlight.js major version broke it?

Yes, we purposely don't support shims and such things anymore - where-as we used to make a concession to these early packaging variants before we had standardized on the 'one true way'...

@dsaltares
Copy link

@joshgoebel I am not familiar with highlight.js packaging but, what is the "one true way"? I assume that their official guide is the "one true way"?

@joshgoebel
Copy link
Member

what is the "one true way"? I assume that their official guide is the "one true way"?

Yes. Source is an ES6 module, builds are done inside highlight.js checkout, distributable go in dist, etc... no weird shims, etc... the build process generates ES6 and CJS "CDN-ready" distributables.

@Calinou
Copy link
Contributor

Calinou commented Dec 28, 2023

Should this PR be merged now? Reading by the above comments, it seems this highlighting plugin doesn't work with the latest highlight.js release.

@accidentallyc
Copy link

accidentallyc commented Nov 16, 2024

Was going to try adding the Gdscript4 changes to the highlighter and essentially ended up with the same solution as this pr.

This is from my local

before

2024-11-16_20-14-18

after

after

highlight using min code i generated locally
image


i think the issue here is the minified code

hey @Pacifist-Penguin
was this built using node ./tools/build.js -t cdn?
inspecting it - it just looks like a minified javascript file so you cant run it on the browser.

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.

5 participants