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