@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 +63 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +63 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +5 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2057,6 +2057,36 @@ function extractBackgroundColor(block, context) {
|
|
|
2057
2057
|
// Fallback: return null (no background applied)
|
|
2058
2058
|
return null;
|
|
2059
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Extract spacer height from block attributes or innerHTML
|
|
2062
|
+
* Returns height in pixels, or null if not found
|
|
2063
|
+
*/
|
|
2064
|
+
function extractSpacerHeight(block) {
|
|
2065
|
+
const attrs = block.attributes || {};
|
|
2066
|
+
// First, try to get height from attributes
|
|
2067
|
+
const height = attrs['height'];
|
|
2068
|
+
if (typeof height === 'number') {
|
|
2069
|
+
return height;
|
|
2070
|
+
}
|
|
2071
|
+
if (typeof height === 'string') {
|
|
2072
|
+
// Parse "100px" or "100" to number
|
|
2073
|
+
const match = height.match(/^(\d+)/);
|
|
2074
|
+
if (match) {
|
|
2075
|
+
return parseInt(match[1], 10);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
// Fall back to parsing innerHTML for style="height:100px"
|
|
2079
|
+
if (block.innerHTML) {
|
|
2080
|
+
const styleMatch = block.innerHTML.match(/style=["']([^"']+)["']/i);
|
|
2081
|
+
if (styleMatch) {
|
|
2082
|
+
const heightMatch = styleMatch[1].match(/height:\s*(\d+)px/i);
|
|
2083
|
+
if (heightMatch) {
|
|
2084
|
+
return parseInt(heightMatch[1], 10);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
return null;
|
|
2089
|
+
}
|
|
2060
2090
|
|
|
2061
2091
|
/**
|
|
2062
2092
|
* Style mapping utilities
|
|
@@ -2240,8 +2270,29 @@ const List = ({ block, children, context }) => {
|
|
|
2240
2270
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
|
|
2241
2271
|
return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2 text-gray-700', spacing) }, children);
|
|
2242
2272
|
};
|
|
2243
|
-
const ListItem = ({ children }) => {
|
|
2244
|
-
|
|
2273
|
+
const ListItem = ({ block, children }) => {
|
|
2274
|
+
// List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
|
|
2275
|
+
// We need to extract the content from inside the <li> tag and render it properly
|
|
2276
|
+
let content = null;
|
|
2277
|
+
if (block.innerHTML) {
|
|
2278
|
+
// Extract content from innerHTML - remove the outer <li> tags
|
|
2279
|
+
// Pattern: <li>content</li> or <li>content<br>more</li>
|
|
2280
|
+
const liMatch = block.innerHTML.match(/<li[^>]*>(.*?)<\/li>/is);
|
|
2281
|
+
if (liMatch && liMatch[1]) {
|
|
2282
|
+
const innerContent = liMatch[1].trim();
|
|
2283
|
+
if (innerContent) {
|
|
2284
|
+
// Use dangerouslySetInnerHTML to properly render HTML content including <br> tags and entities
|
|
2285
|
+
// This is safe because we're only rendering content from WordPress (trusted source)
|
|
2286
|
+
content = jsxRuntimeExports.jsx("span", { dangerouslySetInnerHTML: { __html: innerContent } });
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
// If we have both innerHTML content and children (innerBlocks), combine them
|
|
2291
|
+
if (content && children && React.Children.count(children) > 0) {
|
|
2292
|
+
return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
|
|
2293
|
+
}
|
|
2294
|
+
// Return content from innerHTML if available, otherwise use children
|
|
2295
|
+
return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
|
|
2245
2296
|
};
|
|
2246
2297
|
const Group = ({ block, children, context }) => {
|
|
2247
2298
|
const attrs = block.attributes || {};
|
|
@@ -2458,6 +2509,15 @@ function createDefaultRegistry(colorMapper, spacingConfig) {
|
|
|
2458
2509
|
const html = block.innerHTML || '';
|
|
2459
2510
|
return jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: html } });
|
|
2460
2511
|
},
|
|
2512
|
+
// Spacer block - adds vertical spacing
|
|
2513
|
+
'core/spacer': ({ block }) => {
|
|
2514
|
+
const height = extractSpacerHeight(block);
|
|
2515
|
+
if (height && height > 0) {
|
|
2516
|
+
return jsxRuntimeExports.jsx("div", { style: { height: `${height}px` }, "aria-hidden": "true" });
|
|
2517
|
+
}
|
|
2518
|
+
// Default fallback if height not found
|
|
2519
|
+
return jsxRuntimeExports.jsx("div", { style: { height: '100px' }, "aria-hidden": "true" });
|
|
2520
|
+
},
|
|
2461
2521
|
};
|
|
2462
2522
|
return {
|
|
2463
2523
|
renderers,
|
|
@@ -2773,5 +2833,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
|
|
|
2773
2833
|
return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
|
|
2774
2834
|
};
|
|
2775
2835
|
|
|
2776
|
-
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
2836
|
+
export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
2777
2837
|
//# sourceMappingURL=index.esm.js.map
|