@marvalt/wparser 0.1.7 → 0.1.8
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/dist/index.cjs +119 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +116 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/blockExtractors.d.ts +20 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2309,6 +2309,121 @@ function convertImageToCloudflareVariant(url, options = {}) {
|
|
|
2309
2309
|
}
|
|
2310
2310
|
return url;
|
|
2311
2311
|
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Extract title from innerBlocks (finds first heading block)
|
|
2314
|
+
*/
|
|
2315
|
+
function extractTitleFromInnerBlocks(block) {
|
|
2316
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2317
|
+
// Recursively search for heading blocks
|
|
2318
|
+
for (const innerBlock of innerBlocks) {
|
|
2319
|
+
if (innerBlock.name === 'core/heading') {
|
|
2320
|
+
return getBlockTextContent(innerBlock);
|
|
2321
|
+
}
|
|
2322
|
+
// Recursively search nested blocks
|
|
2323
|
+
const nestedTitle = extractTitleFromInnerBlocks(innerBlock);
|
|
2324
|
+
if (nestedTitle)
|
|
2325
|
+
return nestedTitle;
|
|
2326
|
+
}
|
|
2327
|
+
return null;
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Extract subtitle/description from innerBlocks (finds first paragraph block)
|
|
2331
|
+
*/
|
|
2332
|
+
function extractSubtitleFromInnerBlocks(block) {
|
|
2333
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2334
|
+
// Recursively search for paragraph blocks
|
|
2335
|
+
for (const innerBlock of innerBlocks) {
|
|
2336
|
+
if (innerBlock.name === 'core/paragraph') {
|
|
2337
|
+
const text = getBlockTextContent(innerBlock);
|
|
2338
|
+
if (text && text.trim()) {
|
|
2339
|
+
return text;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
// Recursively search nested blocks
|
|
2343
|
+
const nestedSubtitle = extractSubtitleFromInnerBlocks(innerBlock);
|
|
2344
|
+
if (nestedSubtitle)
|
|
2345
|
+
return nestedSubtitle;
|
|
2346
|
+
}
|
|
2347
|
+
return null;
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Extract buttons from innerBlocks (finds buttons block and extracts button data)
|
|
2351
|
+
*/
|
|
2352
|
+
function extractButtonsFromInnerBlocks(block) {
|
|
2353
|
+
const buttons = [];
|
|
2354
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2355
|
+
// Find buttons block
|
|
2356
|
+
const findButtonsBlock = (blocks) => {
|
|
2357
|
+
for (const innerBlock of blocks) {
|
|
2358
|
+
if (innerBlock.name === 'core/buttons') {
|
|
2359
|
+
return innerBlock;
|
|
2360
|
+
}
|
|
2361
|
+
if (innerBlock.innerBlocks) {
|
|
2362
|
+
const found = findButtonsBlock(innerBlock.innerBlocks);
|
|
2363
|
+
if (found)
|
|
2364
|
+
return found;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
return null;
|
|
2368
|
+
};
|
|
2369
|
+
const buttonsBlock = findButtonsBlock(innerBlocks);
|
|
2370
|
+
if (!buttonsBlock || !buttonsBlock.innerBlocks) {
|
|
2371
|
+
return buttons;
|
|
2372
|
+
}
|
|
2373
|
+
// Extract button data from button blocks
|
|
2374
|
+
for (const buttonBlock of buttonsBlock.innerBlocks) {
|
|
2375
|
+
if (buttonBlock.name === 'core/button') {
|
|
2376
|
+
const attrs = buttonBlock.attributes || {};
|
|
2377
|
+
const url = attrs['url'];
|
|
2378
|
+
const text = attrs['text'] || getBlockTextContent(buttonBlock);
|
|
2379
|
+
// Try to extract from innerHTML if not in attributes
|
|
2380
|
+
if (!url && buttonBlock.innerHTML) {
|
|
2381
|
+
const linkMatch = buttonBlock.innerHTML.match(/<a[^>]+href=["']([^"']+)["'][^>]*>([^<]+)<\/a>/i);
|
|
2382
|
+
if (linkMatch) {
|
|
2383
|
+
const extractedUrl = linkMatch[1];
|
|
2384
|
+
const extractedText = linkMatch[2] || text;
|
|
2385
|
+
if (extractedUrl) {
|
|
2386
|
+
buttons.push({
|
|
2387
|
+
text: extractedText || 'Learn More',
|
|
2388
|
+
url: extractedUrl,
|
|
2389
|
+
isExternal: extractedUrl.startsWith('http://') || extractedUrl.startsWith('https://'),
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
else if (url && text) {
|
|
2395
|
+
buttons.push({
|
|
2396
|
+
text,
|
|
2397
|
+
url,
|
|
2398
|
+
isExternal: url.startsWith('http://') || url.startsWith('https://'),
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
return buttons;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
|
|
2407
|
+
*/
|
|
2408
|
+
function extractVideoIframeFromInnerBlocks(block) {
|
|
2409
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2410
|
+
// Recursively search for HTML blocks with iframe
|
|
2411
|
+
for (const innerBlock of innerBlocks) {
|
|
2412
|
+
if (innerBlock.name === 'core/html' && innerBlock.innerHTML) {
|
|
2413
|
+
// Check if innerHTML contains an iframe
|
|
2414
|
+
if (innerBlock.innerHTML.includes('<iframe')) {
|
|
2415
|
+
return innerBlock.innerHTML;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
// Recursively search nested blocks
|
|
2419
|
+
if (innerBlock.innerBlocks) {
|
|
2420
|
+
const nestedVideo = extractVideoIframeFromInnerBlocks(innerBlock);
|
|
2421
|
+
if (nestedVideo)
|
|
2422
|
+
return nestedVideo;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
return null;
|
|
2426
|
+
}
|
|
2312
2427
|
|
|
2313
2428
|
/**
|
|
2314
2429
|
* Convert image URL with optional Cloudflare variant transformation
|
|
@@ -2404,6 +2519,7 @@ exports.createDefaultRegistry = createDefaultRegistry;
|
|
|
2404
2519
|
exports.createEnhancedRegistry = createEnhancedRegistry;
|
|
2405
2520
|
exports.extractAlignment = extractAlignment;
|
|
2406
2521
|
exports.extractBackgroundImage = extractBackgroundImage;
|
|
2522
|
+
exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
|
|
2407
2523
|
exports.extractContent = extractContent;
|
|
2408
2524
|
exports.extractDimRatio = extractDimRatio;
|
|
2409
2525
|
exports.extractFontSize = extractFontSize;
|
|
@@ -2413,10 +2529,13 @@ exports.extractImageUrl = extractImageUrl;
|
|
|
2413
2529
|
exports.extractMediaPosition = extractMediaPosition;
|
|
2414
2530
|
exports.extractMinHeight = extractMinHeight;
|
|
2415
2531
|
exports.extractOverlayColor = extractOverlayColor;
|
|
2532
|
+
exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
|
|
2416
2533
|
exports.extractTextAlign = extractTextAlign;
|
|
2417
2534
|
exports.extractTextFromHTML = extractTextFromHTML;
|
|
2418
2535
|
exports.extractTitle = extractTitle;
|
|
2536
|
+
exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
|
|
2419
2537
|
exports.extractVerticalAlignment = extractVerticalAlignment;
|
|
2538
|
+
exports.extractVideoIframeFromInnerBlocks = extractVideoIframeFromInnerBlocks;
|
|
2420
2539
|
exports.findMatchingMapping = findMatchingMapping;
|
|
2421
2540
|
exports.findShortcodes = findShortcodes;
|
|
2422
2541
|
exports.getAlignmentClasses = getAlignmentClasses;
|