nodebb-plugin-katex2 1.0.6 → 1.0.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-katex2",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "KaTeX math rendering plugin for NodeBB",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -134,6 +134,32 @@
134
134
  });
135
135
  }
136
136
 
137
+ /**
138
+ * Ожидание готовности KaTeX с таймаутом
139
+ */
140
+ function waitForKatex(maxAttempts = 50, interval = 50) {
141
+ return new Promise((resolve, reject) => {
142
+ let attempts = 0;
143
+
144
+ const check = () => {
145
+ if (isKatexReady()) {
146
+ resolve();
147
+ return;
148
+ }
149
+
150
+ attempts++;
151
+ if (attempts >= maxAttempts) {
152
+ reject(new Error("KaTeX did not initialize in time"));
153
+ return;
154
+ }
155
+
156
+ setTimeout(check, interval);
157
+ };
158
+
159
+ check();
160
+ });
161
+ }
162
+
137
163
  /**
138
164
  * Загрузка библиотеки KaTeX
139
165
  * @returns {Promise}
@@ -158,10 +184,14 @@
158
184
  // Правильный путь согласно plugin.json staticDirs
159
185
  const basePath = "/assets/plugins/nodebb-plugin-katex2/katex/";
160
186
 
187
+ await loadScript(basePath + "katex.min.js");
188
+
189
+ // 3. Ждем инициализации katex
190
+ await waitForKatex();
191
+
161
192
  // Параллельная загрузка всех ресурсов
162
193
  await Promise.all([
163
194
  loadCSS(basePath + "katex.min.css"),
164
- loadScript(basePath + "katex.min.js"),
165
195
  loadScript(basePath + "contrib/auto-render.min.js"),
166
196
  ]);
167
197