@marvalt/wparser 0.1.27 → 0.1.30

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
@@ -2059,6 +2059,36 @@ function extractBackgroundColor(block, context) {
2059
2059
  // Fallback: return null (no background applied)
2060
2060
  return null;
2061
2061
  }
2062
+ /**
2063
+ * Extract spacer height from block attributes or innerHTML
2064
+ * Returns height in pixels, or null if not found
2065
+ */
2066
+ function extractSpacerHeight(block) {
2067
+ const attrs = block.attributes || {};
2068
+ // First, try to get height from attributes
2069
+ const height = attrs['height'];
2070
+ if (typeof height === 'number') {
2071
+ return height;
2072
+ }
2073
+ if (typeof height === 'string') {
2074
+ // Parse "100px" or "100" to number
2075
+ const match = height.match(/^(\d+)/);
2076
+ if (match) {
2077
+ return parseInt(match[1], 10);
2078
+ }
2079
+ }
2080
+ // Fall back to parsing innerHTML for style="height:100px"
2081
+ if (block.innerHTML) {
2082
+ const styleMatch = block.innerHTML.match(/style=["']([^"']+)["']/i);
2083
+ if (styleMatch) {
2084
+ const heightMatch = styleMatch[1].match(/height:\s*(\d+)px/i);
2085
+ if (heightMatch) {
2086
+ return parseInt(heightMatch[1], 10);
2087
+ }
2088
+ }
2089
+ }
2090
+ return null;
2091
+ }
2062
2092
 
2063
2093
  /**
2064
2094
  * Style mapping utilities
@@ -2242,8 +2272,29 @@ const List = ({ block, children, context }) => {
2242
2272
  const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
2243
2273
  return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2 text-gray-700', spacing) }, children);
2244
2274
  };
2245
- const ListItem = ({ children }) => {
2246
- return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: children });
2275
+ const ListItem = ({ block, children }) => {
2276
+ // List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
2277
+ // We need to extract the content from inside the <li> tag and render it properly
2278
+ let content = null;
2279
+ if (block.innerHTML) {
2280
+ // Extract content from innerHTML - remove the outer <li> tags
2281
+ // Pattern: <li>content</li> or <li>content<br>more</li>
2282
+ const liMatch = block.innerHTML.match(/<li[^>]*>(.*?)<\/li>/is);
2283
+ if (liMatch && liMatch[1]) {
2284
+ const innerContent = liMatch[1].trim();
2285
+ if (innerContent) {
2286
+ // Use dangerouslySetInnerHTML to properly render HTML content including <br> tags and entities
2287
+ // This is safe because we're only rendering content from WordPress (trusted source)
2288
+ content = jsxRuntimeExports.jsx("span", { dangerouslySetInnerHTML: { __html: innerContent } });
2289
+ }
2290
+ }
2291
+ }
2292
+ // If we have both innerHTML content and children (innerBlocks), combine them
2293
+ if (content && children && React.Children.count(children) > 0) {
2294
+ return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
2295
+ }
2296
+ // Return content from innerHTML if available, otherwise use children
2297
+ return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
2247
2298
  };
2248
2299
  const Group = ({ block, children, context }) => {
2249
2300
  const attrs = block.attributes || {};
@@ -2460,6 +2511,15 @@ function createDefaultRegistry(colorMapper, spacingConfig) {
2460
2511
  const html = block.innerHTML || '';
2461
2512
  return jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: html } });
2462
2513
  },
2514
+ // Spacer block - adds vertical spacing
2515
+ 'core/spacer': ({ block }) => {
2516
+ const height = extractSpacerHeight(block);
2517
+ if (height && height > 0) {
2518
+ return jsxRuntimeExports.jsx("div", { style: { height: `${height}px` }, "aria-hidden": "true" });
2519
+ }
2520
+ // Default fallback if height not found
2521
+ return jsxRuntimeExports.jsx("div", { style: { height: '100px' }, "aria-hidden": "true" });
2522
+ },
2463
2523
  };
2464
2524
  return {
2465
2525
  renderers,
@@ -2799,6 +2859,7 @@ exports.extractImageUrlWithFallback = extractImageUrlWithFallback;
2799
2859
  exports.extractMediaPosition = extractMediaPosition;
2800
2860
  exports.extractMinHeight = extractMinHeight;
2801
2861
  exports.extractOverlayColor = extractOverlayColor;
2862
+ exports.extractSpacerHeight = extractSpacerHeight;
2802
2863
  exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
2803
2864
  exports.extractTextAlign = extractTextAlign;
2804
2865
  exports.extractTextAlignFromInnerBlocks = extractTextAlignFromInnerBlocks;