highlight.js
highlight.js copied to clipboard
(build) allow third-party packages to override default languages
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
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.
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 |
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).
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.
Changing filter makes sense to me. How this commit?
At the moment I'm using the browser build.
Changing filter makes sense to me. How this commit?
Looks good. Safe to assume you tested and it also gets the job done?
Indeed this works for me.
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 |