@wdprlib/parser 0.1.5 → 1.0.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,63 @@
1
+ # @wdprlib/parser
2
+
3
+ Wikidot markup parser.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @wdprlib/parser
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { parse, resolveIncludes, extractDataRequirements, resolveModules } from '@wdprlib/parser'
15
+ import type { SyntaxTree, PageRef } from '@wdprlib/parser'
16
+
17
+ // Basic parsing
18
+ const tree: SyntaxTree = parse('**Hello** world')
19
+
20
+ // Full pipeline with includes and modules
21
+ const source = '[[include component:box]]\n[[module ListPages]]\n%%title%%\n[[/module]]'
22
+
23
+ // 1. Resolve includes
24
+ const expanded = resolveIncludes(source, (ref: PageRef) => {
25
+ return getPageSource(ref.page) // your function to fetch page source
26
+ })
27
+
28
+ // 2. Parse
29
+ const ast = parse(expanded)
30
+
31
+ // 3. Extract data requirements for modules
32
+ const { requirements, compiledListPagesTemplates } = extractDataRequirements(ast)
33
+
34
+ // 4. Resolve modules with external data
35
+ const resolved = await resolveModules(ast, {
36
+ fetchListPages: async (query) => {
37
+ // Fetch pages matching query from your database
38
+ return { pages: [...], totalCount: 100, site: { name: 'mysite' } }
39
+ },
40
+ getPageTags: () => ['tag1', 'tag2'],
41
+ }, {
42
+ parse,
43
+ compiledListPagesTemplates,
44
+ requirements,
45
+ })
46
+ ```
47
+
48
+ ## Features
49
+
50
+ - Wikidot markup parsing (bold, italic, links, images, tables, etc.)
51
+ - Include resolution (`[[include page]]`)
52
+ - Module support (ListPages, ListUsers, IfTags, etc.)
53
+ - Data extraction for server-side rendering
54
+
55
+ ## Related Packages
56
+
57
+ - [@wdprlib/ast](https://www.npmjs.com/package/@wdprlib/ast) - AST type definitions
58
+ - [@wdprlib/render](https://www.npmjs.com/package/@wdprlib/render) - HTML renderer
59
+ - [@wdprlib/runtime](https://www.npmjs.com/package/@wdprlib/runtime) - Client-side runtime
60
+
61
+ ## License
62
+
63
+ AGPL-3.0 - See [LICENSE](https://github.com/r74tech/wdpr/blob/develop/LICENSE)