@marvalt/wparser 0.1.53 → 0.1.55
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 +70 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +69 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +17 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1910,6 +1910,28 @@ function extractTitleFromInnerBlocks(block) {
|
|
|
1910
1910
|
}
|
|
1911
1911
|
return null;
|
|
1912
1912
|
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Extract text color from heading block in innerBlocks
|
|
1915
|
+
* Used to get custom text color for hero headings
|
|
1916
|
+
*
|
|
1917
|
+
* @param block - Block to search (typically a cover block)
|
|
1918
|
+
* @param context - Render context containing colorMapper
|
|
1919
|
+
* @returns CSS class string (e.g., 'text-white') or null if no custom color
|
|
1920
|
+
*/
|
|
1921
|
+
function extractTitleTextColorFromInnerBlocks(block, context) {
|
|
1922
|
+
const innerBlocks = block.innerBlocks || [];
|
|
1923
|
+
// Recursively search for heading blocks
|
|
1924
|
+
for (const innerBlock of innerBlocks) {
|
|
1925
|
+
if (innerBlock.name === 'core/heading') {
|
|
1926
|
+
return extractTextColor(innerBlock, context);
|
|
1927
|
+
}
|
|
1928
|
+
// Recursively search nested blocks
|
|
1929
|
+
const nestedColor = extractTitleTextColorFromInnerBlocks(innerBlock, context);
|
|
1930
|
+
if (nestedColor)
|
|
1931
|
+
return nestedColor;
|
|
1932
|
+
}
|
|
1933
|
+
return null;
|
|
1934
|
+
}
|
|
1913
1935
|
/**
|
|
1914
1936
|
* Extract subtitle/description from innerBlocks (finds first paragraph block)
|
|
1915
1937
|
*/
|
|
@@ -2116,6 +2138,21 @@ function extractBackgroundColorValue(block, context) {
|
|
|
2116
2138
|
}
|
|
2117
2139
|
return null;
|
|
2118
2140
|
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Extract gradient background from block attributes
|
|
2143
|
+
* WordPress stores gradients in attributes.style.color.gradient
|
|
2144
|
+
*
|
|
2145
|
+
* @param block - WordPress block to extract gradient from
|
|
2146
|
+
* @returns Gradient string (e.g., "linear-gradient(...)") or null if no gradient
|
|
2147
|
+
*/
|
|
2148
|
+
function extractGradientBackground(block) {
|
|
2149
|
+
const attrs = block.attributes || {};
|
|
2150
|
+
const style = attrs['style'];
|
|
2151
|
+
if (style?.color?.gradient && typeof style.color.gradient === 'string') {
|
|
2152
|
+
return style.color.gradient;
|
|
2153
|
+
}
|
|
2154
|
+
return null;
|
|
2155
|
+
}
|
|
2119
2156
|
/**
|
|
2120
2157
|
* Extract and map text color from block attributes
|
|
2121
2158
|
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
@@ -2301,6 +2338,9 @@ const Paragraph = ({ block, context }) => {
|
|
|
2301
2338
|
const attrs = block.attributes || {};
|
|
2302
2339
|
const textAlign = getTextAlignClasses(attrs['align']);
|
|
2303
2340
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'paragraph', 'my-6');
|
|
2341
|
+
// Extract text color if specified, otherwise inherit from parent (CSS variables handle default)
|
|
2342
|
+
const textColor = extractTextColor(block, context);
|
|
2343
|
+
const textColorClass = textColor || ''; // Don't hardcode - let CSS variables handle default
|
|
2304
2344
|
// Check if innerHTML contains HTML elements (like links, strong, em, etc.)
|
|
2305
2345
|
const hasHTML = block.innerHTML && /<[a-z][\s\S]*>/i.test(block.innerHTML);
|
|
2306
2346
|
// Check if content contains shortcodes (check both HTML and text content)
|
|
@@ -2336,17 +2376,17 @@ const Paragraph = ({ block, context }) => {
|
|
|
2336
2376
|
const hasBlockLevelContent = React.Children.toArray(parts).some((part) => isBlockLevelElement(part));
|
|
2337
2377
|
if (hasBlockLevelContent) {
|
|
2338
2378
|
// Render block-level content without <p> wrapper, but add spacing wrapper
|
|
2339
|
-
return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
|
|
2379
|
+
return jsxRuntimeExports.jsx("div", { className: buildClassName(spacing, textColorClass), children: parts });
|
|
2340
2380
|
}
|
|
2341
2381
|
// Render shortcode parts inside paragraph (shortcodes are processed as React components)
|
|
2342
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
|
|
2382
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), children: parts });
|
|
2343
2383
|
}
|
|
2344
2384
|
// If innerHTML contains HTML elements but no shortcodes, render it directly (preserves links, formatting, etc.)
|
|
2345
2385
|
if (hasHTML && block.innerHTML) {
|
|
2346
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), dangerouslySetInnerHTML: { __html: htmlContent } });
|
|
2386
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), dangerouslySetInnerHTML: { __html: htmlContent } });
|
|
2347
2387
|
}
|
|
2348
2388
|
// No HTML and no shortcodes, just render plain text content
|
|
2349
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: textContent });
|
|
2389
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), children: textContent });
|
|
2350
2390
|
};
|
|
2351
2391
|
const Heading = ({ block, children, context }) => {
|
|
2352
2392
|
const attrs = block.attributes || {};
|
|
@@ -2661,12 +2701,32 @@ function createDefaultRegistry(colorMapper, spacingConfig) {
|
|
|
2661
2701
|
'justify-start';
|
|
2662
2702
|
return jsxRuntimeExports.jsx("div", { className: buildClassName('flex flex-wrap gap-3', justifyClass), children: children });
|
|
2663
2703
|
},
|
|
2664
|
-
'core/quote': ({ children }) =>
|
|
2665
|
-
|
|
2666
|
-
|
|
2704
|
+
'core/quote': ({ block, children, context }) => {
|
|
2705
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2706
|
+
const textColor = extractTextColor(block, context);
|
|
2707
|
+
const textColorClass = textColor || '';
|
|
2708
|
+
return jsxRuntimeExports.jsx("blockquote", { className: buildClassName('border-l-4 pl-4 italic', textColorClass), children: children });
|
|
2709
|
+
},
|
|
2710
|
+
'core/code': ({ block, context }) => {
|
|
2711
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2712
|
+
const textColor = extractTextColor(block, context);
|
|
2713
|
+
const textColorClass = textColor || '';
|
|
2714
|
+
return (jsxRuntimeExports.jsx("pre", { className: buildClassName('bg-gray-100 p-3 rounded text-sm overflow-auto', textColorClass), children: jsxRuntimeExports.jsx("code", { children: getString(block) }) }));
|
|
2715
|
+
},
|
|
2716
|
+
'core/preformatted': ({ block, context }) => {
|
|
2717
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2718
|
+
const textColor = extractTextColor(block, context);
|
|
2719
|
+
const textColorClass = textColor || '';
|
|
2720
|
+
return jsxRuntimeExports.jsx("pre", { className: textColorClass || undefined, children: getString(block) });
|
|
2721
|
+
},
|
|
2667
2722
|
'core/table': ({ children }) => jsxRuntimeExports.jsx("div", { className: "overflow-x-auto", children: jsxRuntimeExports.jsx("table", { className: "table-auto w-full", children: children }) }),
|
|
2668
2723
|
'core/table-row': ({ children }) => jsxRuntimeExports.jsx("tr", { children: children }),
|
|
2669
|
-
'core/table-cell': ({ children }) =>
|
|
2724
|
+
'core/table-cell': ({ block, children, context }) => {
|
|
2725
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2726
|
+
const textColor = extractTextColor(block, context);
|
|
2727
|
+
const textColorClass = textColor || '';
|
|
2728
|
+
return jsxRuntimeExports.jsx("td", { className: buildClassName('border px-3 py-2', textColorClass), children: children });
|
|
2729
|
+
},
|
|
2670
2730
|
// Cover block - hero sections with background images
|
|
2671
2731
|
'core/cover': Cover,
|
|
2672
2732
|
// Media & Text block - side-by-side media and content
|
|
@@ -3019,6 +3079,7 @@ exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
|
|
|
3019
3079
|
exports.extractContent = extractContent;
|
|
3020
3080
|
exports.extractDimRatio = extractDimRatio;
|
|
3021
3081
|
exports.extractFontSize = extractFontSize;
|
|
3082
|
+
exports.extractGradientBackground = extractGradientBackground;
|
|
3022
3083
|
exports.extractHeadingLevel = extractHeadingLevel;
|
|
3023
3084
|
exports.extractImageAttributes = extractImageAttributes;
|
|
3024
3085
|
exports.extractImageUrl = extractImageUrl;
|
|
@@ -3034,6 +3095,7 @@ exports.extractTextColor = extractTextColor;
|
|
|
3034
3095
|
exports.extractTextFromHTML = extractTextFromHTML;
|
|
3035
3096
|
exports.extractTitle = extractTitle;
|
|
3036
3097
|
exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
|
|
3098
|
+
exports.extractTitleTextColorFromInnerBlocks = extractTitleTextColorFromInnerBlocks;
|
|
3037
3099
|
exports.extractVerticalAlignment = extractVerticalAlignment;
|
|
3038
3100
|
exports.extractVideoIframeFromInnerBlocks = extractVideoIframeFromInnerBlocks;
|
|
3039
3101
|
exports.findMatchingMapping = findMatchingMapping;
|