Skip to content
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

Automatically downloaded customised files #2404

Open
sixhobbits opened this issue May 25, 2020 · 5 comments
Open

Automatically downloaded customised files #2404

sixhobbits opened this issue May 25, 2020 · 5 comments

Comments

@sixhobbits
Copy link

Motivation
The feature where you can minify the code by selecting which languages you need support for before clicking 'download' is nice, but it would be great to do this automatically (e.g. to add to build tools).

Clicking the relevant checkboxes on the website generates a URL like https://prismjs.com/download.html#themes=prism-funky&languages=markup+css+clike+javascript+haskell+protobuf+purebasic

And we can evidently automatically create this URL. But then the "Download JS" and "Download CSS" buttons have to be pressed manually to trigger the actual download.

Description
And endpoint or similar where I could download the CSS and JS files from a customised URL directly e.g.

GET https://prismjs.com/download.html#themes=prism-funky&languages=markup+css+clike+javascript+haskell+protobuf+purebasic?download=js

GET https://prismjs.com/download.html#themes=prism-funky&languages=markup+css+clike+javascript+haskell+protobuf+purebasic?download=css

Alternatives
Visiting the website manually or trying to reverse engineer the javascript that triggers the download button.

@RunDevelopment
Copy link
Member

We statically serve your website via Github pages, so I don't think we could even do these get requests even if we wanted to.

The alternative doesn't seem nice either tho.

@sixhobbits
Copy link
Author

Thanks for the information. Is there a higher level overview of how the customization tool works? e.g. to help reproduce it locally? The JavaScript source seems a bit convoluted.

@RunDevelopment
Copy link
Member

Yeah, the script does a bunch of things...

The actual build process is quite easy. We just take the list of languages/plugins the user selected, pass it to getLoader, and get a sorted list of ids from that. We then concatenate all JS/CSS files (see the path attribute (each category has one)) of the sorted list of ids (in order) and that's the final output.

(It also has to include prism-core.js and the actual theme. We also have to handle that only some plugins have CSS files.)

That's the basics of what the build process is. Right now at least. It will be able to do more after #2162.

I also want to add that components.json, while required by getLoader, is not part of the public API and we might change the layout of the object at any time.

@siavashs
Copy link

It would be great to provide an npm task to produce the development/minified version based on a component/plugin list, maybe some logic from dependencies.js can be borrowed.

@RunDevelopment
Copy link
Member

Instead of an npm task, we could also do a simple CLI. This could be used like this:

npx prismjs bundle --languages=html,css,java --out-js=./prism.js --out-css=./prism.css

We could also use a configuration file (maybe similar to this format?) instead of CLI arguments or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants