mkdocs-katex-ssr 1.0.5__tar.gz → 1.0.6__tar.gz
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-1.0.5 → mkdocs_katex_ssr-1.0.6}/PKG-INFO +4 -1
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/README.md +3 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr/plugin.py +26 -9
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/PKG-INFO +4 -1
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/pyproject.toml +1 -1
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/LICENSE +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr/renderer.js +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/SOURCES.txt +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/dependency_links.txt +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/entry_points.txt +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/requires.txt +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/top_level.txt +0 -0
- {mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-katex-ssr
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.6
|
|
4
4
|
Summary: A MkDocs plugin for server-side rendering of KaTeX math.
|
|
5
5
|
Author-email: RainPPR <2125773894@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -38,6 +38,7 @@ Traditional client-side rendering relies on JavaScript in the browser to convert
|
|
|
38
38
|
- **High Performance**: Uses a persistent Node.js process to render equations efficiently without spawning a new process for every item.
|
|
39
39
|
- **Offline Support**: Optional "Offline Mode" copies all necessary CSS, fonts, and scripts to your site directory, removing external CDN dependencies.
|
|
40
40
|
- **Smart Asset Management**: Separate configuration for server-side processing scripts (like `mhchem`) and client-side interactive scripts (like `copy-tex`).
|
|
41
|
+
- **Performance Monitoring**: Detailed build-time logging for each page tracking formula counts, cache hits, and processing speeds.
|
|
41
42
|
- **Clean Output**: Aggressive warning suppression for a quieter build log.
|
|
42
43
|
|
|
43
44
|
## Installation
|
|
@@ -65,6 +66,7 @@ markdown_extensions:
|
|
|
65
66
|
plugins:
|
|
66
67
|
- katex-ssr:
|
|
67
68
|
# --- Basic Configuration ---
|
|
69
|
+
verbose: true # Enable build logs for each page
|
|
68
70
|
katex_dist: "https://cdn.jsdelivr.net/npm/katex@latest/dist/"
|
|
69
71
|
add_katex_css: true
|
|
70
72
|
katex_css_filename: "katex-swap.min.css" # Use swap version for better font-display behavior
|
|
@@ -107,6 +109,7 @@ plugins:
|
|
|
107
109
|
|
|
108
110
|
| Option | Type | Default | Description |
|
|
109
111
|
| :--- | :--- | :--- | :--- |
|
|
112
|
+
| `verbose` | bool | `false` | If true, logs the number of formulas, cache hits, and time spent processing each page. |
|
|
110
113
|
| `katex_dist` | str | jsDelivr | Base URL for CDN, or local file path to KaTeX distribution. |
|
|
111
114
|
| `add_katex_css` | bool | `true` | Whether to inject the CSS link tag. |
|
|
112
115
|
| `katex_css_filename` | str | `katex.min.css` | The specific CSS file to load. `katex-swap.min.css` is recommended. |
|
|
@@ -22,6 +22,7 @@ Traditional client-side rendering relies on JavaScript in the browser to convert
|
|
|
22
22
|
- **High Performance**: Uses a persistent Node.js process to render equations efficiently without spawning a new process for every item.
|
|
23
23
|
- **Offline Support**: Optional "Offline Mode" copies all necessary CSS, fonts, and scripts to your site directory, removing external CDN dependencies.
|
|
24
24
|
- **Smart Asset Management**: Separate configuration for server-side processing scripts (like `mhchem`) and client-side interactive scripts (like `copy-tex`).
|
|
25
|
+
- **Performance Monitoring**: Detailed build-time logging for each page tracking formula counts, cache hits, and processing speeds.
|
|
25
26
|
- **Clean Output**: Aggressive warning suppression for a quieter build log.
|
|
26
27
|
|
|
27
28
|
## Installation
|
|
@@ -49,6 +50,7 @@ markdown_extensions:
|
|
|
49
50
|
plugins:
|
|
50
51
|
- katex-ssr:
|
|
51
52
|
# --- Basic Configuration ---
|
|
53
|
+
verbose: true # Enable build logs for each page
|
|
52
54
|
katex_dist: "https://cdn.jsdelivr.net/npm/katex@latest/dist/"
|
|
53
55
|
add_katex_css: true
|
|
54
56
|
katex_css_filename: "katex-swap.min.css" # Use swap version for better font-display behavior
|
|
@@ -91,6 +93,7 @@ plugins:
|
|
|
91
93
|
|
|
92
94
|
| Option | Type | Default | Description |
|
|
93
95
|
| :--- | :--- | :--- | :--- |
|
|
96
|
+
| `verbose` | bool | `false` | If true, logs the number of formulas, cache hits, and time spent processing each page. |
|
|
94
97
|
| `katex_dist` | str | jsDelivr | Base URL for CDN, or local file path to KaTeX distribution. |
|
|
95
98
|
| `add_katex_css` | bool | `true` | Whether to inject the CSS link tag. |
|
|
96
99
|
| `katex_css_filename` | str | `katex.min.css` | The specific CSS file to load. `katex-swap.min.css` is recommended. |
|
|
@@ -7,6 +7,7 @@ import threading
|
|
|
7
7
|
import warnings
|
|
8
8
|
import logging
|
|
9
9
|
import shutil
|
|
10
|
+
import time
|
|
10
11
|
from mkdocs.plugins import BasePlugin
|
|
11
12
|
from mkdocs.config import config_options
|
|
12
13
|
from mkdocs.utils import get_relative_url
|
|
@@ -30,8 +31,11 @@ for logger_name in ["mkdocs", "mkdocs.plugins", "py.warnings", ""]:
|
|
|
30
31
|
|
|
31
32
|
logging.captureWarnings(True)
|
|
32
33
|
|
|
34
|
+
log = logging.getLogger('mkdocs.plugins.katex-ssr')
|
|
35
|
+
|
|
33
36
|
class KatexSsrPlugin(BasePlugin):
|
|
34
37
|
config_scheme = (
|
|
38
|
+
('verbose', config_options.Type(bool, default=False)),
|
|
35
39
|
('katex_dist', config_options.Type(str, default='https://cdn.jsdelivr.net/npm/katex@latest/dist/')),
|
|
36
40
|
('katex_css_filename', config_options.Type(str, default='katex.min.css')),
|
|
37
41
|
('add_katex_css', config_options.Type(bool, default=True)),
|
|
@@ -159,12 +163,12 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
159
163
|
cursor = self.db_conn.execute("SELECT html FROM katex_cache WHERE hash=?", (cache_key,))
|
|
160
164
|
row = cursor.fetchone()
|
|
161
165
|
if row:
|
|
162
|
-
return row[0]
|
|
166
|
+
return row[0], True
|
|
163
167
|
except Exception as e:
|
|
164
168
|
print(f"Error reading cache: {e}")
|
|
165
169
|
|
|
166
170
|
if not self.process:
|
|
167
|
-
return None
|
|
171
|
+
return None, False
|
|
168
172
|
|
|
169
173
|
with self.lock:
|
|
170
174
|
payload = {
|
|
@@ -180,7 +184,7 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
180
184
|
|
|
181
185
|
response_line = self.process.stdout.readline()
|
|
182
186
|
if not response_line:
|
|
183
|
-
return None
|
|
187
|
+
return None, False
|
|
184
188
|
|
|
185
189
|
result = json.loads(response_line.decode('utf-8'))
|
|
186
190
|
if result.get('status') == 'success':
|
|
@@ -195,7 +199,7 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
195
199
|
)
|
|
196
200
|
except Exception as e:
|
|
197
201
|
print(f"Error saving to cache: {e}")
|
|
198
|
-
return html
|
|
202
|
+
return html, False
|
|
199
203
|
else:
|
|
200
204
|
print(f"KaTeX error: {result.get('message')}")
|
|
201
205
|
except Exception as e:
|
|
@@ -203,12 +207,16 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
203
207
|
stderr_content = self.process.stderr.read()
|
|
204
208
|
if stderr_content:
|
|
205
209
|
print(f"Renderer died with: {stderr_content.decode('utf-8', errors='replace')}")
|
|
206
|
-
return None
|
|
210
|
+
return None, False
|
|
207
211
|
|
|
208
212
|
def on_post_page(self, output, page, config):
|
|
209
213
|
if not self.process:
|
|
210
214
|
return output
|
|
211
215
|
|
|
216
|
+
start_time = time.time()
|
|
217
|
+
formula_count = 0
|
|
218
|
+
cache_count = 0
|
|
219
|
+
|
|
212
220
|
soup = BeautifulSoup(output, 'html.parser')
|
|
213
221
|
math_elements = soup.find_all(class_='arithmatex')
|
|
214
222
|
for el in math_elements:
|
|
@@ -228,11 +236,20 @@ class KatexSsrPlugin(BasePlugin):
|
|
|
228
236
|
else:
|
|
229
237
|
latex = content
|
|
230
238
|
|
|
231
|
-
rendered_html = self._render_latex(latex, display_mode)
|
|
232
|
-
|
|
239
|
+
rendered_html, from_cache = self._render_latex(latex, display_mode)
|
|
240
|
+
|
|
241
|
+
if rendered_html:
|
|
242
|
+
formula_count += 1
|
|
243
|
+
if from_cache:
|
|
244
|
+
cache_count += 1
|
|
245
|
+
|
|
246
|
+
new_soup = BeautifulSoup(rendered_html, 'html.parser')
|
|
247
|
+
el.clear()
|
|
248
|
+
el.append(new_soup)
|
|
233
249
|
|
|
234
|
-
|
|
235
|
-
|
|
250
|
+
if self.config['verbose']:
|
|
251
|
+
duration = (time.time() - start_time) * 1000
|
|
252
|
+
log.info(f"Katex-SSR processed {page.file.src_path} in {duration:.2f}ms: {formula_count} formulas ({cache_count} cached)")
|
|
236
253
|
|
|
237
254
|
# Assets Injection
|
|
238
255
|
css_file = self.config['katex_css_filename']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-katex-ssr
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.6
|
|
4
4
|
Summary: A MkDocs plugin for server-side rendering of KaTeX math.
|
|
5
5
|
Author-email: RainPPR <2125773894@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -38,6 +38,7 @@ Traditional client-side rendering relies on JavaScript in the browser to convert
|
|
|
38
38
|
- **High Performance**: Uses a persistent Node.js process to render equations efficiently without spawning a new process for every item.
|
|
39
39
|
- **Offline Support**: Optional "Offline Mode" copies all necessary CSS, fonts, and scripts to your site directory, removing external CDN dependencies.
|
|
40
40
|
- **Smart Asset Management**: Separate configuration for server-side processing scripts (like `mhchem`) and client-side interactive scripts (like `copy-tex`).
|
|
41
|
+
- **Performance Monitoring**: Detailed build-time logging for each page tracking formula counts, cache hits, and processing speeds.
|
|
41
42
|
- **Clean Output**: Aggressive warning suppression for a quieter build log.
|
|
42
43
|
|
|
43
44
|
## Installation
|
|
@@ -65,6 +66,7 @@ markdown_extensions:
|
|
|
65
66
|
plugins:
|
|
66
67
|
- katex-ssr:
|
|
67
68
|
# --- Basic Configuration ---
|
|
69
|
+
verbose: true # Enable build logs for each page
|
|
68
70
|
katex_dist: "https://cdn.jsdelivr.net/npm/katex@latest/dist/"
|
|
69
71
|
add_katex_css: true
|
|
70
72
|
katex_css_filename: "katex-swap.min.css" # Use swap version for better font-display behavior
|
|
@@ -107,6 +109,7 @@ plugins:
|
|
|
107
109
|
|
|
108
110
|
| Option | Type | Default | Description |
|
|
109
111
|
| :--- | :--- | :--- | :--- |
|
|
112
|
+
| `verbose` | bool | `false` | If true, logs the number of formulas, cache hits, and time spent processing each page. |
|
|
110
113
|
| `katex_dist` | str | jsDelivr | Base URL for CDN, or local file path to KaTeX distribution. |
|
|
111
114
|
| `add_katex_css` | bool | `true` | Whether to inject the CSS link tag. |
|
|
112
115
|
| `katex_css_filename` | str | `katex.min.css` | The specific CSS file to load. `katex-swap.min.css` is recommended. |
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{mkdocs_katex_ssr-1.0.5 → mkdocs_katex_ssr-1.0.6}/mkdocs_katex_ssr.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|