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