@wdprlib/parser 4.3.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.
- package/README.md +26 -38
- package/dist/index.cjs +801 -134
- package/dist/index.d.cts +195 -158
- package/dist/index.d.ts +195 -158
- package/dist/index.js +783 -113
- package/package.json +2 -2
- package/src/index.ts +11 -0
- package/src/parser/parse/context.ts +1 -0
- package/src/parser/parse/options.ts +6 -0
- package/src/parser/parse/result.ts +3 -1
- package/src/parser/rules/block/module/include/index.ts +6 -1
- package/src/parser/rules/block/module/include/resolve/index.ts +23 -3
- package/src/parser/rules/block/module/include/resolve/iterate.ts +71 -0
- package/src/parser/rules/block/module/index.ts +2 -1
- package/src/parser/rules/block/module/listpages/resolution/items.ts +2 -2
- package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +3 -3
- package/src/parser/rules/block/module/listusers/resolve.ts +2 -2
- package/src/parser/rules/block/module/resolution/document.ts +357 -0
- package/src/parser/rules/block/module/resolution/resolve-async.ts +269 -0
- package/src/parser/rules/block/module/resolution/styles.ts +134 -12
- package/src/parser/rules/block/module/resolution/walk-resolve.ts +19 -1
- package/src/parser/rules/block/module/resolve.ts +32 -13
- package/src/parser/rules/block/module/types.ts +7 -2
- package/src/parser/rules/contracts/parse-context.ts +1 -0
- package/src/pipeline/index.ts +7 -0
- package/src/pipeline/process.ts +105 -0
- package/src/pipeline/types.ts +63 -0
package/README.md
CHANGED
|
@@ -11,48 +11,36 @@ bun add @wdprlib/parser
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { parse,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (category && !found) return { status: 'category-not-found', category }
|
|
46
|
-
return { status: 'ok', tags: [{ tag: 'apple', 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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.)
|