@marvalt/wparser 0.1.35 → 0.1.39
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.esm.js
CHANGED
|
@@ -1756,7 +1756,17 @@ function extractImageUrl(block) {
|
|
|
1756
1756
|
* Extract image attributes (url, alt, width, height)
|
|
1757
1757
|
*/
|
|
1758
1758
|
function extractImageAttributes(block) {
|
|
1759
|
-
|
|
1759
|
+
const attrs = getImageAttributes(block);
|
|
1760
|
+
// Convert width to number if it's a string
|
|
1761
|
+
const width = typeof attrs.width === 'string'
|
|
1762
|
+
? (parseInt(attrs.width, 10) || undefined)
|
|
1763
|
+
: attrs.width;
|
|
1764
|
+
return {
|
|
1765
|
+
url: attrs.url,
|
|
1766
|
+
alt: attrs.alt,
|
|
1767
|
+
width,
|
|
1768
|
+
height: attrs.height,
|
|
1769
|
+
};
|
|
1760
1770
|
}
|
|
1761
1771
|
/**
|
|
1762
1772
|
* Extract title/heading text from a block
|
|
@@ -2260,16 +2270,20 @@ function getHeadingSpacing(spacingConfig, level) {
|
|
|
2260
2270
|
return headingConfig?.h3 || 'mt-6 mb-4';
|
|
2261
2271
|
}
|
|
2262
2272
|
const Paragraph = ({ block, context }) => {
|
|
2263
|
-
const content = getBlockTextContent(block);
|
|
2264
2273
|
const attrs = block.attributes || {};
|
|
2265
2274
|
const textAlign = getTextAlignClasses(attrs['align']);
|
|
2266
2275
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'paragraph', 'my-6');
|
|
2267
|
-
// Check if
|
|
2268
|
-
const
|
|
2276
|
+
// Check if innerHTML contains HTML elements (like links, strong, em, etc.)
|
|
2277
|
+
const hasHTML = block.innerHTML && /<[a-z][\s\S]*>/i.test(block.innerHTML);
|
|
2278
|
+
// Check if content contains shortcodes (check both HTML and text content)
|
|
2279
|
+
const htmlContent = block.innerHTML || '';
|
|
2280
|
+
const textContent = getBlockTextContent(block);
|
|
2281
|
+
const hasShortcodes = /\[(\w+)/.test(htmlContent) || /\[(\w+)/.test(textContent);
|
|
2282
|
+
// If shortcodes are present, always process them (even if HTML is also present)
|
|
2269
2283
|
if (hasShortcodes && context.registry.shortcodes) {
|
|
2270
|
-
|
|
2284
|
+
// Process shortcodes from text content
|
|
2285
|
+
const parts = renderTextWithShortcodes(textContent, context.registry);
|
|
2271
2286
|
// Check if any part is a block-level element (section, div, etc.)
|
|
2272
|
-
// If so, render without wrapping in <p> to avoid DOM nesting violations
|
|
2273
2287
|
const isBlockLevelElement = (element) => {
|
|
2274
2288
|
if (!React.isValidElement(element)) {
|
|
2275
2289
|
return false;
|
|
@@ -2286,7 +2300,6 @@ const Paragraph = ({ block, context }) => {
|
|
|
2286
2300
|
return children.some((child) => isBlockLevelElement(child));
|
|
2287
2301
|
}
|
|
2288
2302
|
// Check if it's a React component (likely block-level)
|
|
2289
|
-
// Most custom components render block-level content
|
|
2290
2303
|
if (typeof type === 'function' || (typeof type === 'object' && type !== null && type !== React.Fragment)) {
|
|
2291
2304
|
return true;
|
|
2292
2305
|
}
|
|
@@ -2297,11 +2310,15 @@ const Paragraph = ({ block, context }) => {
|
|
|
2297
2310
|
// Render block-level content without <p> wrapper, but add spacing wrapper
|
|
2298
2311
|
return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
|
|
2299
2312
|
}
|
|
2300
|
-
//
|
|
2313
|
+
// Render shortcode parts inside paragraph (shortcodes are processed as React components)
|
|
2301
2314
|
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
|
|
2302
2315
|
}
|
|
2303
|
-
//
|
|
2304
|
-
|
|
2316
|
+
// If innerHTML contains HTML elements but no shortcodes, render it directly (preserves links, formatting, etc.)
|
|
2317
|
+
if (hasHTML && block.innerHTML) {
|
|
2318
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), dangerouslySetInnerHTML: { __html: htmlContent } });
|
|
2319
|
+
}
|
|
2320
|
+
// No HTML and no shortcodes, just render plain text content
|
|
2321
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: textContent });
|
|
2305
2322
|
};
|
|
2306
2323
|
const Heading = ({ block, children, context }) => {
|
|
2307
2324
|
const attrs = block.attributes || {};
|