club-1 / flarum-ext-server-side-highlight
Server-side code highlighting with cached results.
Fund package maintenance!
n-peugnet
Installs: 243
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 4
Type:flarum-extension
Requires
- php: >=7.3
- flarum/core: ^1.2.0
- scrivo/highlight.php: ^9.18
Requires (Dev)
- flarum/phpstan: ^1.8
- flarum/testing: ^1.0.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.2
Suggests
- club-1/flarum-ext-chore-commands: Allows to reparse all the comment posts with the new formatter's configuration
README
A Flarum extension. Server-side code highlighting with cached results.
For each code block of the posts, a hash is computed while parsing them, then on render the code highlighting is done in the backend once, and stored in the cache for future renderings.
It provides the following advantages:
- The highlighting is done on the server so it is not up to the clients to do it.
- The server uses the cache to save highlighted blocks to only do the processing once.
- It works without any JS so even on the worst web browser the highlight will be there and there is no delay before the highlighting is applied.
- The theme adapts itself to the "dark mode" setting of Flarum.
- It works even with BBCode extension disabled.
- Admins can choose the highlight theme for both "Light" and "Dark" Flarum variants.
- Admins can download highlight themes with
highlight:download
Flarum console command. - It is compatible with
fof/nightmode
by switching the highlight theme accordingly.
Client-side highlighting is still used, but only for the post preview.
Installation
Install with composer:
composer require club-1/flarum-ext-server-side-highlight:"*"
Recommendation
This extension alone does not apply the formatting changes to previously posted comments. I you want to reparse all the comments posts of the database it is recommended to install and enable the club-1/flarum-ext-chore-commands
extension and use its chore:reparse
command.
Updating
composer update club-1/flarum-ext-server-side-highlight:"*"
php flarum migrate
php flarum cache:clear
php flarum assets:publish
Acknowledgement
This extension is based on the following libraries: