Doctave / doctave

A batteries-included developer documentation site generator
https://cli.doctave.com
MIT License
549 stars 33 forks source link

Expand supported languages in syntax highlighting #24

Closed begleynk closed 2 years ago

begleynk commented 2 years ago

Follow up from:

The creator of the issue wanted a way to override the prism.js version in order to get support for his language choice. While I don't feel Doctave should allow this by default (it goes against the idea of "batteries included"), the problem of not supporting their languages is a real problem that should be solved.

The issue is that prism.js grammars are non-trivial in size. Including all languages increases the bundle size, and given that most people will only require 1 or 2 languages, this seems wasteful.

I think there are 2 options to look into here:

Use the autoloader feature of Prism to load at runtime only the languages that are on the page. This does not decrease the final bundle size, but at least we don't have to transfer all grammars on every request.

Detect which languages are used on each page and dynamically include into the final bundle only the used languages. Seems complicated, but this would have the added benefit of reducing the deployed bundle size too.

begleynk commented 2 years ago

I think I'm going to go with the first option here - use the autoloader to lazily load the required grammars.

A futher optimization in the future can then be to detect the languages in the project and strip unused grammars from the final site bundle.