mkdocs-katex-ssr 0.1.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocs_katex_ssr/plugin.py +1 -1
- mkdocs_katex_ssr-1.0.2.dist-info/METADATA +126 -0
- mkdocs_katex_ssr-1.0.2.dist-info/RECORD +8 -0
- mkdocs_katex_ssr-0.1.0.dist-info/METADATA +0 -10
- mkdocs_katex_ssr-0.1.0.dist-info/RECORD +0 -8
- {mkdocs_katex_ssr-0.1.0.dist-info → mkdocs_katex_ssr-1.0.2.dist-info}/WHEEL +0 -0
- {mkdocs_katex_ssr-0.1.0.dist-info → mkdocs_katex_ssr-1.0.2.dist-info}/entry_points.txt +0 -0
- {mkdocs_katex_ssr-0.1.0.dist-info → mkdocs_katex_ssr-1.0.2.dist-info}/licenses/LICENSE +0 -0
- {mkdocs_katex_ssr-0.1.0.dist-info → mkdocs_katex_ssr-1.0.2.dist-info}/top_level.txt +0 -0
mkdocs_katex_ssr/plugin.py
CHANGED
|
@@ -150,7 +150,7 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
150
150
|
|
|
151
151
|
result = json.loads(response_line.decode('utf-8'))
|
|
152
152
|
if result.get('status') == 'success':
|
|
153
|
-
return result.get('html')
|
|
153
|
+
return '<div class="arithmatex">{html}</div>'.format(html=result.get('html'))
|
|
154
154
|
else:
|
|
155
155
|
print(f"KaTeX error: {result.get('message')}")
|
|
156
156
|
except Exception as e:
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mkdocs-katex-ssr
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A MkDocs plugin for server-side rendering of KaTeX math.
|
|
5
|
+
Author-email: RainPPR <2125773894@qq.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://raineblog.dpdns.org/mkdocs-katex-ssr/
|
|
8
|
+
Project-URL: Documentation, https://raineblog.dpdns.org/mkdocs-katex-ssr/configuration/
|
|
9
|
+
Project-URL: Repository, https://github.com/raineblog/mkdocs-katex-ssr
|
|
10
|
+
Project-URL: Issues, https://github.com/raineblog/mkdocs-katex-ssr/issues
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: mkdocs>=1.1.0
|
|
14
|
+
Requires-Dist: beautifulsoup4>=4.9.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# MkDocs KaTeX SSR Plugin
|
|
18
|
+
|
|
19
|
+
A MkDocs plugin that renders LaTeX math on the server side using [KaTeX](https://katex.org/), offering faster load times, layout stability, and optional offline support.
|
|
20
|
+
|
|
21
|
+
> [!NOTE]
|
|
22
|
+
> **Maintenance Philosophy**: This project is self-maintained. I welcome bug reports and corrections, but please note that I may not have the bandwidth to accept significant feature requests or major functional additions. Pull requests for bug fixes are appreciated.
|
|
23
|
+
>
|
|
24
|
+
> *This project's code and documentation were generated by Antigravity (Google DeepMind) and verified by the maintainer.*
|
|
25
|
+
|
|
26
|
+
## Why Server-Side Rendering (SSR)?
|
|
27
|
+
|
|
28
|
+
Traditional client-side rendering relies on JavaScript in the browser to convert LaTeX strings (e.g., `$\sqrt{a^2 + b^2}$`) into HTML. This can lead to:
|
|
29
|
+
|
|
30
|
+
- **Layout Shift**: Content jumps as math loads.
|
|
31
|
+
- **Slower Performance**: The browser must download and parse the KaTeX library before rendering.
|
|
32
|
+
- **Dependency**: Requires client-side JavaScript execution.
|
|
33
|
+
|
|
34
|
+
**MkDocs KaTeX SSR** pre-renders all math during the `mkdocs build` process using a local Node.js process. The resulting HTML contains ready-to-view markup.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **High Performance**: Uses a persistent Node.js process to render equations efficiently without spawning a new process for every item.
|
|
39
|
+
- **Offline Support**: Optional "Offline Mode" copies all necessary CSS, fonts, and scripts to your site directory, removing external CDN dependencies.
|
|
40
|
+
- **Smart Asset Management**: Separate configuration for server-side processing scripts (like `mhchem`) and client-side interactive scripts (like `copy-tex`).
|
|
41
|
+
- **Clean Output**: Aggressive warning suppression for a quieter build log.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
### Prerequisites
|
|
46
|
+
|
|
47
|
+
- **Node.js**: Must be installed and available in your system PATH.
|
|
48
|
+
- **Python**: 3.8+
|
|
49
|
+
|
|
50
|
+
### Install Plugin
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install mkdocs-katex-ssr
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
Add the plugin to your `mkdocs.yml`:
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
markdown_extensions:
|
|
62
|
+
- pymdownx.arithmatex:
|
|
63
|
+
generic: true
|
|
64
|
+
|
|
65
|
+
plugins:
|
|
66
|
+
- katex-ssr:
|
|
67
|
+
# --- Basic Configuration ---
|
|
68
|
+
katex_dist: "https://cdn.jsdelivr.net/npm/katex@latest/dist/"
|
|
69
|
+
add_katex_css: true
|
|
70
|
+
katex_css_filename: "katex-swap.min.css" # Use swap version for better font-display behavior
|
|
71
|
+
|
|
72
|
+
# --- Script Loading ---
|
|
73
|
+
# Scripts needed for rendering (Server-Side). e.g., chemical formulas.
|
|
74
|
+
# These are NOT sent to the browser.
|
|
75
|
+
ssr_contribs:
|
|
76
|
+
- mhchem
|
|
77
|
+
|
|
78
|
+
# Scripts needed for interaction (Client-Side). e.g., clipboard copy.
|
|
79
|
+
# These ARE injected into the HTML.
|
|
80
|
+
client_scripts:
|
|
81
|
+
- copy-tex
|
|
82
|
+
|
|
83
|
+
# --- KaTeX Options ---
|
|
84
|
+
katex_options:
|
|
85
|
+
macros:
|
|
86
|
+
"\\RR": "\\mathbb{R}"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Offline Mode (Self-Contained)
|
|
90
|
+
|
|
91
|
+
If you need your documentation to work without an internet connection (or just want to host everything yourself), enable `embed_assets`.
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
plugins:
|
|
95
|
+
- katex-ssr:
|
|
96
|
+
embed_assets: true
|
|
97
|
+
# You can specify a local path if auto-detection fails
|
|
98
|
+
# katex_dist: "./node_modules/katex/dist/"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**What this does:**
|
|
102
|
+
|
|
103
|
+
1. **Copies Files**: It copies `katex.min.css` (or your chosen filename), the `fonts/` directory, and any specified `client_scripts` from your local `node_modules` to `site/assets/katex`.
|
|
104
|
+
2. **Relative Linking**: It updates all HTML citations to point to these local files using correct relative paths (e.g., `../assets/katex/katex.min.css`).
|
|
105
|
+
|
|
106
|
+
## Advanced Configuration Options
|
|
107
|
+
|
|
108
|
+
| Option | Type | Default | Description |
|
|
109
|
+
| :--- | :--- | :--- | :--- |
|
|
110
|
+
| `katex_dist` | str | jsDelivr | Base URL for CDN, or local file path to KaTeX distribution. |
|
|
111
|
+
| `add_katex_css` | bool | `true` | Whether to inject the CSS link tag. |
|
|
112
|
+
| `katex_css_filename` | str | `katex.min.css` | The specific CSS file to load. `katex-swap.min.css` is recommended. |
|
|
113
|
+
| `embed_assets` | bool | `false` | If true, copies assets to output dir and links locally. |
|
|
114
|
+
| `ssr_contribs` | list | `[]` | List of KaTeX `contrib` libraries to load in the Node.js renderer (e.g., `mhchem`). |
|
|
115
|
+
| `client_scripts` | list | `[]` | List of KaTeX `contrib` libraries to load in the browser (e.g., `copy-tex`). |
|
|
116
|
+
| `copy_assets_to` | str | `assets/katex` | Destination directory for copied assets (relative to site_dir). |
|
|
117
|
+
| `katex_options` | dict | `{}` | Standard options passed to `katex.renderToString` (macros, etc.). |
|
|
118
|
+
|
|
119
|
+
## Troubleshooting
|
|
120
|
+
|
|
121
|
+
- **`katex` module not found**: Ensure `npm install katex` (or `pnpm`/`yarn`) has been run in your project root, or specific the path via `katex_dist`.
|
|
122
|
+
- **Node.js error**: The plugin requires `node` to be in your PATH. On Windows, ensure you can run `node --version` in your terminal.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
mkdocs_katex_ssr/plugin.py,sha256=hfbYOK9Fz0hR-OXut-VpgNJ-InJMwpNrwMvTg3-kJpo,11125
|
|
2
|
+
mkdocs_katex_ssr/renderer.js,sha256=15lIck7GXZHiAza9IpnSbu9HmeklaDp_zubetQQowkU,1967
|
|
3
|
+
mkdocs_katex_ssr-1.0.2.dist-info/licenses/LICENSE,sha256=Bea4m1bAyMhuJT5bCGl76QfpKatJarfMzl9vcrdXRgQ,1064
|
|
4
|
+
mkdocs_katex_ssr-1.0.2.dist-info/METADATA,sha256=6FA_aL4s8tLEbECU0yVFEody4hcv5gG_Y0c6ZHpp8Nc,5398
|
|
5
|
+
mkdocs_katex_ssr-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
mkdocs_katex_ssr-1.0.2.dist-info/entry_points.txt,sha256=l3PrOPi_1AqGLse2BTZVz2SB8rn3I4NRVI-wDUbIHVg,68
|
|
7
|
+
mkdocs_katex_ssr-1.0.2.dist-info/top_level.txt,sha256=FdfQyPUx4r9kgiqTW4da0TPUdBbOda_0PXjVkfGmsgs,17
|
|
8
|
+
mkdocs_katex_ssr-1.0.2.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: mkdocs-katex-ssr
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: A MkDocs plugin for server-side rendering of KaTeX math.
|
|
5
|
-
Author-email: Your Name <your.email@example.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Dist: mkdocs>=1.1.0
|
|
9
|
-
Requires-Dist: beautifulsoup4>=4.9.0
|
|
10
|
-
Dynamic: license-file
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
mkdocs_katex_ssr/plugin.py,sha256=9HcxJv4Q1SfWMmnNvWwpw0oaJCuCFCrbhBM5WMgp4vc,11073
|
|
2
|
-
mkdocs_katex_ssr/renderer.js,sha256=15lIck7GXZHiAza9IpnSbu9HmeklaDp_zubetQQowkU,1967
|
|
3
|
-
mkdocs_katex_ssr-0.1.0.dist-info/licenses/LICENSE,sha256=Bea4m1bAyMhuJT5bCGl76QfpKatJarfMzl9vcrdXRgQ,1064
|
|
4
|
-
mkdocs_katex_ssr-0.1.0.dist-info/METADATA,sha256=UHxjskpQ8Zb0smgBOE0dIOeWvlojZkQ3BlQ0Sz8OS0Q,298
|
|
5
|
-
mkdocs_katex_ssr-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
mkdocs_katex_ssr-0.1.0.dist-info/entry_points.txt,sha256=l3PrOPi_1AqGLse2BTZVz2SB8rn3I4NRVI-wDUbIHVg,68
|
|
7
|
-
mkdocs_katex_ssr-0.1.0.dist-info/top_level.txt,sha256=FdfQyPUx4r9kgiqTW4da0TPUdBbOda_0PXjVkfGmsgs,17
|
|
8
|
-
mkdocs_katex_ssr-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|