Skip to content

Vendor highlight.js in built-in themes (no more CDN) - #75

Merged
shenxianpeng merged 2 commits into
mainfrom
feature/vendor-highlightjs
Aug 3, 2026
Merged

shenxianpeng merged 2 commits into
mainfrom
feature/vendor-highlightjs

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Summary

bundle highlight.js 11.8.0 static assets locally in the built-in mkdocs and readthedocs themes instead of loading them from cdnjs.cloudflare.com.

This makes the built-in themes fully usable in offline / intranet / privacy-sensitive environments (upstream issues mkdocs#2171, mkdocs#3630). Google Analytics removal is a follow-up PR.

What changed

  • Vendored the complete highlight.js 11.8.0 minified distribution into both themes under highlight/ (mirrors the official CDN layout):
    • highlight.min.js (core, 23 common languages)
    • languages/*.min.js — all 192 language packs
    • styles/*.min.css + styles/base16/*.min.css — all 250 styles
    • LICENSE (BSD-3-Clause) and an upgrade-provenance README.md
  • Updated both base.html templates to reference the local files via the url filter. The hljs_style, hljs_style_dark, hljs_languages theme options keep working unchanged (including base16 styles like base16/apathy), and the #hljs-light/#hljs-dark ids used by darkmode.js are preserved.
  • Excluded the vendored highlight/ dirs from the jshint pre-commit hook (minified third-party files).
  • Docs: noted the bundled/local-serving behavior in choosing-your-theme.md.
  • Tests: regression test asserting no CDN references in theme templates and that default-referenced files exist.

Verification

  • uvx prek run -a passes
  • Full test suite: 747 tests OK
  • Built sites with both themes, custom hljs_style/hljs_style_dark/hljs_languages (incl. base16) — all assets resolve locally
  • Vendored JS verified in node: core loads, languages/rust.min.js registers, highlighting produces expected output
  • uv build wheel contains all 890 vendored files

Notes

Vendored files are copied to the output site (~2.5 MB, matching the repo's existing convention of shipping full static asset sets in themes).

Bundle the highlight.js 11.8.0 static assets locally in the mkdocs and
readthedocs themes instead of loading them from the cdnjs CDN, so syntax
highlighting works in offline, intranet and privacy-sensitive builds.

The vendored files mirror the CDN distribution layout (core library,
languages/ and styles/), so the hljs_style, hljs_style_dark and
hljs_languages theme options keep working unchanged, including base16
styles. A LICENSE and upgrade README are included with the vendored files.
@github-actions github-actions Bot added the enhancement New feature or request label Aug 3, 2026
@shenxianpeng shenxianpeng added this to the v1.8.0 milestone Aug 3, 2026
@shenxianpeng
shenxianpeng merged commit 75f47d5 into main Aug 3, 2026
23 checks passed
@shenxianpeng
shenxianpeng deleted the feature/vendor-highlightjs branch August 3, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant