highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(build) allow third-party packages to override default languages

Open Lysxia opened this issue 10 months ago • 8 comments

Changes

For example, I can define my own rust.js as a third-party package in extra/, then node tools/build.js rust will pick up my version instead of the default version.

Checklist

  • [x] ~~Added markup tests, or~~ they don't apply here because this just modifies the build script
  • [ ] Updated the changelog at CHANGES.md

Lysxia avatar Jan 22 '25 15:01 Lysxia

I think this is ok, since one would only ever do this on purpose - but I'm going to give it just a little more thought.

joshgoebel avatar Jan 23 '25 05:01 joshgoebel

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

1 file changed

Total change -1 B

View Changes
file base pr diff
highlight.min.js 8.23 KB 8.23 KB -1 B

github-actions[bot] avatar Jan 23 '25 05:01 github-actions[bot]

Which build or builds are you using? The current implementation really wasn't designed to deal with overlapping names at all. I worry any behavior here may be accidental so I need to take a closer look.

I'm fine with the idea of this change though (and it likely was my original intent - that 3rd party get added last, though I'm not sure I considered of dups).

joshgoebel avatar Jan 24 '25 13:01 joshgoebel

Ah, filter makes this work because it's scanning the list top-down to find matches (and it will find the first rust when there are many)... I think a better solution here would be to first call reverse on all languages in dependencies.js#filter so that the filter works from bottom to top - so that languages added later to the list win when there is a name match. (ie, it would feel like latter ones overwrite former, the behavior you'd see if we were using a hash, etc)

Could you give that a shot and update this PR?

Technically this would be a breaking change, but I may let it slide since this strikes me as very edge case.

joshgoebel avatar Jan 24 '25 13:01 joshgoebel

Changing filter makes sense to me. How this commit?

At the moment I'm using the browser build.

Lysxia avatar Jan 24 '25 16:01 Lysxia

Changing filter makes sense to me. How this commit?

Looks good. Safe to assume you tested and it also gets the job done?

joshgoebel avatar Jan 25 '25 03:01 joshgoebel

Indeed this works for me.

Lysxia avatar Jan 25 '25 13:01 Lysxia

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +3 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +1 B
es/highlight.min.js 8.19 KB 8.19 KB +1 B
highlight.min.js 8.23 KB 8.23 KB +1 B

github-actions[bot] avatar Jan 25 '25 13:01 github-actions[bot]