highlightjs-gdscript
highlightjs-gdscript copied to clipboard
Made it work the way it works with other languages. (Edited module.exports)
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.
Were you using the definer function that the file exports? How were you trying to use it in your project exactly?
Were you using the
definerfunction 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.
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!
(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!
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?
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'...
@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"?
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.
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.