extract-webpage 1.2.334 → 1.2.335

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.
@@ -1,2 +1,12 @@
1
1
  import { default as Prism } from 'prismjs';
2
+ /**
3
+ * Registers the grammars above, once per runtime. Cheap to call repeatedly —
4
+ * callers are meant to invoke it wherever they are about to highlight, so that
5
+ * the work does not hinge on a module-level statement surviving tree-shaking.
6
+ *
7
+ * Never rejects: a grammar that fails to load just leaves its language out of
8
+ * `Prism.languages`, which every caller already treats as "render this block
9
+ * unhighlighted".
10
+ */
11
+ export declare function loadPrismGrammars(): Promise<void>;
2
12
  export default Prism;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-webpage",
3
- "version": "1.2.334",
3
+ "version": "1.2.335",
4
4
  "module": "./dist/extract-webpage.es.js",
5
5
  "description": "Search, extract, cite, and outline the web for a topic with AI Research Agent.",
6
6
  "author": "vtempest <grokthiscontact@gmail.com>",
@@ -74,11 +74,11 @@
74
74
  "dependencies": {
75
75
  "@huggingface/transformers": "^4.2.0",
76
76
  "ai": "^7.0.94",
77
- "chat-agent-toolkit": "^1.2.340",
77
+ "chat-agent-toolkit": "^1.2.341",
78
78
  "chrono-node": "^2.10.1",
79
79
  "drizzle-orm": "^0.45.2",
80
- "extract-pdf": "^0.1.324",
81
- "extract-youtube": "^1.0.328",
80
+ "extract-pdf": "^0.1.325",
81
+ "extract-youtube": "^1.0.329",
82
82
  "html-entities": "^2.6.0",
83
83
  "js-yaml": "^5.4.1",
84
84
  "jsdom": "^30.0.1",
@@ -139,26 +139,15 @@ export function convertURLToAbsoluteURL(base, relative) {
139
139
  }
140
140
 
141
141
  import { marked } from "marked";
142
- // Must precede every `prismjs/components/*` import: the grammar scripts read
143
- // `Prism` off the global object, which this module publishes (see its docs).
144
- import Prism from "./prism-global";
145
- import "prismjs/components/prism-markup.js";
146
- import "prismjs/components/prism-css.js";
147
- import "prismjs/components/prism-javascript.js";
148
- import "prismjs/components/prism-typescript.js";
149
- import "prismjs/components/prism-jsx.js";
150
- import "prismjs/components/prism-tsx.js";
151
- import "prismjs/components/prism-python.js";
152
- import "prismjs/components/prism-bash.js";
153
- import "prismjs/components/prism-json.js";
154
- import "prismjs/components/prism-yaml.js";
155
- import "prismjs/components/prism-markdown.js";
156
- import "prismjs/components/prism-sql.js";
157
- import "prismjs/components/prism-rust.js";
158
- import "prismjs/components/prism-go.js";
159
- import "prismjs/components/prism-java.js";
160
- import "prismjs/components/prism-c.js";
161
- import "prismjs/components/prism-cpp.js";
142
+ // `prism-global` owns both the Prism instance and the grammars beyond the ones
143
+ // prismjs' entry point bundles; importing `prismjs/components/*` here directly
144
+ // would reintroduce the load-order crash its docs describe.
145
+ import Prism, { loadPrismGrammars } from "./prism-global";
146
+
147
+ // Start the grammars loading now, and again from the renderer below — the
148
+ // second call is what guarantees they are requested at all, since a bundler is
149
+ // free to drop this one as a side effect of a module it thinks is pure.
150
+ void loadPrismGrammars();
162
151
 
163
152
  // Configure marked once at module load with Prism.js syntax highlighting.
164
153
  // marked v17 removed the `highlight` option from setOptions, so highlighting
@@ -166,6 +155,7 @@ import "prismjs/components/prism-cpp.js";
166
155
  marked.use({
167
156
  renderer: {
168
157
  code({ text, lang }) {
158
+ void loadPrismGrammars();
169
159
  const language = lang && Prism.languages[lang] ? lang : null;
170
160
  const highlighted = language
171
161
  ? Prism.highlight(text, Prism.languages[language], language)
@@ -1,22 +1,82 @@
1
1
  /**
2
2
  * @module html-to-content/prism-global
3
- * @description Publishes Prism on `globalThis` so the `prismjs/components/*`
4
- * grammar scripts can find it.
3
+ * @description Owns the Prism instance: publishes it on `globalThis`, then
4
+ * registers the language grammars that prismjs' own entry point leaves out —
5
+ * without ever depending on module evaluation order.
5
6
  *
6
- * Those grammar files are plain browser scripts, not modules — `prism-markup.js`
7
- * literally opens with `Prism.languages.markup = {...}`, resolving `Prism` as a
8
- * free variable off the global object. Prism's core only publishes that global
9
- * when it can see `window` (browser), a `WorkerGlobalScope` `self`, or Node's
10
- * `global`. On Cloudflare Workers / edge runtimes none of the three exist, so
11
- * the first grammar file throws `ReferenceError: Prism is not defined` while the
12
- * module graph is still evaluating, taking the whole SSR render down with it.
7
+ * The `prismjs/components/*` files are plain browser scripts, not modules:
8
+ * `prism-markup.js` literally opens with `Prism.languages.markup = {...}`,
9
+ * resolving `Prism` as a free variable off the global object. Someone has to
10
+ * put it there first. prismjs' own entry point does that for `window`
11
+ * (browser) and `global` (Node); on Cloudflare Workers / edge runtimes it sees
12
+ * neither, which is what the assignment below is for.
13
13
  *
14
- * Import this module *before* any `prismjs/components/*` import. ES modules are
15
- * evaluated in import order, so this file's body runs — and the global lands —
16
- * before the grammars reference it.
14
+ * Publishing it is only half the job, though: it has to happen *before* the
15
+ * grammar scripts run, and a static `import "prismjs/components/..."` cannot
16
+ * promise that once a bundler is in the loop. Those files declare no
17
+ * dependency on Prism — reading a global is invisible to the module graph — so
18
+ * nothing pins them after whoever publishes it, and a bundler is free to hoist
19
+ * them, split them into another chunk, or drop the publishing statement as a
20
+ * dead `globalThis` write. When that happens the chunk dies on load with
21
+ * `ReferenceError: Prism is not defined`, which takes down the whole route
22
+ * that lazily imported it rather than just the syntax highlighting.
23
+ *
24
+ * So the grammars are loaded with `import()` from inside `loadPrismGrammars()`
25
+ * instead. The global is published by a statement earlier in that same
26
+ * function body, which makes the ordering a runtime fact rather than a promise
27
+ * the bundler has to keep.
17
28
  */
18
29
  import Prism from "prismjs";
19
30
 
20
- (globalThis as typeof globalThis & { Prism?: unknown }).Prism ??= Prism;
31
+ /**
32
+ * The grammars to register, in order — several extend an earlier one, so this
33
+ * list is loaded sequentially rather than in parallel (`tsx` needs `jsx` and
34
+ * `typescript`; `cpp` needs `c`). Markup, CSS, C-like and JavaScript are
35
+ * absent because prismjs' entry point already bundles them.
36
+ */
37
+ const GRAMMARS: ReadonlyArray<() => Promise<unknown>> = [
38
+ () => import("prismjs/components/prism-typescript.js"),
39
+ () => import("prismjs/components/prism-jsx.js"),
40
+ () => import("prismjs/components/prism-tsx.js"),
41
+ () => import("prismjs/components/prism-python.js"),
42
+ () => import("prismjs/components/prism-bash.js"),
43
+ () => import("prismjs/components/prism-json.js"),
44
+ () => import("prismjs/components/prism-yaml.js"),
45
+ () => import("prismjs/components/prism-markdown.js"),
46
+ () => import("prismjs/components/prism-sql.js"),
47
+ () => import("prismjs/components/prism-rust.js"),
48
+ () => import("prismjs/components/prism-go.js"),
49
+ () => import("prismjs/components/prism-java.js"),
50
+ () => import("prismjs/components/prism-c.js"),
51
+ () => import("prismjs/components/prism-cpp.js"),
52
+ ];
53
+
54
+ /** Puts Prism where the grammar scripts look for it. Idempotent. */
55
+ function publishPrismGlobal(): void {
56
+ (globalThis as typeof globalThis & { Prism?: typeof Prism }).Prism ??= Prism;
57
+ }
58
+
59
+ publishPrismGlobal();
60
+
61
+ let loading: Promise<void> | undefined;
62
+
63
+ /**
64
+ * Registers the grammars above, once per runtime. Cheap to call repeatedly —
65
+ * callers are meant to invoke it wherever they are about to highlight, so that
66
+ * the work does not hinge on a module-level statement surviving tree-shaking.
67
+ *
68
+ * Never rejects: a grammar that fails to load just leaves its language out of
69
+ * `Prism.languages`, which every caller already treats as "render this block
70
+ * unhighlighted".
71
+ */
72
+ export function loadPrismGrammars(): Promise<void> {
73
+ loading ??= (async () => {
74
+ publishPrismGlobal();
75
+ for (const load of GRAMMARS) {
76
+ await load();
77
+ }
78
+ })().catch(() => {});
79
+ return loading;
80
+ }
21
81
 
22
82
  export default Prism;