bookdown/themes
Bookdown theme template with Bootswatch skins and Prism syntax highlighting. Configure TOC behavior in bookdown.json, pick Bootswatch/Prism styles via CSS_BOOTSWATCH and CSS_PRISM env vars, and optionally set a custom top menu logo with MENU_LOGO.
Installation:
bookdown is installed via npm (npm install -g bookdown).bookdown.json in your project root with the template:
{
"template": "bookdown/themes"
}
bookdown build to generate the book with default styles (cerulean for Bootswatch, ghcolors for Prism).First Use Case:
CSS_BOOTSWATCH=flatly CSS_PRISM=okaidia bookdown build
bookdown.json: Core configuration file for theme and TOC settings._book/ folder post-build to verify styling.Theming Workflow:
bookdown.json.bookdown serve to preview changes locally with:
CSS_BOOTSWATCH=superhero bookdown serve
TOC Customization:
"theme": {
"toc": {
"collapsibleFromLevel": 2 // Collapse sections from level 2+
}
}
bookdown’s built-in TOC plugins (e.g., bookdown-plugin-toc) for advanced features.Syntax Highlighting:
_book/assets/js/prism.js (e.g., for Laravel Blade templates):
Prism.languages.blade = Prism.languages.extend('markup', {
// Custom Blade syntax rules
});
# Build docs alongside Laravel assets
CSS_BOOTSWATCH=sandstone bookdown build && npm run dev
@include('bookdown.output.index')
laravel-mix to bundle Bookdown assets with Laravel’s frontend stack.Environment Variable Overrides:
CSS_BOOTSWATCH, CSS_PRISM) are not persisted in bookdown.json and must be set per-build..env file:
CSS_BOOTSWATCH=darkly
CSS_PRISM=twilight
Prism Language Support:
prism.js as shown in the workflows section or use a community plugin like prism-laravel.TOC Configuration Limits:
collapsibleFromLevel only accepts integers; no support for dynamic or conditional logic.bookdown’s afterBuild hook).Deprecated Package:
Styling Issues:
_book/assets/css/ folder post-build to verify loaded styles. Conflicts may arise if other CSS files override Bootswatch.cerulean class on <body>).Build Failures:
bookdown.json is valid JSON (use JSONLint).bookdown’s template system.Custom Themes:
_book/assets/css/custom.css):
@import "~bootswatch/cerulean/bootstrap.scss";
@import "~prismjs/themes/ghcolors.css";
/* Custom overrides */
body { font-family: 'Helvetica Neue', sans-serif; }
Dynamic Themes:
CSS_BOOTSWATCH based on user preferences (e.g., saved in the database):
// app/Http/Middleware/SetBookdownTheme.php
public function handle($request, Closure $next) {
if ($request->user()->prefers_dark_mode) {
putenv('CSS_BOOTSWATCH=darkly');
}
return $next($request);
}
Plugin Integration:
bookdown plugins. Example: Add a plugin to auto-generate a theme selector:
// bookdown-plugin-theme-selector.js
module.exports = function(bookdown) {
bookdown.on('afterBuild', () => {
// Inject theme selector HTML/JS
});
};
How can I help you explore Laravel packages today?