mkdocs-katex-ssr 1.0.5__py3-none-any.whl → 1.0.6__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.
@@ -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
- new_soup = BeautifulSoup(rendered_html, 'html.parser')
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
- el.clear()
235
- el.append(new_soup)
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.5
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. |
@@ -0,0 +1,8 @@
1
+ mkdocs_katex_ssr/plugin.py,sha256=lSSSH-LPyik6ZA4eblYb81PFNzzWxIcZ5GsIyrS9wek,13823
2
+ mkdocs_katex_ssr/renderer.js,sha256=15lIck7GXZHiAza9IpnSbu9HmeklaDp_zubetQQowkU,1967
3
+ mkdocs_katex_ssr-1.0.6.dist-info/licenses/LICENSE,sha256=Bea4m1bAyMhuJT5bCGl76QfpKatJarfMzl9vcrdXRgQ,1064
4
+ mkdocs_katex_ssr-1.0.6.dist-info/METADATA,sha256=0pkDe-rFgP1OQCM2ACdBbqMhFMGLDJFdMdWBW9_Ys10,5704
5
+ mkdocs_katex_ssr-1.0.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ mkdocs_katex_ssr-1.0.6.dist-info/entry_points.txt,sha256=l3PrOPi_1AqGLse2BTZVz2SB8rn3I4NRVI-wDUbIHVg,68
7
+ mkdocs_katex_ssr-1.0.6.dist-info/top_level.txt,sha256=FdfQyPUx4r9kgiqTW4da0TPUdBbOda_0PXjVkfGmsgs,17
8
+ mkdocs_katex_ssr-1.0.6.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- mkdocs_katex_ssr/plugin.py,sha256=-T7CYjyCuELmKcphpOSSMxUJ_WTBk1KvLCLgor_94-I,13163
2
- mkdocs_katex_ssr/renderer.js,sha256=15lIck7GXZHiAza9IpnSbu9HmeklaDp_zubetQQowkU,1967
3
- mkdocs_katex_ssr-1.0.5.dist-info/licenses/LICENSE,sha256=Bea4m1bAyMhuJT5bCGl76QfpKatJarfMzl9vcrdXRgQ,1064
4
- mkdocs_katex_ssr-1.0.5.dist-info/METADATA,sha256=nOHPUpLTurAhn678qSG69kWYr_lDgn0IfslItkBVt4U,5398
5
- mkdocs_katex_ssr-1.0.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
- mkdocs_katex_ssr-1.0.5.dist-info/entry_points.txt,sha256=l3PrOPi_1AqGLse2BTZVz2SB8rn3I4NRVI-wDUbIHVg,68
7
- mkdocs_katex_ssr-1.0.5.dist-info/top_level.txt,sha256=FdfQyPUx4r9kgiqTW4da0TPUdBbOda_0PXjVkfGmsgs,17
8
- mkdocs_katex_ssr-1.0.5.dist-info/RECORD,,