highlightjs-gdscript icon indicating copy to clipboard operation
highlightjs-gdscript copied to clipboard

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

Open Pacifist-Penguin opened this issue 4 years ago • 10 comments

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 avatar Oct 11 '21 20:10 Pacifist-Penguin

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

joshgoebel avatar Oct 12 '21 05:10 joshgoebel

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.

Pacifist-Penguin avatar Oct 12 '21 11:10 Pacifist-Penguin

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!

joshgoebel avatar Oct 12 '21 11:10 joshgoebel

(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!

Pacifist-Penguin avatar Oct 12 '21 15:10 Pacifist-Penguin

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?

dsaltares avatar Jan 24 '22 08:01 dsaltares

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 avatar Jan 24 '22 08:01 joshgoebel

@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"?

dsaltares avatar Jan 24 '22 08:01 dsaltares

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.

joshgoebel avatar Jan 24 '22 13:01 joshgoebel

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.

Calinou avatar Dec 28 '23 18:12 Calinou