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