@mdream/js 2.0.0-beta.1 → 2.0.0
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/README.md +402 -126
- package/dist/_chunks/clean.mjs +526 -0
- package/dist/_chunks/const.mjs +3 -7
- package/dist/_chunks/extraction.d.mts +14 -0
- package/dist/_chunks/html.mjs +260 -0
- package/dist/_chunks/markdown-processor.mjs +1077 -828
- package/dist/_chunks/minimal.mjs +29 -0
- package/dist/_chunks/output-runner.mjs +54 -0
- package/dist/_chunks/parse.mjs +133 -1500
- package/dist/_chunks/plugin.mjs +14 -0
- package/dist/_chunks/src.mjs +291 -0
- package/dist/_chunks/tag-overrides.mjs +138 -0
- package/dist/_chunks/{plugins.mjs → tailwind.mjs} +145 -292
- package/dist/_chunks/text.mjs +583 -0
- package/dist/_chunks/types.d.mts +136 -126
- package/dist/_chunks/url.mjs +82 -0
- package/dist/_chunks/utils.mjs +659 -0
- package/dist/clean.d.mts +10 -0
- package/dist/clean.mjs +2 -0
- package/dist/cli.mjs +47 -8
- package/dist/html.d.mts +6 -0
- package/dist/html.mjs +2 -0
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +4 -58
- package/dist/parse.d.mts +15 -10
- package/dist/plugins.d.mts +13 -28
- package/dist/plugins.mjs +52 -2
- package/dist/preset/minimal.d.mts +14 -2
- package/dist/preset/minimal.mjs +1 -32
- package/dist/splitter.d.mts +12 -4
- package/dist/splitter.mjs +355 -113
- package/dist/text.d.mts +6 -0
- package/dist/text.mjs +2 -0
- package/package.json +33 -7
- package/dist/_chunks/index.d.mts +0 -9
- package/dist/_chunks/minimal.d.mts +0 -6
- package/dist/_chunks/resolve-plugins.mjs +0 -44
- package/dist/_chunks/stream.mjs +0 -37
- package/dist/core.d.mts +0 -15
- package/dist/core.mjs +0 -28
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TagIdMap } from "./const.mjs";
|
|
2
|
-
|
|
3
|
-
return plugin;
|
|
4
|
-
}
|
|
2
|
+
import { createPlugin } from "./plugin.mjs";
|
|
5
3
|
function createTagSelector(tagName) {
|
|
6
4
|
return {
|
|
7
5
|
matches: (element) => element.name === tagName,
|
|
@@ -154,118 +152,7 @@ function parseSelector(selector) {
|
|
|
154
152
|
selectors.push(parseCompoundSelector(last));
|
|
155
153
|
return createSelectorList(selectors);
|
|
156
154
|
}
|
|
157
|
-
function extractionPlugin(selectors) {
|
|
158
|
-
const matcherCallbacks = Object.entries(selectors).map(([selector, callback]) => ({
|
|
159
|
-
matcher: parseSelector(selector),
|
|
160
|
-
callback
|
|
161
|
-
}));
|
|
162
|
-
const trackedElements = /* @__PURE__ */ new Map();
|
|
163
|
-
return createPlugin({
|
|
164
|
-
onNodeEnter(element) {
|
|
165
|
-
let callbacks;
|
|
166
|
-
for (let i = 0; i < matcherCallbacks.length; i++) {
|
|
167
|
-
const { matcher, callback } = matcherCallbacks[i];
|
|
168
|
-
if (matcher.matches(element)) {
|
|
169
|
-
callbacks ||= [];
|
|
170
|
-
callbacks.push(callback);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (callbacks) trackedElements.set(element, {
|
|
174
|
-
textContent: "",
|
|
175
|
-
callbacks
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
processTextNode(textNode) {
|
|
179
|
-
let currentParent = textNode.parent;
|
|
180
|
-
while (currentParent) {
|
|
181
|
-
const tracked = trackedElements.get(currentParent);
|
|
182
|
-
if (tracked) tracked.textContent += textNode.value;
|
|
183
|
-
currentParent = currentParent.parent;
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
onNodeExit(element, state) {
|
|
187
|
-
const tracked = trackedElements.get(element);
|
|
188
|
-
if (tracked) {
|
|
189
|
-
for (let i = 0; i < tracked.callbacks.length; i++) {
|
|
190
|
-
const extractedElement = {
|
|
191
|
-
...element,
|
|
192
|
-
attributes: { ...element.attributes },
|
|
193
|
-
textContent: tracked.textContent.trim()
|
|
194
|
-
};
|
|
195
|
-
tracked.callbacks[i](extractedElement, state);
|
|
196
|
-
}
|
|
197
|
-
trackedElements.delete(element);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function extractionCollectorPlugin(config) {
|
|
203
|
-
const matchers = Object.entries(config).map(([selector, callback]) => ({
|
|
204
|
-
selector,
|
|
205
|
-
matcher: parseSelector(selector),
|
|
206
|
-
callback
|
|
207
|
-
}));
|
|
208
|
-
const results = [];
|
|
209
|
-
const trackedElements = /* @__PURE__ */ new Map();
|
|
210
|
-
const plugin = createPlugin({
|
|
211
|
-
onNodeEnter(element) {
|
|
212
|
-
let selectors;
|
|
213
|
-
for (let i = 0; i < matchers.length; i++) {
|
|
214
|
-
const m = matchers[i];
|
|
215
|
-
if (m.matcher.matches(element)) {
|
|
216
|
-
selectors ||= [];
|
|
217
|
-
selectors.push(m.selector);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (selectors) trackedElements.set(element, {
|
|
221
|
-
textContent: "",
|
|
222
|
-
selectors
|
|
223
|
-
});
|
|
224
|
-
},
|
|
225
|
-
processTextNode(textNode) {
|
|
226
|
-
let currentParent = textNode.parent;
|
|
227
|
-
while (currentParent) {
|
|
228
|
-
const tracked = trackedElements.get(currentParent);
|
|
229
|
-
if (tracked) tracked.textContent += textNode.value;
|
|
230
|
-
currentParent = currentParent.parent;
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
onNodeExit(element) {
|
|
234
|
-
const tracked = trackedElements.get(element);
|
|
235
|
-
if (tracked) {
|
|
236
|
-
for (let i = 0; i < tracked.selectors.length; i++) {
|
|
237
|
-
const extracted = {
|
|
238
|
-
selector: tracked.selectors[i],
|
|
239
|
-
tagName: element.name,
|
|
240
|
-
textContent: tracked.textContent.trim(),
|
|
241
|
-
attributes: { ...element.attributes }
|
|
242
|
-
};
|
|
243
|
-
results.push(extracted);
|
|
244
|
-
}
|
|
245
|
-
trackedElements.delete(element);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
function callHandlers() {
|
|
250
|
-
for (let i = 0; i < results.length; i++) {
|
|
251
|
-
const el = results[i];
|
|
252
|
-
for (let j = 0; j < matchers.length; j++) if (matchers[j].selector === el.selector) {
|
|
253
|
-
matchers[j].callback(el);
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
plugin,
|
|
260
|
-
getResults: () => results,
|
|
261
|
-
callHandlers
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
155
|
function compileSelector(selector) {
|
|
265
|
-
if (typeof selector === "number") return {
|
|
266
|
-
matches: (element) => element.tagId === selector,
|
|
267
|
-
toString: () => String(selector)
|
|
268
|
-
};
|
|
269
156
|
const tagId = TagIdMap[selector];
|
|
270
157
|
if (tagId !== void 0) return {
|
|
271
158
|
matches: (element) => element.tagId === tagId,
|
|
@@ -273,6 +160,15 @@ function compileSelector(selector) {
|
|
|
273
160
|
};
|
|
274
161
|
return parseSelector(selector);
|
|
275
162
|
}
|
|
163
|
+
function compileSelectors(key, selectors) {
|
|
164
|
+
if (!selectors) return [];
|
|
165
|
+
const matchers = [];
|
|
166
|
+
for (const selector of selectors) {
|
|
167
|
+
if (typeof selector !== "string") throw new TypeError(`filterPlugin takes \`${key}\` entries as strings. Pass the tag name or a CSS selector, such as 'form'.`);
|
|
168
|
+
matchers.push(compileSelector(selector));
|
|
169
|
+
}
|
|
170
|
+
return matchers;
|
|
171
|
+
}
|
|
276
172
|
function isHidden(element) {
|
|
277
173
|
const style = element.attributes?.style;
|
|
278
174
|
if (style && (style.includes("display:none") || style.includes("display: none") || style.includes("visibility:hidden") || style.includes("visibility: hidden") || style.includes("position:absolute") || style.includes("position: absolute") || style.includes("position:fixed") || style.includes("position: fixed"))) return true;
|
|
@@ -280,8 +176,8 @@ function isHidden(element) {
|
|
|
280
176
|
return hidden !== void 0 && hidden.toLowerCase() !== "until-found";
|
|
281
177
|
}
|
|
282
178
|
function filterPlugin(options = {}) {
|
|
283
|
-
const includeSelectors = options.include
|
|
284
|
-
const excludeSelectors = options.exclude
|
|
179
|
+
const includeSelectors = compileSelectors("include", options.include);
|
|
180
|
+
const excludeSelectors = compileSelectors("exclude", options.exclude);
|
|
285
181
|
const processChildren = options.processChildren !== false;
|
|
286
182
|
const skippedSubtrees = /* @__PURE__ */ new WeakSet();
|
|
287
183
|
const skippedByInclude = /* @__PURE__ */ new WeakSet();
|
|
@@ -322,8 +218,10 @@ function filterPlugin(options = {}) {
|
|
|
322
218
|
}
|
|
323
219
|
const BACKSLASH_RE = /\\/g;
|
|
324
220
|
const DOUBLE_QUOTE_RE = /"/g;
|
|
325
|
-
const ESCAPED_DOUBLE_QUOTE_RE = /\\"/g;
|
|
326
221
|
function frontmatterPlugin(options = {}) {
|
|
222
|
+
return createPlugin(() => createFrontmatterHooks(options));
|
|
223
|
+
}
|
|
224
|
+
function createFrontmatterHooks(options) {
|
|
327
225
|
const additionalFields = options.additionalFields || {};
|
|
328
226
|
const metaFields = /* @__PURE__ */ new Set([
|
|
329
227
|
"description",
|
|
@@ -346,22 +244,37 @@ function frontmatterPlugin(options = {}) {
|
|
|
346
244
|
if (value.includes("\n") || value.includes(":") || value.includes("#") || value.includes(" ")) return `"${value}"`;
|
|
347
245
|
return value;
|
|
348
246
|
}
|
|
247
|
+
function rawValue(value) {
|
|
248
|
+
const content = value.startsWith("\"") && value.endsWith("\"") ? value.slice(1, -1) : value;
|
|
249
|
+
let result = "";
|
|
250
|
+
for (let index = 0; index < content.length; index++) {
|
|
251
|
+
const character = content[index];
|
|
252
|
+
const next = content[index + 1];
|
|
253
|
+
if (character === "\\" && (next === "\\" || next === "\"")) {
|
|
254
|
+
result += next;
|
|
255
|
+
index++;
|
|
256
|
+
} else result += character;
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
349
260
|
function getStructuredData() {
|
|
350
261
|
const result = {};
|
|
351
262
|
if (frontmatter.title) {
|
|
352
263
|
const raw = frontmatter.title;
|
|
353
|
-
result.title =
|
|
354
|
-
}
|
|
355
|
-
for (const [k, v] of Object.entries(frontmatter.meta)) {
|
|
356
|
-
const cleanKey = k.startsWith("\"") && k.endsWith("\"") ? k.slice(1, -1) : k;
|
|
357
|
-
result[cleanKey] = typeof v === "string" && v.startsWith("\"") && v.endsWith("\"") ? v.slice(1, -1).replace(ESCAPED_DOUBLE_QUOTE_RE, "\"") : String(v);
|
|
264
|
+
result.title = rawValue(raw);
|
|
358
265
|
}
|
|
266
|
+
for (const [k, v] of Object.entries(frontmatter.meta)) result[k] = rawValue(String(v));
|
|
359
267
|
if (additionalFields) {
|
|
360
268
|
for (const [k, v] of Object.entries(additionalFields)) if (typeof v === "string") result[k] = v;
|
|
361
269
|
}
|
|
362
270
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
363
271
|
}
|
|
364
|
-
|
|
272
|
+
return createPlugin({
|
|
273
|
+
onDocumentEnd() {
|
|
274
|
+
if (!options.onExtract) return;
|
|
275
|
+
const structured = getStructuredData();
|
|
276
|
+
if (structured) options.onExtract(structured);
|
|
277
|
+
},
|
|
365
278
|
onNodeEnter(node) {
|
|
366
279
|
if (node.excludedFromMarkdown) return;
|
|
367
280
|
if (node.tagId === 1) {
|
|
@@ -372,7 +285,7 @@ function frontmatterPlugin(options = {}) {
|
|
|
372
285
|
if (inHead && node.type === 1 && node.tagId === 5) {
|
|
373
286
|
const { name, property, content } = node.attributes || {};
|
|
374
287
|
const metaName = property || name;
|
|
375
|
-
if (metaName && content && metaFields.has(metaName)) frontmatter.meta[metaName
|
|
288
|
+
if (metaName && content && metaFields.has(metaName)) frontmatter.meta[metaName] = formatValue(metaName, content);
|
|
376
289
|
return;
|
|
377
290
|
}
|
|
378
291
|
},
|
|
@@ -380,12 +293,13 @@ function frontmatterPlugin(options = {}) {
|
|
|
380
293
|
if (node.excludedFromMarkdown) return void 0;
|
|
381
294
|
if (node.type === 1 && node.tagId === 1) {
|
|
382
295
|
inHead = false;
|
|
383
|
-
if (state.
|
|
296
|
+
if (state.outputFormat !== "markdown") return void 0;
|
|
384
297
|
if (Object.keys(frontmatter).length > 0) {
|
|
385
298
|
const frontmatterContent = generateFrontmatter();
|
|
386
299
|
if (frontmatterContent) {
|
|
387
|
-
state
|
|
388
|
-
|
|
300
|
+
const output = state;
|
|
301
|
+
output.buffer.push(frontmatterContent);
|
|
302
|
+
output.lastContentCache = frontmatterContent;
|
|
389
303
|
}
|
|
390
304
|
}
|
|
391
305
|
}
|
|
@@ -403,11 +317,9 @@ function frontmatterPlugin(options = {}) {
|
|
|
403
317
|
}
|
|
404
318
|
}
|
|
405
319
|
});
|
|
406
|
-
plugin.getFrontmatter = getStructuredData;
|
|
407
|
-
return plugin;
|
|
408
320
|
function generateFrontmatter() {
|
|
409
321
|
if (Object.keys(frontmatter).length === 0) return "";
|
|
410
|
-
|
|
322
|
+
const yamlLines = [];
|
|
411
323
|
const entries = Object.entries(frontmatter).sort(([a], [b]) => {
|
|
412
324
|
if (a === "title") return -1;
|
|
413
325
|
if (b === "title") return 1;
|
|
@@ -417,31 +329,26 @@ function frontmatterPlugin(options = {}) {
|
|
|
417
329
|
});
|
|
418
330
|
for (const [key, value] of entries) if (key === "meta" && typeof value === "object" && value && Object.keys(value).length > 0) {
|
|
419
331
|
yamlLines.push("meta:");
|
|
420
|
-
const metaEntries = Object.entries(value).sort(([a], [b]) => a
|
|
332
|
+
const metaEntries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([metaKey, metaValue]) => ` ${metaKey.includes(":") ? `"${metaKey}"` : metaKey}: ${metaValue}`);
|
|
421
333
|
yamlLines.push(...metaEntries);
|
|
422
334
|
} else if (key !== "meta" && typeof value === "string") yamlLines.push(`${key}: ${value}`);
|
|
423
|
-
if (
|
|
335
|
+
if (yamlLines.length === 0) return "";
|
|
424
336
|
return `---\n${yamlLines.join("\n")}\n---\n\n`;
|
|
425
337
|
}
|
|
426
338
|
}
|
|
427
339
|
function isolateMainPlugin() {
|
|
340
|
+
return createPlugin(createIsolateMainHooks);
|
|
341
|
+
}
|
|
342
|
+
function createIsolateMainHooks() {
|
|
428
343
|
let mainElement = null;
|
|
429
344
|
let firstHeaderElement = null;
|
|
430
345
|
let afterFooter = false;
|
|
431
|
-
const headerTagIds = /* @__PURE__ */ new Set([
|
|
432
|
-
7,
|
|
433
|
-
8,
|
|
434
|
-
9,
|
|
435
|
-
10,
|
|
436
|
-
11,
|
|
437
|
-
12
|
|
438
|
-
]);
|
|
439
346
|
return createPlugin({ beforeNodeProcess(event) {
|
|
440
347
|
const { node } = event;
|
|
441
348
|
if (node.excludedFromMarkdown || node.parent?.excludedFromMarkdown) return;
|
|
442
349
|
if (node.type === 1) {
|
|
443
350
|
const element = node;
|
|
444
|
-
if (!mainElement && element.tagId === 104 && element.depth <=
|
|
351
|
+
if (!mainElement && element.tagId === 104 && element.depth <= 50) {
|
|
445
352
|
mainElement = element;
|
|
446
353
|
return;
|
|
447
354
|
}
|
|
@@ -458,7 +365,7 @@ function isolateMainPlugin() {
|
|
|
458
365
|
if (!isInsideMain) return { skip: true };
|
|
459
366
|
return;
|
|
460
367
|
}
|
|
461
|
-
if (!firstHeaderElement && element.tagId !== void 0 &&
|
|
368
|
+
if (!firstHeaderElement && element.tagId !== void 0 && element.tagId >= 7 && element.tagId <= 12) {
|
|
462
369
|
let current = element.parent;
|
|
463
370
|
let isInHeaderTag = false;
|
|
464
371
|
while (current) {
|
|
@@ -515,158 +422,104 @@ function isolateMainPlugin() {
|
|
|
515
422
|
}
|
|
516
423
|
} });
|
|
517
424
|
}
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
suffix: "**"
|
|
522
|
-
},
|
|
523
|
-
"font-semibold": {
|
|
524
|
-
prefix: "**",
|
|
525
|
-
suffix: "**"
|
|
526
|
-
},
|
|
527
|
-
"font-black": {
|
|
528
|
-
prefix: "**",
|
|
529
|
-
suffix: "**"
|
|
530
|
-
},
|
|
531
|
-
"font-extrabold": {
|
|
532
|
-
prefix: "**",
|
|
533
|
-
suffix: "**"
|
|
534
|
-
},
|
|
535
|
-
"font-medium": {
|
|
536
|
-
prefix: "**",
|
|
537
|
-
suffix: "**"
|
|
538
|
-
},
|
|
539
|
-
"font-italic": {
|
|
540
|
-
prefix: "*",
|
|
541
|
-
suffix: "*"
|
|
542
|
-
},
|
|
543
|
-
"italic": {
|
|
544
|
-
prefix: "*",
|
|
545
|
-
suffix: "*"
|
|
546
|
-
},
|
|
547
|
-
"line-through": {
|
|
548
|
-
prefix: "~~",
|
|
549
|
-
suffix: "~~"
|
|
550
|
-
},
|
|
551
|
-
"hidden": { hidden: true },
|
|
552
|
-
"invisible": { hidden: true },
|
|
553
|
-
"absolute": { hidden: true },
|
|
554
|
-
"fixed": { hidden: true },
|
|
555
|
-
"sticky": { hidden: true }
|
|
556
|
-
};
|
|
557
|
-
function extractBaseClass(className) {
|
|
558
|
-
for (const bp of [
|
|
559
|
-
"sm:",
|
|
560
|
-
"md:",
|
|
561
|
-
"lg:",
|
|
562
|
-
"xl:",
|
|
563
|
-
"2xl:"
|
|
564
|
-
]) if (className.startsWith(bp)) return {
|
|
565
|
-
baseClass: className.substring(bp.length),
|
|
566
|
-
breakpoint: bp
|
|
567
|
-
};
|
|
568
|
-
return {
|
|
569
|
-
baseClass: className,
|
|
570
|
-
breakpoint: ""
|
|
571
|
-
};
|
|
425
|
+
const UNSET = -1;
|
|
426
|
+
function isClassSeparator(code) {
|
|
427
|
+
return code === 32 || code >= 9 && code <= 13 || code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288;
|
|
572
428
|
}
|
|
573
|
-
function
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
};
|
|
582
|
-
return classes.toSorted((a, b) => {
|
|
583
|
-
const aBreakpoint = extractBaseClass(a).breakpoint;
|
|
584
|
-
const bBreakpoint = extractBaseClass(b).breakpoint;
|
|
585
|
-
return (breakpointOrder[aBreakpoint] || 0) - (breakpointOrder[bBreakpoint] || 0);
|
|
586
|
-
});
|
|
429
|
+
function breakpointOf(cls) {
|
|
430
|
+
const c = cls.charCodeAt(0);
|
|
431
|
+
if (c === 115 && cls.startsWith("sm:")) return 1;
|
|
432
|
+
if (c === 109 && cls.startsWith("md:")) return 2;
|
|
433
|
+
if (c === 108 && cls.startsWith("lg:")) return 3;
|
|
434
|
+
if (c === 120 && cls.startsWith("xl:")) return 4;
|
|
435
|
+
if (c === 50 && cls.startsWith("2xl:")) return 5;
|
|
436
|
+
return 0;
|
|
587
437
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
for (const cls of sorted) {
|
|
599
|
-
const { baseClass } = extractBaseClass(cls);
|
|
600
|
-
if (baseClass.includes("italic")) groups.emphasis?.push(cls);
|
|
601
|
-
else if (baseClass.includes("font-") || baseClass === "bold") groups.weight?.push(cls);
|
|
602
|
-
else if (baseClass.includes("line-through") || baseClass.includes("underline")) groups.decoration?.push(cls);
|
|
603
|
-
else if (baseClass === "hidden" || baseClass.includes("invisible")) groups.display?.push(cls);
|
|
604
|
-
else if ([
|
|
605
|
-
"absolute",
|
|
606
|
-
"fixed",
|
|
607
|
-
"sticky"
|
|
608
|
-
].includes(baseClass)) groups.position?.push(cls);
|
|
609
|
-
else groups.other?.push(cls);
|
|
610
|
-
}
|
|
611
|
-
return groups;
|
|
612
|
-
}
|
|
613
|
-
function normalizeClasses(classes) {
|
|
614
|
-
const result = [];
|
|
615
|
-
const mobileClasses = classes.filter((cls) => !hasBreakpoint(cls));
|
|
616
|
-
const breakpointClasses = classes.filter((cls) => hasBreakpoint(cls));
|
|
617
|
-
result.push(...mobileClasses);
|
|
618
|
-
result.push(...breakpointClasses);
|
|
619
|
-
return result;
|
|
620
|
-
}
|
|
621
|
-
function hasBreakpoint(className) {
|
|
622
|
-
const { breakpoint } = extractBaseClass(className);
|
|
623
|
-
return breakpoint !== "";
|
|
438
|
+
const BREAKPOINT_PREFIX_LENGTH = [
|
|
439
|
+
0,
|
|
440
|
+
3,
|
|
441
|
+
3,
|
|
442
|
+
3,
|
|
443
|
+
3,
|
|
444
|
+
4
|
|
445
|
+
];
|
|
446
|
+
function supersede(current, breakpoint, enabled) {
|
|
447
|
+
return current === UNSET || breakpoint >= current >> 1 ? breakpoint << 1 | (enabled ? 1 : 0) : current;
|
|
624
448
|
}
|
|
625
|
-
function processTailwindClasses(
|
|
626
|
-
let
|
|
627
|
-
let
|
|
628
|
-
let
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
449
|
+
function processTailwindClasses(classAttr) {
|
|
450
|
+
let weight = UNSET;
|
|
451
|
+
let emphasis = UNSET;
|
|
452
|
+
let decoration = UNSET;
|
|
453
|
+
let displayHidden = UNSET;
|
|
454
|
+
let positionHidden = UNSET;
|
|
455
|
+
const length = classAttr.length;
|
|
456
|
+
let index = 0;
|
|
457
|
+
while (index < length) {
|
|
458
|
+
while (index < length && isClassSeparator(classAttr.charCodeAt(index))) index++;
|
|
459
|
+
if (index >= length) break;
|
|
460
|
+
const start = index;
|
|
461
|
+
while (index < length && !isClassSeparator(classAttr.charCodeAt(index))) index++;
|
|
462
|
+
const cls = classAttr.slice(start, index);
|
|
463
|
+
const breakpoint = breakpointOf(cls);
|
|
464
|
+
const base = breakpoint ? cls.slice(BREAKPOINT_PREFIX_LENGTH[breakpoint]) : cls;
|
|
465
|
+
switch (base) {
|
|
466
|
+
case "italic":
|
|
467
|
+
emphasis = supersede(emphasis, breakpoint, true);
|
|
468
|
+
break;
|
|
469
|
+
case "not-italic":
|
|
470
|
+
emphasis = supersede(emphasis, breakpoint, false);
|
|
471
|
+
break;
|
|
472
|
+
case "font-bold":
|
|
473
|
+
case "font-semibold":
|
|
474
|
+
case "font-black":
|
|
475
|
+
case "font-extrabold":
|
|
476
|
+
case "font-medium":
|
|
477
|
+
case "bold":
|
|
478
|
+
weight = supersede(weight, breakpoint, true);
|
|
479
|
+
break;
|
|
480
|
+
case "line-through":
|
|
481
|
+
case "underline":
|
|
482
|
+
decoration = supersede(decoration, breakpoint, true);
|
|
483
|
+
break;
|
|
484
|
+
case "no-underline":
|
|
485
|
+
decoration = supersede(decoration, breakpoint, false);
|
|
486
|
+
break;
|
|
487
|
+
case "hidden":
|
|
488
|
+
displayHidden = supersede(displayHidden, breakpoint, true);
|
|
489
|
+
break;
|
|
490
|
+
case "block":
|
|
491
|
+
case "flex":
|
|
492
|
+
case "inline":
|
|
493
|
+
displayHidden = supersede(displayHidden, breakpoint, false);
|
|
494
|
+
break;
|
|
495
|
+
case "absolute":
|
|
496
|
+
case "fixed":
|
|
497
|
+
case "sticky":
|
|
498
|
+
positionHidden = supersede(positionHidden, breakpoint, true);
|
|
499
|
+
break;
|
|
500
|
+
case "static":
|
|
501
|
+
case "relative":
|
|
502
|
+
positionHidden = supersede(positionHidden, breakpoint, false);
|
|
503
|
+
break;
|
|
504
|
+
default: if (base.includes("font-")) weight = supersede(weight, breakpoint, false);
|
|
505
|
+
else if (base.includes("invisible")) displayHidden = supersede(displayHidden, breakpoint, true);
|
|
644
506
|
}
|
|
645
507
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (mapping.suffix) suffix = mapping.suffix + suffix;
|
|
652
|
-
}
|
|
508
|
+
let prefix = "";
|
|
509
|
+
let suffix = "";
|
|
510
|
+
if (weight !== UNSET && weight & 1) {
|
|
511
|
+
prefix += "**";
|
|
512
|
+
suffix += "**";
|
|
653
513
|
}
|
|
654
|
-
if (
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
if (mapping && mapping.hidden) {
|
|
658
|
-
hidden = true;
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
514
|
+
if (emphasis !== UNSET && emphasis & 1) {
|
|
515
|
+
prefix += "*";
|
|
516
|
+
suffix = `*${suffix}`;
|
|
661
517
|
}
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
if (mapping && mapping.hidden) {
|
|
666
|
-
hidden = true;
|
|
667
|
-
break;
|
|
668
|
-
}
|
|
518
|
+
if (decoration !== UNSET && decoration & 1) {
|
|
519
|
+
prefix += "~~";
|
|
520
|
+
suffix = `~~${suffix}`;
|
|
669
521
|
}
|
|
522
|
+
const hidden = displayHidden !== UNSET && (displayHidden & 1) === 1 || positionHidden !== UNSET && (positionHidden & 1) === 1;
|
|
670
523
|
return {
|
|
671
524
|
prefix,
|
|
672
525
|
suffix,
|
|
@@ -677,8 +530,8 @@ function tailwindPlugin() {
|
|
|
677
530
|
return createPlugin({
|
|
678
531
|
excludesOverflowSubtree(node) {
|
|
679
532
|
if (node.parent?.context?.tailwind?.hidden) return true;
|
|
680
|
-
const
|
|
681
|
-
return
|
|
533
|
+
const classAttr = node.attributes?.class;
|
|
534
|
+
return classAttr ? processTailwindClasses(classAttr).hidden : false;
|
|
682
535
|
},
|
|
683
536
|
processAttributes(node) {
|
|
684
537
|
const parentHidden = node.parent?.context?.tailwind?.hidden;
|
|
@@ -688,7 +541,7 @@ function tailwindPlugin() {
|
|
|
688
541
|
let suffix = "";
|
|
689
542
|
let hidden = false;
|
|
690
543
|
if (classAttr) {
|
|
691
|
-
const result = processTailwindClasses(classAttr
|
|
544
|
+
const result = processTailwindClasses(classAttr);
|
|
692
545
|
prefix = result.prefix;
|
|
693
546
|
suffix = result.suffix;
|
|
694
547
|
hidden = result.hidden;
|
|
@@ -708,8 +561,8 @@ function tailwindPlugin() {
|
|
|
708
561
|
content: "",
|
|
709
562
|
skip: true
|
|
710
563
|
};
|
|
711
|
-
const prefix = state.
|
|
712
|
-
const suffix = state.
|
|
564
|
+
const prefix = state.outputFormat === "markdown" ? tailwindData?.prefix || "" : "";
|
|
565
|
+
const suffix = state.outputFormat === "markdown" ? tailwindData?.suffix || "" : "";
|
|
713
566
|
if (prefix || suffix) node.generatedMarkdown = {
|
|
714
567
|
prefix,
|
|
715
568
|
suffix
|
|
@@ -722,4 +575,4 @@ function tailwindPlugin() {
|
|
|
722
575
|
}
|
|
723
576
|
});
|
|
724
577
|
}
|
|
725
|
-
export {
|
|
578
|
+
export { filterPlugin, frontmatterPlugin, isolateMainPlugin, parseSelector, tailwindPlugin };
|