@marvalt/wparser 0.1.0

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/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @marvalt/wparser (WordPress Pages Parser)
2
+
3
+ Static-only WordPress page parser and renderer for React apps.
4
+
5
+ - Input: Gutenberg blocks from static JSON
6
+ - Output: React components styled via your theme
7
+ - No live refresh; static data only
8
+ - Auto-hero uses featured image unless `[HEROSECTION]` is present
9
+ - Extensible: future adapters (Elementor/Divi) via registry
10
+
11
+ ## Installation
12
+
13
+ Peer deps: React 18+
14
+
15
+ ```bash
16
+ npm install
17
+ npm run build -w digivalt-npm-packages/marvalt-wparser
18
+ ```
19
+
20
+ ## Security
21
+ - Content is rendered as text; no HTML is injected by default.
22
+ - If you enable any HTML rendering in custom renderers, sanitize first and use a CSP.
23
+ - Use trusted WordPress sources; this package assumes trusted input for v0.1.0.
24
+
25
+ ## Data shape (required)
26
+ - Gutenberg blocks only (no HTML fallback in v0.1.0)
27
+ - Minimal page type:
28
+
29
+ ```ts
30
+ interface WordPressPageMinimal {
31
+ id: number;
32
+ slug: string;
33
+ title?: { rendered: string };
34
+ blocks: Array<{
35
+ name: string;
36
+ attributes?: Record<string, unknown>;
37
+ innerBlocks?: any[];
38
+ innerHTML?: string;
39
+ }>;
40
+ _embedded?: { 'wp:featuredmedia'?: Array<{ source_url?: string; alt_text?: string }> };
41
+ }
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ```tsx
47
+ import { WPContent, WPPage, createDefaultRegistry, WPErrorBoundary } from '@marvalt/wparser';
48
+
49
+ const registry = createDefaultRegistry();
50
+
51
+ <WPErrorBoundary>
52
+ <WPPage page={page} registry={registry} />
53
+ </WPErrorBoundary>
54
+
55
+ <WPContent blocks={page.blocks} registry={registry} />
56
+ ```
57
+
58
+ ## Supported core blocks (default registry)
59
+ - paragraph, heading, image, list, list-item, group, columns, column, separator, buttons/button, quote, code, preformatted, table (+ row/cell)
60
+
61
+ ## Custom renderers
62
+ Extend or replace mappings:
63
+
64
+ ```ts
65
+ const registry = createDefaultRegistry();
66
+ registry.renderers['core/paragraph'] = ({ block }) => <p className="my-2">{String(block.attributes?.content || '')}</p>;
67
+ ```
68
+
69
+ ## API
70
+ - `parseGutenbergBlocks(blocks)` → returns normalized block tree
71
+ - `renderNodes(blocks, registry, { debugWrappers? })` → React nodes
72
+ - `createDefaultRegistry()` → default mapping
73
+ - `WPContent`, `WPPage` components
74
+ - `WPErrorBoundary`
75
+
76
+ ## Notes
77
+ - No environment handling in v0.1.0.
78
+ - Tailwind classes are used in defaults; replace or override as needed.
79
+
80
+ ## Roadmap
81
+ - Shortcodes/embeds/ACF plugins
82
+ - Optional adapters: Elementor, Divi (as separate packages)
83
+ - Error boundary customization and logging hooks