@marvalt/wparser 0.1.8 → 0.1.11
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 +73 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +72 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +14 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1730,6 +1730,26 @@ const Paragraph = ({ block, context }) => {
|
|
|
1730
1730
|
const hasShortcodes = /\[(\w+)/.test(content);
|
|
1731
1731
|
if (hasShortcodes && context.registry.shortcodes) {
|
|
1732
1732
|
const parts = renderTextWithShortcodes(content, context.registry);
|
|
1733
|
+
// Check if any part is a block-level element (section, div, etc.)
|
|
1734
|
+
// If so, render without wrapping in <p> to avoid DOM nesting violations
|
|
1735
|
+
const hasBlockLevelContent = React.Children.toArray(parts).some((part) => {
|
|
1736
|
+
if (React.isValidElement(part)) {
|
|
1737
|
+
const type = part.type;
|
|
1738
|
+
// Check for block-level HTML elements
|
|
1739
|
+
if (typeof type === 'string' && ['section', 'div', 'article', 'header', 'footer', 'aside', 'nav'].includes(type)) {
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
// Check if it's a React component (likely block-level)
|
|
1743
|
+
if (typeof type === 'function' || (typeof type === 'object' && type !== null)) {
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
return false;
|
|
1748
|
+
});
|
|
1749
|
+
if (hasBlockLevelContent) {
|
|
1750
|
+
// Render block-level content without <p> wrapper
|
|
1751
|
+
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: parts });
|
|
1752
|
+
}
|
|
1733
1753
|
return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: parts });
|
|
1734
1754
|
}
|
|
1735
1755
|
return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: content });
|
|
@@ -2400,6 +2420,57 @@ function extractButtonsFromInnerBlocks(block) {
|
|
|
2400
2420
|
}
|
|
2401
2421
|
return buttons;
|
|
2402
2422
|
}
|
|
2423
|
+
/**
|
|
2424
|
+
* Extract text alignment from inner blocks
|
|
2425
|
+
* Recursively searches for heading or paragraph blocks with textAlign attribute
|
|
2426
|
+
* Also checks group blocks for justifyContent in layout
|
|
2427
|
+
*/
|
|
2428
|
+
function extractTextAlignFromInnerBlocks(block) {
|
|
2429
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2430
|
+
// Recursively search for heading or paragraph blocks with textAlign
|
|
2431
|
+
for (const innerBlock of innerBlocks) {
|
|
2432
|
+
if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
|
|
2433
|
+
const attrs = innerBlock.attributes || {};
|
|
2434
|
+
const textAlign = attrs['textAlign'];
|
|
2435
|
+
if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
|
|
2436
|
+
return textAlign;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
// Check group blocks for justifyContent
|
|
2440
|
+
if (innerBlock.name === 'core/group') {
|
|
2441
|
+
const attrs = innerBlock.attributes || {};
|
|
2442
|
+
const layout = attrs['layout'];
|
|
2443
|
+
const justifyContent = layout?.justifyContent;
|
|
2444
|
+
if (justifyContent === 'left')
|
|
2445
|
+
return 'left';
|
|
2446
|
+
if (justifyContent === 'center')
|
|
2447
|
+
return 'center';
|
|
2448
|
+
if (justifyContent === 'right')
|
|
2449
|
+
return 'right';
|
|
2450
|
+
}
|
|
2451
|
+
// Recursively search nested blocks
|
|
2452
|
+
const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
|
|
2453
|
+
if (nestedAlign)
|
|
2454
|
+
return nestedAlign;
|
|
2455
|
+
}
|
|
2456
|
+
return null;
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Parse contentPosition string into horizontal and vertical alignment
|
|
2460
|
+
* Format: "horizontal vertical" (e.g., "center center", "left top", "right bottom")
|
|
2461
|
+
*/
|
|
2462
|
+
function parseContentPosition(contentPosition) {
|
|
2463
|
+
if (!contentPosition) {
|
|
2464
|
+
return { horizontal: 'left', vertical: 'center' };
|
|
2465
|
+
}
|
|
2466
|
+
const parts = contentPosition.trim().split(/\s+/);
|
|
2467
|
+
const horizontal = parts[0] || 'left';
|
|
2468
|
+
const vertical = parts[1] || 'center';
|
|
2469
|
+
return {
|
|
2470
|
+
horizontal: (horizontal === 'center' || horizontal === 'right' ? horizontal : 'left'),
|
|
2471
|
+
vertical: (vertical === 'top' || vertical === 'bottom' ? vertical : 'center'),
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2403
2474
|
/**
|
|
2404
2475
|
* Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
|
|
2405
2476
|
*/
|
|
@@ -2505,5 +2576,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
|
|
|
2505
2576
|
return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
|
|
2506
2577
|
};
|
|
2507
2578
|
|
|
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 };
|
|
2579
|
+
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, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
2509
2580
|
//# sourceMappingURL=index.esm.js.map
|