@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.esm.js
CHANGED
|
@@ -2307,6 +2307,121 @@ function convertImageToCloudflareVariant(url, options = {}) {
|
|
|
2307
2307
|
}
|
|
2308
2308
|
return url;
|
|
2309
2309
|
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Extract title from innerBlocks (finds first heading block)
|
|
2312
|
+
*/
|
|
2313
|
+
function extractTitleFromInnerBlocks(block) {
|
|
2314
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2315
|
+
// Recursively search for heading blocks
|
|
2316
|
+
for (const innerBlock of innerBlocks) {
|
|
2317
|
+
if (innerBlock.name === 'core/heading') {
|
|
2318
|
+
return getBlockTextContent(innerBlock);
|
|
2319
|
+
}
|
|
2320
|
+
// Recursively search nested blocks
|
|
2321
|
+
const nestedTitle = extractTitleFromInnerBlocks(innerBlock);
|
|
2322
|
+
if (nestedTitle)
|
|
2323
|
+
return nestedTitle;
|
|
2324
|
+
}
|
|
2325
|
+
return null;
|
|
2326
|
+
}
|
|
2327
|
+
/**
|
|
2328
|
+
* Extract subtitle/description from innerBlocks (finds first paragraph block)
|
|
2329
|
+
*/
|
|
2330
|
+
function extractSubtitleFromInnerBlocks(block) {
|
|
2331
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2332
|
+
// Recursively search for paragraph blocks
|
|
2333
|
+
for (const innerBlock of innerBlocks) {
|
|
2334
|
+
if (innerBlock.name === 'core/paragraph') {
|
|
2335
|
+
const text = getBlockTextContent(innerBlock);
|
|
2336
|
+
if (text && text.trim()) {
|
|
2337
|
+
return text;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
// Recursively search nested blocks
|
|
2341
|
+
const nestedSubtitle = extractSubtitleFromInnerBlocks(innerBlock);
|
|
2342
|
+
if (nestedSubtitle)
|
|
2343
|
+
return nestedSubtitle;
|
|
2344
|
+
}
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Extract buttons from innerBlocks (finds buttons block and extracts button data)
|
|
2349
|
+
*/
|
|
2350
|
+
function extractButtonsFromInnerBlocks(block) {
|
|
2351
|
+
const buttons = [];
|
|
2352
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2353
|
+
// Find buttons block
|
|
2354
|
+
const findButtonsBlock = (blocks) => {
|
|
2355
|
+
for (const innerBlock of blocks) {
|
|
2356
|
+
if (innerBlock.name === 'core/buttons') {
|
|
2357
|
+
return innerBlock;
|
|
2358
|
+
}
|
|
2359
|
+
if (innerBlock.innerBlocks) {
|
|
2360
|
+
const found = findButtonsBlock(innerBlock.innerBlocks);
|
|
2361
|
+
if (found)
|
|
2362
|
+
return found;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
return null;
|
|
2366
|
+
};
|
|
2367
|
+
const buttonsBlock = findButtonsBlock(innerBlocks);
|
|
2368
|
+
if (!buttonsBlock || !buttonsBlock.innerBlocks) {
|
|
2369
|
+
return buttons;
|
|
2370
|
+
}
|
|
2371
|
+
// Extract button data from button blocks
|
|
2372
|
+
for (const buttonBlock of buttonsBlock.innerBlocks) {
|
|
2373
|
+
if (buttonBlock.name === 'core/button') {
|
|
2374
|
+
const attrs = buttonBlock.attributes || {};
|
|
2375
|
+
const url = attrs['url'];
|
|
2376
|
+
const text = attrs['text'] || getBlockTextContent(buttonBlock);
|
|
2377
|
+
// Try to extract from innerHTML if not in attributes
|
|
2378
|
+
if (!url && buttonBlock.innerHTML) {
|
|
2379
|
+
const linkMatch = buttonBlock.innerHTML.match(/<a[^>]+href=["']([^"']+)["'][^>]*>([^<]+)<\/a>/i);
|
|
2380
|
+
if (linkMatch) {
|
|
2381
|
+
const extractedUrl = linkMatch[1];
|
|
2382
|
+
const extractedText = linkMatch[2] || text;
|
|
2383
|
+
if (extractedUrl) {
|
|
2384
|
+
buttons.push({
|
|
2385
|
+
text: extractedText || 'Learn More',
|
|
2386
|
+
url: extractedUrl,
|
|
2387
|
+
isExternal: extractedUrl.startsWith('http://') || extractedUrl.startsWith('https://'),
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
else if (url && text) {
|
|
2393
|
+
buttons.push({
|
|
2394
|
+
text,
|
|
2395
|
+
url,
|
|
2396
|
+
isExternal: url.startsWith('http://') || url.startsWith('https://'),
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
return buttons;
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
|
|
2405
|
+
*/
|
|
2406
|
+
function extractVideoIframeFromInnerBlocks(block) {
|
|
2407
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2408
|
+
// Recursively search for HTML blocks with iframe
|
|
2409
|
+
for (const innerBlock of innerBlocks) {
|
|
2410
|
+
if (innerBlock.name === 'core/html' && innerBlock.innerHTML) {
|
|
2411
|
+
// Check if innerHTML contains an iframe
|
|
2412
|
+
if (innerBlock.innerHTML.includes('<iframe')) {
|
|
2413
|
+
return innerBlock.innerHTML;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
// Recursively search nested blocks
|
|
2417
|
+
if (innerBlock.innerBlocks) {
|
|
2418
|
+
const nestedVideo = extractVideoIframeFromInnerBlocks(innerBlock);
|
|
2419
|
+
if (nestedVideo)
|
|
2420
|
+
return nestedVideo;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
return null;
|
|
2424
|
+
}
|
|
2310
2425
|
|
|
2311
2426
|
/**
|
|
2312
2427
|
* Convert image URL with optional Cloudflare variant transformation
|
|
@@ -2390,5 +2505,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
|
|
|
2390
2505
|
return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
|
|
2391
2506
|
};
|
|
2392
2507
|
|
|
2393
|
-
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundImage, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractMediaPosition, extractMinHeight, extractOverlayColor, extractTextAlign, extractTextFromHTML, extractTitle, extractVerticalAlignment, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, matchesPattern, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
2508
|
+
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, matchesPattern, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
2394
2509
|
//# sourceMappingURL=index.esm.js.map
|