@marvalt/wparser 0.1.38 → 0.1.40

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
@@ -2277,57 +2277,14 @@ const Paragraph = ({ block, context }) => {
2277
2277
  const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'paragraph', 'my-6');
2278
2278
  // Check if innerHTML contains HTML elements (like links, strong, em, etc.)
2279
2279
  const hasHTML = block.innerHTML && /<[a-z][\s\S]*>/i.test(block.innerHTML);
2280
- // If innerHTML contains HTML elements, render it directly (preserves links, formatting, etc.)
2281
- if (hasHTML && block.innerHTML) {
2282
- const htmlContent = block.innerHTML;
2283
- // Check if HTML contains shortcodes
2284
- const hasShortcodes = /\[(\w+)/.test(htmlContent);
2285
- if (hasShortcodes && context.registry.shortcodes) {
2286
- // For HTML with shortcodes, we need to process shortcodes first
2287
- // Extract text content to process shortcodes, then reconstruct
2288
- const textContent = getBlockTextContent(block);
2289
- const parts = renderTextWithShortcodes(textContent, context.registry);
2290
- // Check if any part is a block-level element (section, div, etc.)
2291
- const isBlockLevelElement = (element) => {
2292
- if (!React.isValidElement(element)) {
2293
- return false;
2294
- }
2295
- const type = element.type;
2296
- // Check for block-level HTML elements
2297
- if (typeof type === 'string' && ['section', 'div', 'article', 'header', 'footer', 'aside', 'nav'].includes(type)) {
2298
- return true;
2299
- }
2300
- // Check if it's React.Fragment - recursively check its children
2301
- if (type === React.Fragment) {
2302
- const fragmentProps = element.props;
2303
- const children = React.Children.toArray(fragmentProps.children);
2304
- return children.some((child) => isBlockLevelElement(child));
2305
- }
2306
- // Check if it's a React component (likely block-level)
2307
- if (typeof type === 'function' || (typeof type === 'object' && type !== null && type !== React.Fragment)) {
2308
- return true;
2309
- }
2310
- return false;
2311
- };
2312
- const hasBlockLevelContent = React.Children.toArray(parts).some((part) => isBlockLevelElement(part));
2313
- if (hasBlockLevelContent) {
2314
- // Render block-level content without <p> wrapper, but add spacing wrapper
2315
- return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
2316
- }
2317
- // For mixed HTML and shortcodes, render shortcode parts but this is complex
2318
- // For now, fall back to rendering HTML with shortcodes processed in text
2319
- // This is a limitation - shortcodes in HTML paragraphs with links won't work perfectly
2320
- // But links will be preserved
2321
- return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), dangerouslySetInnerHTML: { __html: htmlContent } });
2322
- }
2323
- // No shortcodes, just render HTML directly (preserves links, formatting, etc.)
2324
- return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), dangerouslySetInnerHTML: { __html: htmlContent } });
2325
- }
2326
- // No HTML, use text content (existing logic for shortcodes)
2327
- const content = getBlockTextContent(block);
2328
- const hasShortcodes = /\[(\w+)/.test(content);
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)
2329
2285
  if (hasShortcodes && context.registry.shortcodes) {
2330
- const parts = renderTextWithShortcodes(content, context.registry);
2286
+ // Process shortcodes from text content
2287
+ const parts = renderTextWithShortcodes(textContent, context.registry);
2331
2288
  // Check if any part is a block-level element (section, div, etc.)
2332
2289
  const isBlockLevelElement = (element) => {
2333
2290
  if (!React.isValidElement(element)) {
@@ -2355,11 +2312,15 @@ const Paragraph = ({ block, context }) => {
2355
2312
  // Render block-level content without <p> wrapper, but add spacing wrapper
2356
2313
  return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
2357
2314
  }
2358
- // 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)
2359
2316
  return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
2360
2317
  }
2361
- // Don't hardcode text color - let it inherit from parent (e.g., column with background color)
2362
- 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 });
2363
2324
  };
2364
2325
  const Heading = ({ block, children, context }) => {
2365
2326
  const attrs = block.attributes || {};