@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 CHANGED
@@ -1732,6 +1732,26 @@ const Paragraph = ({ block, context }) => {
1732
1732
  const hasShortcodes = /\[(\w+)/.test(content);
1733
1733
  if (hasShortcodes && context.registry.shortcodes) {
1734
1734
  const parts = renderTextWithShortcodes(content, context.registry);
1735
+ // Check if any part is a block-level element (section, div, etc.)
1736
+ // If so, render without wrapping in <p> to avoid DOM nesting violations
1737
+ const hasBlockLevelContent = React.Children.toArray(parts).some((part) => {
1738
+ if (React.isValidElement(part)) {
1739
+ const type = part.type;
1740
+ // Check for block-level HTML elements
1741
+ if (typeof type === 'string' && ['section', 'div', 'article', 'header', 'footer', 'aside', 'nav'].includes(type)) {
1742
+ return true;
1743
+ }
1744
+ // Check if it's a React component (likely block-level)
1745
+ if (typeof type === 'function' || (typeof type === 'object' && type !== null)) {
1746
+ return true;
1747
+ }
1748
+ }
1749
+ return false;
1750
+ });
1751
+ if (hasBlockLevelContent) {
1752
+ // Render block-level content without <p> wrapper
1753
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: parts });
1754
+ }
1735
1755
  return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: parts });
1736
1756
  }
1737
1757
  return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: content });
@@ -2402,6 +2422,57 @@ function extractButtonsFromInnerBlocks(block) {
2402
2422
  }
2403
2423
  return buttons;
2404
2424
  }
2425
+ /**
2426
+ * Extract text alignment from inner blocks
2427
+ * Recursively searches for heading or paragraph blocks with textAlign attribute
2428
+ * Also checks group blocks for justifyContent in layout
2429
+ */
2430
+ function extractTextAlignFromInnerBlocks(block) {
2431
+ const innerBlocks = block.innerBlocks || [];
2432
+ // Recursively search for heading or paragraph blocks with textAlign
2433
+ for (const innerBlock of innerBlocks) {
2434
+ if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
2435
+ const attrs = innerBlock.attributes || {};
2436
+ const textAlign = attrs['textAlign'];
2437
+ if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
2438
+ return textAlign;
2439
+ }
2440
+ }
2441
+ // Check group blocks for justifyContent
2442
+ if (innerBlock.name === 'core/group') {
2443
+ const attrs = innerBlock.attributes || {};
2444
+ const layout = attrs['layout'];
2445
+ const justifyContent = layout?.justifyContent;
2446
+ if (justifyContent === 'left')
2447
+ return 'left';
2448
+ if (justifyContent === 'center')
2449
+ return 'center';
2450
+ if (justifyContent === 'right')
2451
+ return 'right';
2452
+ }
2453
+ // Recursively search nested blocks
2454
+ const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
2455
+ if (nestedAlign)
2456
+ return nestedAlign;
2457
+ }
2458
+ return null;
2459
+ }
2460
+ /**
2461
+ * Parse contentPosition string into horizontal and vertical alignment
2462
+ * Format: "horizontal vertical" (e.g., "center center", "left top", "right bottom")
2463
+ */
2464
+ function parseContentPosition(contentPosition) {
2465
+ if (!contentPosition) {
2466
+ return { horizontal: 'left', vertical: 'center' };
2467
+ }
2468
+ const parts = contentPosition.trim().split(/\s+/);
2469
+ const horizontal = parts[0] || 'left';
2470
+ const vertical = parts[1] || 'center';
2471
+ return {
2472
+ horizontal: (horizontal === 'center' || horizontal === 'right' ? horizontal : 'left'),
2473
+ vertical: (vertical === 'top' || vertical === 'bottom' ? vertical : 'center'),
2474
+ };
2475
+ }
2405
2476
  /**
2406
2477
  * Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
2407
2478
  */
@@ -2531,6 +2602,7 @@ exports.extractMinHeight = extractMinHeight;
2531
2602
  exports.extractOverlayColor = extractOverlayColor;
2532
2603
  exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
2533
2604
  exports.extractTextAlign = extractTextAlign;
2605
+ exports.extractTextAlignFromInnerBlocks = extractTextAlignFromInnerBlocks;
2534
2606
  exports.extractTextFromHTML = extractTextFromHTML;
2535
2607
  exports.extractTitle = extractTitle;
2536
2608
  exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
@@ -2550,6 +2622,7 @@ exports.getSectionSpacingClasses = getSectionSpacingClasses;
2550
2622
  exports.getTextAlignClasses = getTextAlignClasses;
2551
2623
  exports.isCloudflareImageUrl = isCloudflareImageUrl;
2552
2624
  exports.matchesPattern = matchesPattern;
2625
+ exports.parseContentPosition = parseContentPosition;
2553
2626
  exports.parseGutenbergBlocks = parseGutenbergBlocks;
2554
2627
  exports.parseShortcodeAttrs = parseShortcodeAttrs;
2555
2628
  exports.renderNodes = renderNodes;