vendor_mathjax.py 903 B

123456789101112131415
  1. from pathlib import Path
  2. import urllib.request,tarfile,io,json
  3. ROOT=Path(__file__).resolve().parents[1]
  4. OUT=ROOT/'课件'/'EnterpriseKB_RAG_V1.0讲义'/'assets'/'mathjax'
  5. if not (OUT/'tex-mml-chtml.js').exists():
  6. raw=urllib.request.urlopen('https://registry.npmjs.org/mathjax/-/mathjax-3.2.2.tgz',timeout=90).read()
  7. with tarfile.open(fileobj=io.BytesIO(raw),mode='r:gz') as archive:
  8. for entry in archive.getmembers():
  9. if entry.isfile() and entry.name.startswith('package/es5/'):
  10. rel=Path(entry.name).relative_to('package/es5')
  11. if '..' in rel.parts:raise ValueError('Invalid archive path')
  12. p=OUT/rel;p.parent.mkdir(parents=True,exist_ok=True);p.write_bytes(archive.extractfile(entry).read())
  13. license=archive.extractfile('package/LICENSE').read();(OUT/'LICENSE').write_bytes(license)
  14. print('MathJax 3.2.2 vendored for offline formulas')
  15. else:print('Local MathJax already available')