@wdprlib/parser 4.2.0 → 4.4.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.
Files changed (30) hide show
  1. package/README.md +28 -38
  2. package/dist/index.cjs +973 -134
  3. package/dist/index.d.cts +195 -158
  4. package/dist/index.d.ts +195 -158
  5. package/dist/index.js +955 -113
  6. package/package.json +2 -2
  7. package/src/index.ts +17 -0
  8. package/src/parser/parse/context.ts +1 -0
  9. package/src/parser/parse/options.ts +6 -0
  10. package/src/parser/parse/result.ts +3 -1
  11. package/src/parser/rules/block/gallery/index.ts +215 -0
  12. package/src/parser/rules/block/gallery/items.ts +62 -0
  13. package/src/parser/rules/block/index.ts +3 -0
  14. package/src/parser/rules/block/module/include/index.ts +6 -1
  15. package/src/parser/rules/block/module/include/resolve/index.ts +23 -3
  16. package/src/parser/rules/block/module/include/resolve/iterate.ts +71 -0
  17. package/src/parser/rules/block/module/index.ts +2 -1
  18. package/src/parser/rules/block/module/listpages/resolution/items.ts +2 -2
  19. package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +3 -3
  20. package/src/parser/rules/block/module/listusers/resolve.ts +2 -2
  21. package/src/parser/rules/block/module/resolution/document.ts +357 -0
  22. package/src/parser/rules/block/module/resolution/resolve-async.ts +269 -0
  23. package/src/parser/rules/block/module/resolution/styles.ts +134 -12
  24. package/src/parser/rules/block/module/resolution/walk-resolve.ts +19 -1
  25. package/src/parser/rules/block/module/resolve.ts +32 -13
  26. package/src/parser/rules/block/module/types.ts +7 -2
  27. package/src/parser/rules/contracts/parse-context.ts +1 -0
  28. package/src/pipeline/index.ts +7 -0
  29. package/src/pipeline/process.ts +105 -0
  30. package/src/pipeline/types.ts +63 -0
package/README.md CHANGED
@@ -11,53 +11,43 @@ bun add @wdprlib/parser
11
11
  ## Usage
12
12
 
13
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' } }
14
+ import { parse, processWikitext } from "@wdprlib/parser";
15
+
16
+ // Basic parsing keeps the AST-oriented low-level API available.
17
+ const { ast, diagnostics } = parse("**Hello** world");
18
+
19
+ // The high-level API expands includes, parses modules, and merges all
20
+ // side channels and diagnostics into one document.
21
+ const document = await processWikitext(source, {
22
+ page: {
23
+ fullName: "docs:start", // category-qualified Wikidot fullname
24
+ unixName: "start", // separately named URL-safe page identifier
25
+ tags: ["docs"],
26
+ urlPath: "/docs:start/offset/0",
39
27
  },
40
- fetchTagCloud: async ({ category, limit }) => {
41
- // Fetch up to `limit` tags (weight = page count) for `[[module TagCloud]]`,
42
- // ordered by weight descending. `category` is the raw, untrusted attribute
43
- // value look it up with a parameterized query and return the normalized name
44
- const found = category ? await findCategory(category) : null // your lookup
45
- if (category && !found) return { status: 'category-not-found', category }
46
- return { status: 'ok', tags: [{ tag: 'scp', weight: 42 }], category: found?.unixName ?? null }
28
+ dataProvider: {
29
+ fetchInclude: async (pageRef, { page }) => getPageSource(pageRef, page),
30
+ fetchListPages: async (query, requirement, { page }) => queryPages(query, requirement, page),
31
+ fetchListUsers: async (requirement, { page }) => queryUsers(requirement, page),
32
+ fetchTagCloud: async (requirement, { page }) => queryTags(requirement, page),
47
33
  },
48
- getPageTags: () => ['tag1', 'tag2'],
49
- }, {
50
- parse,
51
- compiledListPagesTemplates,
52
- requirements,
53
- })
34
+ });
35
+
36
+ document.ast;
37
+ document.diagnostics;
38
+ document.dependencies; // direct and transitive includes, including module output
54
39
  ```
55
40
 
41
+ Pass `document` to `renderWikitext()` from `@wdprlib/render` for HTML generation.
42
+ The parser and renderer remain separate packages and both depend only on the shared AST contract.
43
+
56
44
  ## Features
57
45
 
58
46
  - Wikidot markup parsing (bold, italic, links, images, tables, etc.)
59
47
  - Include resolution (`[[include page]]`)
60
48
  - Module support (ListPages, ListUsers, TagCloud, IfTags, etc.)
49
+ - `[[gallery]]` (auto-collection uses the page's attachments passed to `@wdprlib/render` as `page.files`; lightbox via `@wdprlib/runtime`)
50
+
61
51
  - Data extraction for server-side rendering
62
52
 
63
53
  ## Related Packages