@ai-matrx/print 0.2.1 → 0.3.1
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/CHANGELOG.md +76 -0
- package/README.md +44 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/markdown.cjs +1260 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.cts +177 -0
- package/dist/markdown.d.ts +177 -0
- package/dist/markdown.js +1237 -0
- package/dist/markdown.js.map +1 -0
- package/dist/pdf.cjs +77 -4
- package/dist/pdf.cjs.map +1 -1
- package/dist/pdf.d.cts +35 -9
- package/dist/pdf.d.ts +35 -9
- package/dist/pdf.js +77 -4
- package/dist/pdf.js.map +1 -1
- package/package.json +12 -2
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,1237 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
function escapeHtml(str) {
|
|
3
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4
|
+
}
|
|
5
|
+
function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
|
|
6
|
+
const win = window.open("", "_blank", windowFeatures);
|
|
7
|
+
if (!win) {
|
|
8
|
+
const blob = new Blob([htmlDocument], { type: "text/html;charset=utf-8" });
|
|
9
|
+
const url = URL.createObjectURL(blob);
|
|
10
|
+
const a = document.createElement("a");
|
|
11
|
+
a.href = url;
|
|
12
|
+
a.download = `${filename.replace(/\s+/g, "-").toLowerCase()}.html`;
|
|
13
|
+
document.body.appendChild(a);
|
|
14
|
+
a.click();
|
|
15
|
+
document.body.removeChild(a);
|
|
16
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
17
|
+
return "downloaded";
|
|
18
|
+
}
|
|
19
|
+
win.document.open();
|
|
20
|
+
win.document.write(htmlDocument);
|
|
21
|
+
win.document.close();
|
|
22
|
+
return "opened";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/markdown-css.ts
|
|
26
|
+
var MARKDOWN_DOCUMENT_TOKENS_CSS = `:root {
|
|
27
|
+
--matrx-print-accent: #667eea;
|
|
28
|
+
--matrx-print-accent-2: #764ba2;
|
|
29
|
+
--matrx-print-bg: #ffffff;
|
|
30
|
+
--matrx-print-border: #e1e1e1;
|
|
31
|
+
--matrx-print-border-muted: #d1d5db;
|
|
32
|
+
--matrx-print-border-strong: #e5e5e5;
|
|
33
|
+
--matrx-print-code-bg: #f5f5f5;
|
|
34
|
+
--matrx-print-code-block-bg: #f8f8f8;
|
|
35
|
+
--matrx-print-code-block-fg: #333;
|
|
36
|
+
--matrx-print-code-fg: #d73a49;
|
|
37
|
+
--matrx-print-fg: #1a1a1a;
|
|
38
|
+
--matrx-print-fg-muted: #4a4a4a;
|
|
39
|
+
--matrx-print-fg-subtle: #6b7280;
|
|
40
|
+
--matrx-print-heading: #2a2a2a;
|
|
41
|
+
--matrx-print-heading-sub: #3a3a3a;
|
|
42
|
+
--matrx-print-link-fg: #374151;
|
|
43
|
+
--matrx-print-link-hover-fg: #1f2937;
|
|
44
|
+
--matrx-print-link-underline: #9ca3af;
|
|
45
|
+
--matrx-print-quote-fg: #666;
|
|
46
|
+
--matrx-print-shadow: rgba(0, 0, 0, 0.1);
|
|
47
|
+
--matrx-print-shadow-strong: rgba(0, 0, 0, 0.2);
|
|
48
|
+
--matrx-print-success: #2d5016;
|
|
49
|
+
--matrx-print-success-2: #1e3a0f;
|
|
50
|
+
--matrx-print-surface: #f8f9fa;
|
|
51
|
+
--matrx-print-table-fg: #333333;
|
|
52
|
+
}`;
|
|
53
|
+
var MARKDOWN_ARTICLE_TOKENS_CSS = `:root {
|
|
54
|
+
--matrx-print-accent: #2563eb;
|
|
55
|
+
--matrx-print-bg: #fff;
|
|
56
|
+
--matrx-print-border: #e5e7eb;
|
|
57
|
+
--matrx-print-border-muted: #d1d5db;
|
|
58
|
+
--matrx-print-code-bg: #f1f5f9;
|
|
59
|
+
--matrx-print-fg: #1a1a1a;
|
|
60
|
+
--matrx-print-fg-muted: #374151;
|
|
61
|
+
--matrx-print-fg-subtle: #64748b;
|
|
62
|
+
--matrx-print-heading: #111827;
|
|
63
|
+
--matrx-print-ink: #0f172a;
|
|
64
|
+
--matrx-print-line: #e2e8f0;
|
|
65
|
+
--matrx-print-quote-bg: #f5f3ff;
|
|
66
|
+
--matrx-print-quote-border: #6366f1;
|
|
67
|
+
--matrx-print-surface: #f8fafc;
|
|
68
|
+
--matrx-print-surface-sunken: #f3f4f6;
|
|
69
|
+
--matrx-print-table-head-bg: #1e293b;
|
|
70
|
+
--matrx-print-table-head-border: #334155;
|
|
71
|
+
}`;
|
|
72
|
+
var MARKDOWN_DOCUMENT_CSS = `/*
|
|
73
|
+
* MATRX WordPress CSS - Production Ready
|
|
74
|
+
* Use this CSS in your WordPress theme to style MATRX content
|
|
75
|
+
* All styles are scoped to .matrx-content-container to avoid conflicts
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/* Content Container */
|
|
79
|
+
.matrx-content-container {
|
|
80
|
+
max-width: 800px;
|
|
81
|
+
margin: 0 auto;
|
|
82
|
+
padding: 2rem;
|
|
83
|
+
line-height: 1.6;
|
|
84
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* Typography */
|
|
88
|
+
.matrx-h1 {
|
|
89
|
+
font-size: 2.5rem;
|
|
90
|
+
font-weight: 700;
|
|
91
|
+
margin: 0 0 1.5rem 0;
|
|
92
|
+
color: var(--matrx-print-fg, #1a1a1a);
|
|
93
|
+
line-height: 1.2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.matrx-h2 {
|
|
97
|
+
font-size: 1.8rem;
|
|
98
|
+
font-weight: 600;
|
|
99
|
+
margin: 3rem 0 1rem 0 !important;
|
|
100
|
+
color: var(--matrx-print-heading, #2a2a2a);
|
|
101
|
+
line-height: 1.3 !important;
|
|
102
|
+
border-bottom: 2px solid var(--matrx-print-border-strong, #e5e5e5);
|
|
103
|
+
padding-bottom: 0.75rem !important;
|
|
104
|
+
padding-top: 0 !important;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.matrx-h3 {
|
|
108
|
+
font-size: 1.3rem;
|
|
109
|
+
font-weight: 600;
|
|
110
|
+
margin: 2rem 0 1rem 0;
|
|
111
|
+
color: var(--matrx-print-heading-sub, #3a3a3a);
|
|
112
|
+
line-height: 1.4;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.matrx-h4 {
|
|
116
|
+
font-size: 1.1rem;
|
|
117
|
+
font-weight: 600;
|
|
118
|
+
margin: 1.5rem 0 0.75rem 0;
|
|
119
|
+
color: var(--matrx-print-heading-sub, #3a3a3a);
|
|
120
|
+
line-height: 1.4;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.matrx-h5 {
|
|
124
|
+
font-size: 1rem;
|
|
125
|
+
font-weight: 600;
|
|
126
|
+
margin: 1.25rem 0 0.5rem 0;
|
|
127
|
+
color: var(--matrx-print-heading-sub, #3a3a3a);
|
|
128
|
+
line-height: 1.4;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.matrx-h6 {
|
|
132
|
+
font-size: 0.9rem;
|
|
133
|
+
font-weight: 600;
|
|
134
|
+
margin: 1rem 0 0.5rem 0;
|
|
135
|
+
color: var(--matrx-print-heading-sub, #3a3a3a);
|
|
136
|
+
line-height: 1.4;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Paragraphs */
|
|
140
|
+
.matrx-intro {
|
|
141
|
+
font-size: 1.1rem;
|
|
142
|
+
color: var(--matrx-print-fg-muted, #4a4a4a);
|
|
143
|
+
margin-bottom: 2rem;
|
|
144
|
+
padding: 1.5rem;
|
|
145
|
+
background: var(--matrx-print-surface, #f8f9fa);
|
|
146
|
+
border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);
|
|
147
|
+
border-radius: 0 8px 8px 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.matrx-paragraph {
|
|
151
|
+
font-size: 1rem;
|
|
152
|
+
color: var(--matrx-print-fg-muted, #4a4a4a);
|
|
153
|
+
margin-bottom: 1.5rem;
|
|
154
|
+
text-align: justify;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* Text Formatting */
|
|
158
|
+
.matrx-em {
|
|
159
|
+
font-style: italic;
|
|
160
|
+
color: var(--matrx-print-heading, #2a2a2a);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.matrx-strong {
|
|
164
|
+
font-weight: 600;
|
|
165
|
+
color: var(--matrx-print-heading, #2a2a2a);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Links */
|
|
169
|
+
.matrx-link {
|
|
170
|
+
color: var(--matrx-print-link-fg, #374151);
|
|
171
|
+
text-decoration: underline;
|
|
172
|
+
text-decoration-color: var(--matrx-print-border-muted, #d1d5db);
|
|
173
|
+
text-underline-offset: 3px;
|
|
174
|
+
transition: all 0.2s ease;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.matrx-link:hover {
|
|
178
|
+
color: var(--matrx-print-link-hover-fg, #1f2937);
|
|
179
|
+
text-decoration-color: var(--matrx-print-link-underline, #9ca3af);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Images */
|
|
183
|
+
.matrx-image {
|
|
184
|
+
max-width: 100%;
|
|
185
|
+
height: auto;
|
|
186
|
+
display: block;
|
|
187
|
+
margin: 1.5rem auto;
|
|
188
|
+
border-radius: 8px;
|
|
189
|
+
box-shadow: 0 2px 8px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* Lists */
|
|
193
|
+
.matrx-list {
|
|
194
|
+
margin: 1.5rem 0;
|
|
195
|
+
padding-left: 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.matrx-bullet-list {
|
|
199
|
+
list-style: none;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.matrx-list-item {
|
|
203
|
+
margin-bottom: 1rem;
|
|
204
|
+
padding-left: 1.5rem;
|
|
205
|
+
position: relative;
|
|
206
|
+
color: var(--matrx-print-fg-muted, #4a4a4a);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.matrx-list-item::before {
|
|
210
|
+
content: "\u2022";
|
|
211
|
+
color: var(--matrx-print-fg-subtle, #6b7280);
|
|
212
|
+
font-weight: bold;
|
|
213
|
+
position: absolute;
|
|
214
|
+
left: 0;
|
|
215
|
+
top: 0;
|
|
216
|
+
font-size: 1.2rem;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Numbered Lists */
|
|
220
|
+
.matrx-numbered-list {
|
|
221
|
+
list-style: decimal;
|
|
222
|
+
padding-left: 2rem;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.matrx-numbered-list > .matrx-list-item {
|
|
226
|
+
padding-left: 0.5rem;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.matrx-numbered-list > .matrx-list-item::before {
|
|
230
|
+
content: none;
|
|
231
|
+
/* Remove the bullet */
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Nested list indentation */
|
|
235
|
+
.matrx-nested-list {
|
|
236
|
+
margin-top: 0.5rem;
|
|
237
|
+
margin-bottom: 0.5rem;
|
|
238
|
+
padding-left: 1.5rem !important;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* Ensure nested lists within list items are properly indented */
|
|
242
|
+
.matrx-list-item > .matrx-list {
|
|
243
|
+
margin-top: 0.5rem;
|
|
244
|
+
margin-bottom: 0.5rem;
|
|
245
|
+
padding-left: 1.5rem;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* For multiple levels of nesting, increase indentation */
|
|
249
|
+
.matrx-nested-list .matrx-nested-list {
|
|
250
|
+
padding-left: 1.5rem !important;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Code */
|
|
254
|
+
.matrx-content-container .matrx-inline-code {
|
|
255
|
+
background-color: var(--matrx-print-code-bg, #f5f5f5);
|
|
256
|
+
padding: 0.125rem 0.25rem;
|
|
257
|
+
border-radius: 0.25rem;
|
|
258
|
+
font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
|
|
259
|
+
font-size: 0.875rem;
|
|
260
|
+
color: var(--matrx-print-code-fg, #d73a49);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.matrx-content-container .matrx-code-block {
|
|
264
|
+
background-color: var(--matrx-print-code-block-bg, #f8f8f8);
|
|
265
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
266
|
+
border-radius: 0.375rem;
|
|
267
|
+
padding: 1rem;
|
|
268
|
+
margin: 1.5rem 0;
|
|
269
|
+
overflow-x: auto;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.matrx-content-container .matrx-code {
|
|
273
|
+
font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
|
|
274
|
+
font-size: 0.875rem;
|
|
275
|
+
line-height: 1.5;
|
|
276
|
+
color: var(--matrx-print-code-block-fg, #333);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Blockquotes */
|
|
280
|
+
.matrx-content-container .matrx-blockquote {
|
|
281
|
+
border-left: 4px solid var(--matrx-print-border, #e1e1e1);
|
|
282
|
+
padding-left: 1rem;
|
|
283
|
+
margin: 1.5rem 0;
|
|
284
|
+
font-style: italic;
|
|
285
|
+
color: var(--matrx-print-quote-fg, #666);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/* Tables */
|
|
289
|
+
.matrx-content-container .matrx-table {
|
|
290
|
+
width: 100%;
|
|
291
|
+
border-collapse: collapse;
|
|
292
|
+
margin: 1.5rem 0;
|
|
293
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.matrx-content-container .matrx-table-header {
|
|
297
|
+
background-color: var(--matrx-print-surface, #f8f9fa);
|
|
298
|
+
font-weight: 600;
|
|
299
|
+
padding: 0.75rem;
|
|
300
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
301
|
+
text-align: left;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.matrx-content-container .matrx-table-cell {
|
|
305
|
+
padding: 0.75rem;
|
|
306
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.matrx-content-container .matrx-table-row:nth-child(even) {
|
|
310
|
+
background-color: var(--matrx-print-surface, #f8f9fa);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* Images */
|
|
314
|
+
.matrx-content-container .matrx-image {
|
|
315
|
+
max-width: 100%;
|
|
316
|
+
height: auto;
|
|
317
|
+
border-radius: 0.375rem;
|
|
318
|
+
margin: 1rem 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* Horizontal Rules */
|
|
322
|
+
.matrx-content-container .matrx-hr {
|
|
323
|
+
border: none;
|
|
324
|
+
border-top: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
325
|
+
margin: 2rem 0;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* FAQ Styles - Clean Design */
|
|
329
|
+
.matrx-faq-item {
|
|
330
|
+
margin-bottom: 2rem;
|
|
331
|
+
padding: 1.5rem;
|
|
332
|
+
background: var(--matrx-print-surface, #f8f9fa);
|
|
333
|
+
border-radius: 8px;
|
|
334
|
+
border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.matrx-faq-question {
|
|
338
|
+
font-size: 1.2rem;
|
|
339
|
+
font-weight: 600;
|
|
340
|
+
margin: 0 0 0.75rem 0;
|
|
341
|
+
color: var(--matrx-print-heading, #2a2a2a);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.matrx-faq-answer {
|
|
345
|
+
margin: 0;
|
|
346
|
+
color: var(--matrx-print-fg-muted, #4a4a4a);
|
|
347
|
+
line-height: 1.6;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/* Code Blocks */
|
|
351
|
+
.matrx-inline-code {
|
|
352
|
+
background-color: var(--matrx-print-code-bg, #f5f5f5);
|
|
353
|
+
padding: 0.125rem 0.25rem;
|
|
354
|
+
border-radius: 0.25rem;
|
|
355
|
+
font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
|
|
356
|
+
font-size: 0.875rem;
|
|
357
|
+
color: var(--matrx-print-code-fg, #d73a49);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.matrx-code-block {
|
|
361
|
+
background-color: var(--matrx-print-code-block-bg, #f8f8f8);
|
|
362
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
363
|
+
border-radius: 0.375rem;
|
|
364
|
+
padding: 1rem;
|
|
365
|
+
margin: 1.5rem 0;
|
|
366
|
+
overflow-x: auto;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.matrx-code {
|
|
370
|
+
font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
|
|
371
|
+
font-size: 0.875rem;
|
|
372
|
+
line-height: 1.5;
|
|
373
|
+
color: var(--matrx-print-code-block-fg, #333);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* Blockquotes */
|
|
377
|
+
.matrx-blockquote {
|
|
378
|
+
border-left: 4px solid var(--matrx-print-border, #e1e1e1);
|
|
379
|
+
padding-left: 1rem;
|
|
380
|
+
margin: 1.5rem 0;
|
|
381
|
+
font-style: italic;
|
|
382
|
+
color: var(--matrx-print-quote-fg, #666);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/* Tables */
|
|
386
|
+
.matrx-table {
|
|
387
|
+
width: 100%;
|
|
388
|
+
border-collapse: collapse;
|
|
389
|
+
margin: 1.5rem 0;
|
|
390
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
391
|
+
color: var(--matrx-print-table-fg, #333333);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.matrx-table-head {
|
|
395
|
+
background-color: var(--matrx-print-surface, #f8f9fa);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.matrx-table-body {
|
|
399
|
+
background-color: var(--matrx-print-bg, #ffffff);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.matrx-table-header {
|
|
403
|
+
background-color: var(--matrx-print-surface, #f8f9fa);
|
|
404
|
+
font-weight: 600;
|
|
405
|
+
padding: 0.75rem;
|
|
406
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
407
|
+
text-align: left;
|
|
408
|
+
color: var(--matrx-print-table-fg, #333333);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.matrx-table-cell {
|
|
412
|
+
padding: 0.75rem;
|
|
413
|
+
border: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
414
|
+
color: var(--matrx-print-table-fg, #333333);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.matrx-table-row {
|
|
418
|
+
color: var(--matrx-print-table-fg, #333333);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.matrx-table-row:nth-child(even) {
|
|
422
|
+
background-color: var(--matrx-print-surface, #f8f9fa);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/* Ensure table content doesn't inherit external colors */
|
|
426
|
+
.matrx-table * {
|
|
427
|
+
color: inherit;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* Images */
|
|
431
|
+
.matrx-image {
|
|
432
|
+
max-width: 100%;
|
|
433
|
+
height: auto;
|
|
434
|
+
border-radius: 0.375rem;
|
|
435
|
+
margin: 1rem 0;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/* Horizontal Rules */
|
|
439
|
+
.matrx-hr {
|
|
440
|
+
border: none;
|
|
441
|
+
border-top: 1px solid var(--matrx-print-border, #e1e1e1);
|
|
442
|
+
margin: 2rem 0;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/* Utility Classes */
|
|
446
|
+
.matrx-div {
|
|
447
|
+
margin: 0.5rem 0;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.matrx-span {
|
|
451
|
+
/* Inherit parent styling by default */
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/* Flashcard Styles */
|
|
455
|
+
.matrx-flashcards-container {
|
|
456
|
+
margin: 2rem 0;
|
|
457
|
+
display: flex;
|
|
458
|
+
flex-direction: column;
|
|
459
|
+
gap: 0.5rem;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
.matrx-flashcard {
|
|
463
|
+
perspective: 1000px;
|
|
464
|
+
perspective-origin: center center;
|
|
465
|
+
height: 200px;
|
|
466
|
+
cursor: pointer;
|
|
467
|
+
position: relative;
|
|
468
|
+
margin-bottom: 0.5rem;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.matrx-flashcard-input {
|
|
472
|
+
display: none;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.matrx-flashcard-inner {
|
|
476
|
+
position: absolute;
|
|
477
|
+
top: 0;
|
|
478
|
+
left: 0;
|
|
479
|
+
width: 100%;
|
|
480
|
+
height: 100%;
|
|
481
|
+
transition: transform 0.6s;
|
|
482
|
+
transform-style: preserve-3d;
|
|
483
|
+
transform-origin: center center;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.matrx-flashcard-input:checked ~ .matrx-flashcard-inner {
|
|
487
|
+
transform: rotateY(180deg);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
.matrx-flashcard-front,
|
|
491
|
+
.matrx-flashcard-back {
|
|
492
|
+
position: absolute;
|
|
493
|
+
top: 0;
|
|
494
|
+
left: 0;
|
|
495
|
+
width: 100%;
|
|
496
|
+
height: 100%;
|
|
497
|
+
backface-visibility: hidden;
|
|
498
|
+
border-radius: 12px;
|
|
499
|
+
display: flex;
|
|
500
|
+
align-items: center;
|
|
501
|
+
justify-content: center;
|
|
502
|
+
padding: 1.5rem;
|
|
503
|
+
box-shadow: 0 4px 6px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));
|
|
504
|
+
transition: box-shadow 0.3s ease;
|
|
505
|
+
box-sizing: border-box;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.matrx-flashcard-front {
|
|
509
|
+
background: linear-gradient(135deg, var(--matrx-print-accent, #667eea) 0%, var(--matrx-print-accent-2, #764ba2) 100%);
|
|
510
|
+
color: white;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
.matrx-flashcard-back {
|
|
514
|
+
background: linear-gradient(135deg, var(--matrx-print-success, #2d5016) 0%, var(--matrx-print-success-2, #1e3a0f) 100%);
|
|
515
|
+
color: white;
|
|
516
|
+
transform: rotateY(180deg);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.matrx-flashcard:hover .matrx-flashcard-front,
|
|
520
|
+
.matrx-flashcard:hover .matrx-flashcard-back {
|
|
521
|
+
box-shadow: 0 8px 16px var(--matrx-print-shadow-strong, rgba(0, 0, 0, 0.2));
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.matrx-flashcard-content {
|
|
525
|
+
text-align: center;
|
|
526
|
+
font-size: 1.3rem;
|
|
527
|
+
line-height: 1.8;
|
|
528
|
+
max-height: 100%;
|
|
529
|
+
width: 100%;
|
|
530
|
+
overflow: hidden;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.matrx-flashcard-label {
|
|
534
|
+
cursor: pointer;
|
|
535
|
+
user-select: none;
|
|
536
|
+
position: absolute;
|
|
537
|
+
top: 0;
|
|
538
|
+
left: 0;
|
|
539
|
+
width: 100%;
|
|
540
|
+
height: 100%;
|
|
541
|
+
z-index: 10;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.matrx-flashcard-indicator {
|
|
545
|
+
position: absolute;
|
|
546
|
+
bottom: 12px;
|
|
547
|
+
right: 16px;
|
|
548
|
+
font-size: 0.75rem;
|
|
549
|
+
opacity: 0.8;
|
|
550
|
+
font-weight: 500;
|
|
551
|
+
letter-spacing: 0.5px;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/* Responsive adjustments */
|
|
555
|
+
@media (max-width: 768px) {
|
|
556
|
+
.matrx-flashcard {
|
|
557
|
+
height: 180px;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
.matrx-flashcard-content {
|
|
561
|
+
font-size: 1rem;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.matrx-flashcard-front,
|
|
565
|
+
.matrx-flashcard-back {
|
|
566
|
+
padding: 1.25rem;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
@media (max-width: 480px) {
|
|
571
|
+
.matrx-flashcard {
|
|
572
|
+
height: 160px;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
.matrx-flashcard-content {
|
|
576
|
+
font-size: 0.95rem;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
.matrx-flashcard-front,
|
|
580
|
+
.matrx-flashcard-back {
|
|
581
|
+
padding: 1rem;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/* Responsive Design */
|
|
586
|
+
@media (max-width: 768px) {
|
|
587
|
+
.matrx-content-container {
|
|
588
|
+
padding: 1rem;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
.matrx-h1 {
|
|
592
|
+
font-size: 2rem;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
.matrx-h2 {
|
|
596
|
+
font-size: 1.5rem;
|
|
597
|
+
margin: 2rem 0 1rem 0 !important;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
.matrx-h3 {
|
|
601
|
+
font-size: 1.2rem;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
.matrx-h4 {
|
|
605
|
+
font-size: 1.05rem;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
.matrx-h5 {
|
|
609
|
+
font-size: 0.95rem;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
.matrx-h6 {
|
|
613
|
+
font-size: 0.9rem;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
.matrx-intro {
|
|
617
|
+
padding: 1rem;
|
|
618
|
+
font-size: 1rem;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
.matrx-faq-question {
|
|
622
|
+
font-size: 1.1rem;
|
|
623
|
+
margin: 1.5rem 0 0.75rem 0;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.matrx-paragraph {
|
|
627
|
+
text-align: left;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
.matrx-table {
|
|
631
|
+
font-size: 0.875rem;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.matrx-table-header,
|
|
635
|
+
.matrx-table-cell {
|
|
636
|
+
padding: 0.5rem;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.matrx-code-block {
|
|
640
|
+
padding: 0.75rem;
|
|
641
|
+
margin: 1rem 0;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
@media (max-width: 480px) {
|
|
646
|
+
.matrx-content-container {
|
|
647
|
+
padding: 0.75rem;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
.matrx-h1 {
|
|
651
|
+
font-size: 1.75rem;
|
|
652
|
+
margin-bottom: 1rem;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
.matrx-h2 {
|
|
656
|
+
font-size: 1.3rem;
|
|
657
|
+
margin: 1.5rem 0 0.75rem 0 !important;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.matrx-h3 {
|
|
661
|
+
font-size: 1.1rem;
|
|
662
|
+
margin: 1.5rem 0 0.75rem 0;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
.matrx-h4 {
|
|
666
|
+
font-size: 1rem;
|
|
667
|
+
margin: 1.25rem 0 0.5rem 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
.matrx-h5 {
|
|
671
|
+
font-size: 0.9rem;
|
|
672
|
+
margin: 1rem 0 0.5rem 0;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
.matrx-h6 {
|
|
676
|
+
font-size: 0.85rem;
|
|
677
|
+
margin: 1rem 0 0.5rem 0;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
.matrx-intro {
|
|
681
|
+
padding: 0.75rem;
|
|
682
|
+
margin-bottom: 1.5rem;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
.matrx-paragraph {
|
|
686
|
+
margin-bottom: 1.25rem;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.matrx-list-item {
|
|
690
|
+
margin-bottom: 0.75rem;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
.matrx-table-header,
|
|
694
|
+
.matrx-table-cell {
|
|
695
|
+
padding: 0.375rem;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
.matrx-code-block {
|
|
699
|
+
padding: 0.5rem;
|
|
700
|
+
font-size: 0.8rem;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
.matrx-inline-code {
|
|
704
|
+
font-size: 0.8rem;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
/* Print / PDF hard parts \u2014 added by @ai-matrx/print 0.3.0. */
|
|
708
|
+
@media print {
|
|
709
|
+
.matrx-content-container {
|
|
710
|
+
max-width: 100%;
|
|
711
|
+
padding: 0;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
.matrx-h1,
|
|
715
|
+
.matrx-h2,
|
|
716
|
+
.matrx-h3,
|
|
717
|
+
.matrx-h4,
|
|
718
|
+
.matrx-h5,
|
|
719
|
+
.matrx-h6 {
|
|
720
|
+
page-break-after: avoid;
|
|
721
|
+
break-after: avoid;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
.matrx-paragraph,
|
|
725
|
+
.matrx-intro {
|
|
726
|
+
orphans: 3;
|
|
727
|
+
widows: 3;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
.matrx-table,
|
|
731
|
+
.matrx-code-block,
|
|
732
|
+
.matrx-blockquote,
|
|
733
|
+
.matrx-list-item,
|
|
734
|
+
.matrx-image,
|
|
735
|
+
.matrx-faq-item,
|
|
736
|
+
.matrx-flashcard {
|
|
737
|
+
page-break-inside: avoid;
|
|
738
|
+
break-inside: avoid;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
.matrx-table-header,
|
|
742
|
+
.matrx-code-block,
|
|
743
|
+
.matrx-blockquote,
|
|
744
|
+
.matrx-flashcard {
|
|
745
|
+
-webkit-print-color-adjust: exact;
|
|
746
|
+
print-color-adjust: exact;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
.matrx-link {
|
|
750
|
+
text-decoration: underline;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
`;
|
|
754
|
+
var MARKDOWN_ARTICLE_CSS = `*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{font-family:Georgia,'Times New Roman',serif;font-size:11pt;line-height:1.7;color:var(--matrx-print-fg, #1a1a1a);background:var(--matrx-print-bg, #fff);max-width:780px;margin:0 auto;padding:32px 40px}.print-actions{display:flex;gap:10px;margin-bottom:28px;padding-bottom:20px;border-bottom:2px solid var(--matrx-print-border, #e5e7eb)}.print-btn{display:inline-flex;align-items:center;gap:6px;padding:8px 20px;border-radius:8px;font-size:13px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;cursor:pointer;border:none;font-weight:600;transition:opacity .15s}.print-btn:hover{opacity:.85}.print-btn-primary{background:var(--matrx-print-accent, #2563eb);color:var(--matrx-print-bg, #fff)}.print-btn-secondary{background:var(--matrx-print-surface-sunken, #f3f4f6);color:var(--matrx-print-fg-muted, #374151);border:1px solid var(--matrx-print-border-muted, #d1d5db)}h1,h2,h3,h4,h5,h6{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Helvetica Neue',sans-serif;font-weight:700;line-height:1.3;color:var(--matrx-print-heading, #111827);margin-top:1.6em;margin-bottom:.5em;page-break-after:avoid}h1{font-size:24pt;border-bottom:2px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.3em;margin-top:0}h2{font-size:18pt;border-bottom:1px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.2em}h3{font-size:14pt}p{margin-bottom:.9em;orphans:3;widows:3}a{color:var(--matrx-print-accent, #2563eb);text-decoration:underline;word-break:break-word}ul,ol{margin:.6em 0 .9em 0;padding-left:1.8em}li{margin-bottom:.3em;page-break-inside:avoid}blockquote{margin:1em 0;padding:.7em 1em .7em 1.2em;border-left:4px solid var(--matrx-print-quote-border, #6366f1);background:var(--matrx-print-quote-bg, #f5f3ff);border-radius:0 6px 6px 0;color:var(--matrx-print-fg-muted, #374151);font-style:italic;page-break-inside:avoid}.inline-code{font-family:'JetBrains Mono','Fira Code',monospace;font-size:9.5pt;background:var(--matrx-print-code-bg, #f1f5f9);color:var(--matrx-print-ink, #0f172a);padding:1px 5px;border-radius:4px;border:1px solid var(--matrx-print-line, #e2e8f0)}.code-block-wrapper{position:relative;margin:1em 0 1.2em;border-radius:8px;overflow:hidden;border:1px solid var(--matrx-print-line, #e2e8f0);page-break-inside:avoid}.code-lang{display:block;font-family:-apple-system,sans-serif;font-size:9pt;font-weight:600;color:var(--matrx-print-fg-subtle, #64748b);background:var(--matrx-print-surface, #f8fafc);padding:4px 12px;border-bottom:1px solid var(--matrx-print-line, #e2e8f0);text-transform:uppercase;letter-spacing:.05em}.code-block{margin:0;padding:14px 16px;background:var(--matrx-print-ink, #0f172a);color:var(--matrx-print-line, #e2e8f0);font-family:'JetBrains Mono',monospace;font-size:9pt;line-height:1.6;overflow-x:auto;white-space:pre;tab-size:2}.print-table{width:100%;border-collapse:collapse;margin:1em 0 1.2em;font-size:10pt;page-break-inside:avoid}.print-table th{background:var(--matrx-print-table-head-bg, #1e293b);color:var(--matrx-print-surface, #f8fafc);font-family:-apple-system,sans-serif;font-weight:600;font-size:9.5pt;text-align:left;padding:8px 12px;border:1px solid var(--matrx-print-table-head-border, #334155)}.print-table td{padding:7px 12px;border:1px solid var(--matrx-print-line, #e2e8f0);vertical-align:top}.print-table tr:nth-child(even) td{background:var(--matrx-print-surface, #f8fafc)}hr{border:none;border-top:2px solid var(--matrx-print-border, #e5e7eb);margin:1.5em 0}@media print{body{max-width:100%;padding:0;font-size:10.5pt}.print-actions{display:none!important}.code-block,.print-table th,blockquote{color-adjust:exact;-webkit-print-color-adjust:exact;print-color-adjust:exact}a[href]::after{content:" ("attr(href)")";font-size:9pt;color:var(--matrx-print-fg-subtle, #64748b)}a[href^="#"]::after,a[href^="javascript:"]::after{content:""}h1,h2,h3{page-break-after:avoid}pre,blockquote,table{page-break-inside:avoid}}`;
|
|
755
|
+
|
|
756
|
+
// src/markdown.ts
|
|
757
|
+
function removeThinkingContent(content) {
|
|
758
|
+
if (!content) return "";
|
|
759
|
+
let result = content.replace(/\n*<thinking>[\s\S]*?<\/thinking>\n*/gi, "\n").replace(/\n*<think>[\s\S]*?<\/think>\n*/gi, "\n").replace(/\n*<reasoning>[\s\S]*?<\/reasoning>\n*/gi, "\n");
|
|
760
|
+
result = result.replace(/\n{3,}/g, "\n\n");
|
|
761
|
+
return result.trim();
|
|
762
|
+
}
|
|
763
|
+
function hasThinkingContent(content) {
|
|
764
|
+
if (!content) return false;
|
|
765
|
+
return /<thinking>|<think>|<reasoning>/i.test(content);
|
|
766
|
+
}
|
|
767
|
+
function convertMarkdownTables(html) {
|
|
768
|
+
const tableRegex = /^(\|.*\|)\s*\n(\|[-\s:|]*\|)\s*\n((?:\|.*\|\s*\n?)*)/gm;
|
|
769
|
+
return html.replace(
|
|
770
|
+
tableRegex,
|
|
771
|
+
(_match, headerRow, _separatorRow, bodyRows) => {
|
|
772
|
+
const headers = headerRow.split("|").map((cell) => cell.trim()).filter((cell) => cell !== "");
|
|
773
|
+
const rows = bodyRows.trim().split("\n").filter((row) => row.trim()).map(
|
|
774
|
+
(row) => row.split("|").map((cell) => cell.trim()).filter((cell) => cell !== "")
|
|
775
|
+
);
|
|
776
|
+
let tableHtml = '<table class="matrx-table">\n';
|
|
777
|
+
if (headers.length > 0) {
|
|
778
|
+
tableHtml += '<thead class="matrx-table-head">\n<tr class="matrx-table-row">\n';
|
|
779
|
+
for (const header of headers) {
|
|
780
|
+
tableHtml += `<th class="matrx-table-header">${header}</th>
|
|
781
|
+
`;
|
|
782
|
+
}
|
|
783
|
+
tableHtml += "</tr>\n</thead>\n";
|
|
784
|
+
}
|
|
785
|
+
if (rows.length > 0) {
|
|
786
|
+
tableHtml += '<tbody class="matrx-table-body">\n';
|
|
787
|
+
for (const row of rows) {
|
|
788
|
+
if (row.length === 0) continue;
|
|
789
|
+
tableHtml += '<tr class="matrx-table-row">\n';
|
|
790
|
+
for (const cell of row) {
|
|
791
|
+
tableHtml += `<td class="matrx-table-cell">${cell}</td>
|
|
792
|
+
`;
|
|
793
|
+
}
|
|
794
|
+
tableHtml += "</tr>\n";
|
|
795
|
+
}
|
|
796
|
+
tableHtml += "</tbody>\n";
|
|
797
|
+
}
|
|
798
|
+
return `${tableHtml}</table>
|
|
799
|
+
`;
|
|
800
|
+
}
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
function markdownToHtml(markdown, options = {}) {
|
|
804
|
+
const notice = options.onNotice;
|
|
805
|
+
if (!markdown) {
|
|
806
|
+
notice?.({
|
|
807
|
+
code: "empty-output",
|
|
808
|
+
message: "markdownToHtml received an empty string.",
|
|
809
|
+
remedy: "Check the content is loaded before converting; nothing was rendered."
|
|
810
|
+
});
|
|
811
|
+
return "";
|
|
812
|
+
}
|
|
813
|
+
const startWrapper = '<div class="matrx-content-container">';
|
|
814
|
+
const endWrapper = "</div>";
|
|
815
|
+
let html = options.includeThinking ? markdown : removeThinkingContent(markdown);
|
|
816
|
+
const flashcardPlaceholders = [];
|
|
817
|
+
let flashcardIndex = 0;
|
|
818
|
+
let globalCardIndex = 0;
|
|
819
|
+
html = html.replace(
|
|
820
|
+
/<flashcards>([\s\S]*?)<\/flashcards>/gi,
|
|
821
|
+
(_match, content) => {
|
|
822
|
+
const cards = content.split(/\n*---\n*/g).map((card) => card.trim()).filter((card) => card.length > 0);
|
|
823
|
+
if (cards.length === 0) return "";
|
|
824
|
+
let flashcardsHtml = '<div class="matrx-flashcards-container">\n';
|
|
825
|
+
for (const card of cards) {
|
|
826
|
+
const frontMatch = card.match(/Front:\s*(.+?)(?=\n|$)/i);
|
|
827
|
+
const backMatch = card.match(/Back:\s*([\s\S]+?)$/i);
|
|
828
|
+
const front = frontMatch?.[1]?.trim();
|
|
829
|
+
const back = backMatch?.[1]?.trim();
|
|
830
|
+
if (!front || !back) {
|
|
831
|
+
notice?.({
|
|
832
|
+
code: "flashcard-malformed",
|
|
833
|
+
message: `A flashcard was skipped: it is missing a ${front ? "Back:" : "Front:"} line.`,
|
|
834
|
+
remedy: 'Every card inside <flashcards> needs both "Front: \u2026" and "Back: \u2026", separated from the next card by ---.'
|
|
835
|
+
});
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
globalCardIndex++;
|
|
839
|
+
const cardId = `card${globalCardIndex}`;
|
|
840
|
+
flashcardsHtml += ` <div class="matrx-flashcard">
|
|
841
|
+
<input type="checkbox" class="matrx-flashcard-input" id="${cardId}">
|
|
842
|
+
<label for="${cardId}" class="matrx-flashcard-label"></label>
|
|
843
|
+
<div class="matrx-flashcard-inner">
|
|
844
|
+
<div class="matrx-flashcard-front">
|
|
845
|
+
<div class="matrx-flashcard-content">
|
|
846
|
+
<strong>${front}</strong>
|
|
847
|
+
</div>
|
|
848
|
+
<span class="matrx-flashcard-indicator">CLICK TO FLIP</span>
|
|
849
|
+
</div>
|
|
850
|
+
<div class="matrx-flashcard-back">
|
|
851
|
+
<div class="matrx-flashcard-content">
|
|
852
|
+
${back}
|
|
853
|
+
</div>
|
|
854
|
+
<span class="matrx-flashcard-indicator">CLICK TO FLIP</span>
|
|
855
|
+
</div>
|
|
856
|
+
</div>
|
|
857
|
+
</div>
|
|
858
|
+
|
|
859
|
+
`;
|
|
860
|
+
}
|
|
861
|
+
flashcardsHtml += "</div>\n";
|
|
862
|
+
const placeholder = `\u03A9FLASHCARD\u03A9${flashcardIndex}\u03A9FLASHCARD\u03A9`;
|
|
863
|
+
flashcardPlaceholders.push({ placeholder, html: flashcardsHtml });
|
|
864
|
+
flashcardIndex++;
|
|
865
|
+
return placeholder;
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
html = html.replace(/^[-]{3,}$/gm, '<hr class="matrx-hr">');
|
|
869
|
+
html = html.replace(/^[*]{3,}$/gm, '<hr class="matrx-hr">');
|
|
870
|
+
const imagePlaceholders = [];
|
|
871
|
+
let imageIndex = 0;
|
|
872
|
+
html = html.replace(
|
|
873
|
+
/!\[([^\]]*)\]\(([^)]+)\)/g,
|
|
874
|
+
(_match, altText, url) => {
|
|
875
|
+
const placeholder = `\u03A9IMAGE\u03A9${imageIndex}\u03A9IMAGE\u03A9`;
|
|
876
|
+
imagePlaceholders.push({
|
|
877
|
+
placeholder,
|
|
878
|
+
html: `<img class="matrx-image" src="${url}" alt="${altText}" />`
|
|
879
|
+
});
|
|
880
|
+
imageIndex++;
|
|
881
|
+
return placeholder;
|
|
882
|
+
}
|
|
883
|
+
);
|
|
884
|
+
const linkPlaceholders = [];
|
|
885
|
+
let linkIndex = 0;
|
|
886
|
+
html = html.replace(
|
|
887
|
+
/\[([^\]]+)\]\(([^)]+)\)/g,
|
|
888
|
+
(_match, linkText, url) => {
|
|
889
|
+
const placeholder = `\u03A9LINK\u03A9${linkIndex}\u03A9LINK\u03A9`;
|
|
890
|
+
linkPlaceholders.push({
|
|
891
|
+
placeholder,
|
|
892
|
+
html: `<a class="matrx-link" href="${url}">${linkText}</a>`
|
|
893
|
+
});
|
|
894
|
+
linkIndex++;
|
|
895
|
+
return placeholder;
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
html = html.replace(/^# (.+)$/gm, '<h1 class="matrx-h1">$1</h1>').replace(/^## (.+)$/gm, '<h2 class="matrx-h2">$1</h2>').replace(/^### (.+)$/gm, '<h3 class="matrx-h3">$1</h3>').replace(/^#### (.+)$/gm, '<h4 class="matrx-h4">$1</h4>').replace(/^##### (.+)$/gm, '<h5 class="matrx-h5">$1</h5>').replace(/^###### (.+)$/gm, '<h6 class="matrx-h6">$1</h6>');
|
|
899
|
+
html = html.replace(/\*\*(.+?)\*\*/g, '<strong class="matrx-strong">$1</strong>').replace(/\*(.+?)\*/g, '<em class="matrx-em">$1</em>').replace(/__(.+?)__/g, '<strong class="matrx-strong">$1</strong>').replace(/_(.+?)_/g, '<em class="matrx-em">$1</em>');
|
|
900
|
+
const lines = html.split("\n");
|
|
901
|
+
let processedHtml = "";
|
|
902
|
+
const listStack = [];
|
|
903
|
+
let lastListItem = "";
|
|
904
|
+
const top = () => listStack[listStack.length - 1];
|
|
905
|
+
const closeDeeperThan = (indent) => {
|
|
906
|
+
while (listStack.length > 0 && top().indent > indent) {
|
|
907
|
+
if (lastListItem) {
|
|
908
|
+
processedHtml += "</li>\n";
|
|
909
|
+
lastListItem = "";
|
|
910
|
+
}
|
|
911
|
+
const closing = listStack.pop();
|
|
912
|
+
if (!closing) break;
|
|
913
|
+
processedHtml += closing.type === "ol" ? "</ol>\n" : "</ul>\n";
|
|
914
|
+
if (listStack.length > 0) processedHtml += "</li>\n";
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
for (const line of lines) {
|
|
918
|
+
const numberedMatch = line.match(/^(\s*)(\d+)\.\s+(.+)$/);
|
|
919
|
+
if (numberedMatch) {
|
|
920
|
+
const indent = (numberedMatch[1] ?? "").length;
|
|
921
|
+
const content = numberedMatch[3] ?? "";
|
|
922
|
+
const current = top();
|
|
923
|
+
if (current && indent > current.indent) {
|
|
924
|
+
processedHtml += '\n<ol class="matrx-list matrx-numbered-list matrx-nested-list">\n';
|
|
925
|
+
listStack.push({ type: "ol", indent });
|
|
926
|
+
processedHtml += `<li class="matrx-list-item">${content}`;
|
|
927
|
+
lastListItem = "ol";
|
|
928
|
+
} else {
|
|
929
|
+
closeDeeperThan(indent);
|
|
930
|
+
if (lastListItem && top()?.indent === indent) processedHtml += "</li>\n";
|
|
931
|
+
const now = top();
|
|
932
|
+
if (!now || now.indent !== indent || now.type !== "ol") {
|
|
933
|
+
processedHtml += '<ol class="matrx-list matrx-numbered-list">\n';
|
|
934
|
+
listStack.push({ type: "ol", indent });
|
|
935
|
+
}
|
|
936
|
+
processedHtml += `<li class="matrx-list-item">${content}`;
|
|
937
|
+
lastListItem = "ol";
|
|
938
|
+
}
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
const bulletMatch = line.match(/^(\s*)[*\-+]\s+(.+)$/);
|
|
942
|
+
if (bulletMatch) {
|
|
943
|
+
const indent = (bulletMatch[1] ?? "").length;
|
|
944
|
+
const content = bulletMatch[2] ?? "";
|
|
945
|
+
const current = top();
|
|
946
|
+
if (current && indent > current.indent) {
|
|
947
|
+
processedHtml += '\n<ul class="matrx-list matrx-bullet-list matrx-nested-list">\n';
|
|
948
|
+
listStack.push({ type: "ul", indent });
|
|
949
|
+
processedHtml += `<li class="matrx-list-item">${content}`;
|
|
950
|
+
lastListItem = "ul";
|
|
951
|
+
} else {
|
|
952
|
+
closeDeeperThan(indent);
|
|
953
|
+
if (lastListItem && top()?.indent === indent) processedHtml += "</li>\n";
|
|
954
|
+
const now = top();
|
|
955
|
+
if (!now || now.indent !== indent || now.type !== "ul") {
|
|
956
|
+
processedHtml += '<ul class="matrx-list matrx-bullet-list">\n';
|
|
957
|
+
listStack.push({ type: "ul", indent });
|
|
958
|
+
}
|
|
959
|
+
processedHtml += `<li class="matrx-list-item">${content}`;
|
|
960
|
+
lastListItem = "ul";
|
|
961
|
+
}
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (line.trim() !== "") {
|
|
965
|
+
while (listStack.length > 0) {
|
|
966
|
+
if (lastListItem) {
|
|
967
|
+
processedHtml += "</li>\n";
|
|
968
|
+
lastListItem = "";
|
|
969
|
+
}
|
|
970
|
+
const closing = listStack.pop();
|
|
971
|
+
if (!closing) break;
|
|
972
|
+
processedHtml += closing.type === "ol" ? "</ol>\n" : "</ul>\n";
|
|
973
|
+
if (listStack.length > 0) processedHtml += "</li>\n";
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
processedHtml += `${line}
|
|
977
|
+
`;
|
|
978
|
+
}
|
|
979
|
+
while (listStack.length > 0) {
|
|
980
|
+
if (lastListItem) {
|
|
981
|
+
processedHtml += "</li>\n";
|
|
982
|
+
lastListItem = "";
|
|
983
|
+
}
|
|
984
|
+
const closing = listStack.pop();
|
|
985
|
+
if (!closing) break;
|
|
986
|
+
processedHtml += closing.type === "ol" ? "</ol>\n" : "</ul>\n";
|
|
987
|
+
if (listStack.length > 0) processedHtml += "</li>\n";
|
|
988
|
+
}
|
|
989
|
+
html = processedHtml;
|
|
990
|
+
html = html.replace(/^> (.+)$/gm, '<blockquote class="matrx-blockquote">$1</blockquote>');
|
|
991
|
+
html = html.replace(
|
|
992
|
+
/```([^`]+)```/gs,
|
|
993
|
+
'<pre class="matrx-code-block"><code class="matrx-code">$1</code></pre>'
|
|
994
|
+
);
|
|
995
|
+
html = html.replace(/`([^`]+)`/g, '<code class="matrx-inline-code">$1</code>');
|
|
996
|
+
html = convertMarkdownTables(html);
|
|
997
|
+
html = html.replace(/<table>/g, '<table class="matrx-table">').replace(/<thead>/g, '<thead class="matrx-table-head">').replace(/<tbody>/g, '<tbody class="matrx-table-body">').replace(/<tr>/g, '<tr class="matrx-table-row">').replace(/<th>/g, '<th class="matrx-table-header">').replace(/<td>/g, '<td class="matrx-table-cell">');
|
|
998
|
+
html = html.replace(/<img([^>]*)>/g, '<img class="matrx-image"$1>');
|
|
999
|
+
html = html.replace(/<div(?!\s+class="matrx-)([^>]*)>/g, '<div class="matrx-div"$1>');
|
|
1000
|
+
html = html.replace(/<span([^>]*)>/g, '<span class="matrx-span"$1>');
|
|
1001
|
+
html = html.replace(/^([^<\n].+)$/gm, '<p class="matrx-paragraph">$1</p>');
|
|
1002
|
+
html = html.replace(
|
|
1003
|
+
/<\/p>\s*<p class="matrx-paragraph">/g,
|
|
1004
|
+
'</p><p class="matrx-paragraph">'
|
|
1005
|
+
);
|
|
1006
|
+
html = html.replace(
|
|
1007
|
+
/(<h1 class="matrx-h1">[\s\S]*?<\/h1>\s*)<p class="matrx-paragraph">([\s\S]*?)<\/p>/g,
|
|
1008
|
+
'$1<p class="matrx-intro">$2</p>'
|
|
1009
|
+
);
|
|
1010
|
+
html = html.replace(
|
|
1011
|
+
/^<strong class="matrx-strong">([^<]*\?[^<]*)<\/strong>$/gm,
|
|
1012
|
+
'<h3 class="matrx-h3">$1</h3>'
|
|
1013
|
+
);
|
|
1014
|
+
html = html.replace(
|
|
1015
|
+
/<p class="matrx-paragraph"><strong class="matrx-strong">([^<]*\?[^<]*)<\/strong><\/p>/g,
|
|
1016
|
+
'<h3 class="matrx-h3">$1</h3>'
|
|
1017
|
+
);
|
|
1018
|
+
html = html.replace(
|
|
1019
|
+
/<h3 class="matrx-h3">([^<]*\?[^<]*)<\/h3>/g,
|
|
1020
|
+
'<div class="matrx-faq-question">$1</div>'
|
|
1021
|
+
);
|
|
1022
|
+
html = html.replace(
|
|
1023
|
+
/(<div class="matrx-faq-question">[^<]*<\/div>)\s*(<p class="matrx-paragraph">[\s\S]*?<\/p>)/g,
|
|
1024
|
+
'<div class="matrx-faq-item">$1<div class="matrx-faq-answer">$2</div></div>'
|
|
1025
|
+
);
|
|
1026
|
+
html = html.replace(
|
|
1027
|
+
/(<div class="matrx-faq-question">[^<]*<\/div>)(?!\s*<div class="matrx-faq-answer">)/g,
|
|
1028
|
+
'<div class="matrx-faq-item">$1<div class="matrx-faq-answer"></div></div>'
|
|
1029
|
+
);
|
|
1030
|
+
html = html.replace(
|
|
1031
|
+
/(<div class="matrx-faq-answer">)<p class="matrx-paragraph">([\s\S]*?)<\/p>(<\/div>)/g,
|
|
1032
|
+
"$1$2$3"
|
|
1033
|
+
);
|
|
1034
|
+
for (const { placeholder, html: imageHtml } of imagePlaceholders) {
|
|
1035
|
+
if (html.includes(placeholder)) html = html.replaceAll(placeholder, imageHtml);
|
|
1036
|
+
}
|
|
1037
|
+
html = html.replace(/<p class="matrx-paragraph">\s*(<img[^>]*>)\s*<\/p>/g, "$1");
|
|
1038
|
+
for (const { placeholder, html: linkHtml } of linkPlaceholders) {
|
|
1039
|
+
if (html.includes(placeholder)) html = html.replaceAll(placeholder, linkHtml);
|
|
1040
|
+
}
|
|
1041
|
+
for (const { placeholder, html: cardHtml } of flashcardPlaceholders) {
|
|
1042
|
+
if (html.includes(placeholder)) html = html.replaceAll(placeholder, cardHtml);
|
|
1043
|
+
}
|
|
1044
|
+
return startWrapper + html + endWrapper;
|
|
1045
|
+
}
|
|
1046
|
+
function convertArticleTables(html) {
|
|
1047
|
+
const tableRegex = /^(\|.*\|)\s*\n(\|[-\s:|]*\|)\s*\n((?:\|.*\|\s*\n?)*)/gm;
|
|
1048
|
+
return html.replace(
|
|
1049
|
+
tableRegex,
|
|
1050
|
+
(_match, headerRow, _sep, bodyRows) => {
|
|
1051
|
+
const headers = headerRow.split("|").map((c) => c.trim()).filter((c) => c !== "");
|
|
1052
|
+
const rows = bodyRows.trim().split("\n").filter((r) => r.trim()).map(
|
|
1053
|
+
(r) => r.split("|").map((c) => c.trim()).filter((c) => c !== "")
|
|
1054
|
+
);
|
|
1055
|
+
let t = '<table class="print-table">\n';
|
|
1056
|
+
if (headers.length) {
|
|
1057
|
+
t += `<thead><tr>${headers.map((h) => `<th>${h}</th>`).join("")}</tr></thead>
|
|
1058
|
+
`;
|
|
1059
|
+
}
|
|
1060
|
+
if (rows.length) {
|
|
1061
|
+
t += `<tbody>${rows.map(
|
|
1062
|
+
(r) => r.length ? `<tr>${r.map((c) => `<td>${c}</td>`).join("")}</tr>` : ""
|
|
1063
|
+
).join("\n")}</tbody>
|
|
1064
|
+
`;
|
|
1065
|
+
}
|
|
1066
|
+
return `${t}</table>
|
|
1067
|
+
`;
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
function markdownToArticleHtml(markdown, options = {}) {
|
|
1072
|
+
if (!markdown) {
|
|
1073
|
+
options.onNotice?.({
|
|
1074
|
+
code: "empty-output",
|
|
1075
|
+
message: "markdownToArticleHtml received an empty string.",
|
|
1076
|
+
remedy: "Check the content is loaded before printing; nothing was rendered."
|
|
1077
|
+
});
|
|
1078
|
+
return "";
|
|
1079
|
+
}
|
|
1080
|
+
let html = options.includeThinking ? markdown : removeThinkingContent(markdown);
|
|
1081
|
+
html = convertArticleTables(html);
|
|
1082
|
+
const codeBlockPlaceholders = [];
|
|
1083
|
+
let codeIdx = 0;
|
|
1084
|
+
html = html.replace(
|
|
1085
|
+
/```(\w*)\n?([\s\S]*?)```/g,
|
|
1086
|
+
(_m, lang, code) => {
|
|
1087
|
+
const ph = `\u03A9CODEBLOCK\u03A9${codeIdx}\u03A9CODEBLOCK\u03A9`;
|
|
1088
|
+
const langLabel = lang ? `<span class="code-lang">${lang}</span>` : "";
|
|
1089
|
+
codeBlockPlaceholders.push({
|
|
1090
|
+
placeholder: ph,
|
|
1091
|
+
html: `<div class="code-block-wrapper">${langLabel}<pre class="code-block"><code>${escapeHtml(
|
|
1092
|
+
code.trim()
|
|
1093
|
+
)}</code></pre></div>`
|
|
1094
|
+
});
|
|
1095
|
+
codeIdx++;
|
|
1096
|
+
return ph;
|
|
1097
|
+
}
|
|
1098
|
+
);
|
|
1099
|
+
const linkPlaceholders = [];
|
|
1100
|
+
let linkIdx = 0;
|
|
1101
|
+
html = html.replace(
|
|
1102
|
+
/\[([^\]]+)\]\(([^)]+)\)/g,
|
|
1103
|
+
(_m, text, url) => {
|
|
1104
|
+
const ph = `\u03A9LINK\u03A9${linkIdx}\u03A9LINK\u03A9`;
|
|
1105
|
+
linkPlaceholders.push({ placeholder: ph, html: `<a href="${url}">${text}</a>` });
|
|
1106
|
+
linkIdx++;
|
|
1107
|
+
return ph;
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1110
|
+
html = html.replace(/^#{6}\s+(.+)$/gm, "<h6>$1</h6>").replace(/^#{5}\s+(.+)$/gm, "<h5>$1</h5>").replace(/^#{4}\s+(.+)$/gm, "<h4>$1</h4>").replace(/^#{3}\s+(.+)$/gm, "<h3>$1</h3>").replace(/^#{2}\s+(.+)$/gm, "<h2>$1</h2>").replace(/^#{1}\s+(.+)$/gm, "<h1>$1</h1>");
|
|
1111
|
+
html = html.replace(/^> (.+)$/gm, "<blockquote>$1</blockquote>");
|
|
1112
|
+
html = html.replace(/^[-*_]{3,}$/gm, "<hr>");
|
|
1113
|
+
html = html.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>").replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/___(.+?)___/g, "<strong><em>$1</em></strong>").replace(/__(.+?)__/g, "<strong>$1</strong>").replace(/_([^_\s][^_]*)_/g, "<em>$1</em>");
|
|
1114
|
+
html = html.replace(/`([^`]+)`/g, '<code class="inline-code">$1</code>');
|
|
1115
|
+
const lines = html.split("\n");
|
|
1116
|
+
const result = [];
|
|
1117
|
+
let inUl = false;
|
|
1118
|
+
let inOl = false;
|
|
1119
|
+
for (const line of lines) {
|
|
1120
|
+
const ulMatch = line.match(/^(\s*)[-*+]\s+(.+)$/);
|
|
1121
|
+
const olMatch = line.match(/^(\s*)\d+\.\s+(.+)$/);
|
|
1122
|
+
if (ulMatch) {
|
|
1123
|
+
if (inOl) {
|
|
1124
|
+
result.push("</ol>");
|
|
1125
|
+
inOl = false;
|
|
1126
|
+
}
|
|
1127
|
+
if (!inUl) {
|
|
1128
|
+
result.push("<ul>");
|
|
1129
|
+
inUl = true;
|
|
1130
|
+
}
|
|
1131
|
+
result.push(`<li>${ulMatch[2] ?? ""}</li>`);
|
|
1132
|
+
} else if (olMatch) {
|
|
1133
|
+
if (inUl) {
|
|
1134
|
+
result.push("</ul>");
|
|
1135
|
+
inUl = false;
|
|
1136
|
+
}
|
|
1137
|
+
if (!inOl) {
|
|
1138
|
+
result.push("<ol>");
|
|
1139
|
+
inOl = true;
|
|
1140
|
+
}
|
|
1141
|
+
result.push(`<li>${olMatch[2] ?? ""}</li>`);
|
|
1142
|
+
} else {
|
|
1143
|
+
if (inUl) {
|
|
1144
|
+
result.push("</ul>");
|
|
1145
|
+
inUl = false;
|
|
1146
|
+
}
|
|
1147
|
+
if (inOl) {
|
|
1148
|
+
result.push("</ol>");
|
|
1149
|
+
inOl = false;
|
|
1150
|
+
}
|
|
1151
|
+
result.push(line);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
if (inUl) result.push("</ul>");
|
|
1155
|
+
if (inOl) result.push("</ol>");
|
|
1156
|
+
html = result.join("\n");
|
|
1157
|
+
html = html.split("\n").map((line) => {
|
|
1158
|
+
const t = line.trim();
|
|
1159
|
+
if (!t) return "";
|
|
1160
|
+
if (/^<(h[1-6]|ul|ol|li|blockquote|pre|hr|table|thead|tbody|tr|th|td|div|ΩCODE)/.test(t)) {
|
|
1161
|
+
return line;
|
|
1162
|
+
}
|
|
1163
|
+
return `<p>${t}</p>`;
|
|
1164
|
+
}).join("\n");
|
|
1165
|
+
for (const { placeholder, html: ph } of codeBlockPlaceholders) {
|
|
1166
|
+
html = html.replace(`<p>${placeholder}</p>`, ph);
|
|
1167
|
+
html = html.replace(placeholder, ph);
|
|
1168
|
+
}
|
|
1169
|
+
for (const { placeholder, html: ph } of linkPlaceholders) {
|
|
1170
|
+
html = html.replaceAll(placeholder, ph);
|
|
1171
|
+
}
|
|
1172
|
+
return html;
|
|
1173
|
+
}
|
|
1174
|
+
var PRINT_ACTIONS_CSS = `
|
|
1175
|
+
.print-actions { display: flex; gap: 10px; margin: 0 auto 28px; max-width: 800px; padding: 0 2rem 20px; border-bottom: 2px solid var(--matrx-print-border, #e1e1e1); }
|
|
1176
|
+
.print-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 20px; border-radius: 8px; font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; cursor: pointer; border: none; font-weight: 600; }
|
|
1177
|
+
.print-btn-primary { background: var(--matrx-print-accent, #667eea); color: var(--matrx-print-bg, #ffffff); }
|
|
1178
|
+
.print-btn-secondary { background: var(--matrx-print-surface, #f8f9fa); color: var(--matrx-print-fg-strong, #374151); border: 1px solid var(--matrx-print-border-muted, #d1d5db); }
|
|
1179
|
+
@media print { .print-actions { display: none !important; } }
|
|
1180
|
+
`;
|
|
1181
|
+
function getMarkdownStylesheet(options = {}) {
|
|
1182
|
+
const skin = options.skin ?? "document";
|
|
1183
|
+
const base = skin === "article" ? `${MARKDOWN_ARTICLE_TOKENS_CSS}
|
|
1184
|
+
${MARKDOWN_ARTICLE_CSS}` : `${MARKDOWN_DOCUMENT_TOKENS_CSS}
|
|
1185
|
+
${MARKDOWN_DOCUMENT_CSS}`;
|
|
1186
|
+
return [base, options.tokens ?? "", options.extraCss ?? ""].filter((part) => part.trim().length > 0).join("\n");
|
|
1187
|
+
}
|
|
1188
|
+
function markdownToHtmlForSkin(markdown, skin, options = {}) {
|
|
1189
|
+
return skin === "article" ? markdownToArticleHtml(markdown, options) : markdownToHtml(markdown, options);
|
|
1190
|
+
}
|
|
1191
|
+
function renderMarkdownDocument(markdown, options = {}) {
|
|
1192
|
+
const skin = options.skin ?? "document";
|
|
1193
|
+
const title = options.title ?? "AI Response";
|
|
1194
|
+
const convert = options.convertToHtml ?? ((md) => markdownToHtmlForSkin(
|
|
1195
|
+
md,
|
|
1196
|
+
skin,
|
|
1197
|
+
options.onNotice ? { onNotice: options.onNotice } : {}
|
|
1198
|
+
));
|
|
1199
|
+
const bodyHtml = convert(markdown);
|
|
1200
|
+
const css = options.css ?? getMarkdownStylesheet({
|
|
1201
|
+
skin,
|
|
1202
|
+
...options.tokens === void 0 ? {} : { tokens: options.tokens },
|
|
1203
|
+
...options.extraCss === void 0 ? {} : { extraCss: options.extraCss }
|
|
1204
|
+
});
|
|
1205
|
+
const chrome = options.withPrintActions && skin !== "article" ? PRINT_ACTIONS_CSS : "";
|
|
1206
|
+
const actions = options.withPrintActions ? '<div class="print-actions"><button class="print-btn print-btn-primary" onclick="window.print()">Print / Save as PDF</button><button class="print-btn print-btn-secondary" onclick="window.close()">Close</button></div>' : "";
|
|
1207
|
+
return `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>${escapeHtml(
|
|
1208
|
+
title
|
|
1209
|
+
)}</title>
|
|
1210
|
+
<style>${css}${chrome}</style></head>
|
|
1211
|
+
<body>${actions}<div class="content">${bodyHtml}</div></body></html>`;
|
|
1212
|
+
}
|
|
1213
|
+
function printMarkdown(markdown, options = {}) {
|
|
1214
|
+
const title = options.title ?? "AI Response";
|
|
1215
|
+
const doc = renderMarkdownDocument(markdown, {
|
|
1216
|
+
...options,
|
|
1217
|
+
title,
|
|
1218
|
+
withPrintActions: options.withPrintActions ?? true
|
|
1219
|
+
});
|
|
1220
|
+
return options.windowFeatures === void 0 ? openPrintWindow(doc, title) : openPrintWindow(doc, title, options.windowFeatures);
|
|
1221
|
+
}
|
|
1222
|
+
export {
|
|
1223
|
+
MARKDOWN_ARTICLE_CSS,
|
|
1224
|
+
MARKDOWN_ARTICLE_TOKENS_CSS,
|
|
1225
|
+
MARKDOWN_DOCUMENT_CSS,
|
|
1226
|
+
MARKDOWN_DOCUMENT_TOKENS_CSS,
|
|
1227
|
+
PRINT_ACTIONS_CSS,
|
|
1228
|
+
getMarkdownStylesheet,
|
|
1229
|
+
hasThinkingContent,
|
|
1230
|
+
markdownToArticleHtml,
|
|
1231
|
+
markdownToHtml,
|
|
1232
|
+
markdownToHtmlForSkin,
|
|
1233
|
+
printMarkdown,
|
|
1234
|
+
removeThinkingContent,
|
|
1235
|
+
renderMarkdownDocument
|
|
1236
|
+
};
|
|
1237
|
+
//# sourceMappingURL=markdown.js.map
|