@jxsuite/parser 0.10.2 → 0.12.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 +116 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# `@jxsuite/parser`
|
|
2
|
+
|
|
3
|
+
> Markdown parser and external class integration for Jx.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@jxsuite/parser` provides the content layer for Jx applications. It exports `MarkdownFile` and `MarkdownCollection` — external classes that satisfy the Jx `$prototype` + `$src` contract — and a `transpile` utility for converting Jx-flavored Markdown directly into Jx component objects.
|
|
8
|
+
|
|
9
|
+
Built on the [`unified`](https://unifiedjs.com/) / remark / rehype pipeline.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun add @jxsuite/parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## `MarkdownFile`
|
|
18
|
+
|
|
19
|
+
Parses a single Markdown file into structured data.
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"state": {
|
|
24
|
+
"post": {
|
|
25
|
+
"$prototype": "MarkdownFile",
|
|
26
|
+
"$src": "@jxsuite/parser/MarkdownFile.class.json",
|
|
27
|
+
"src": "./content/posts/hello-world.md"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Resolved value:**
|
|
34
|
+
|
|
35
|
+
| Property | Type | Description |
|
|
36
|
+
| -------------- | -------- | ----------------------------------- |
|
|
37
|
+
| `slug` | `string` | Filename without extension |
|
|
38
|
+
| `path` | `string` | Full file path |
|
|
39
|
+
| `frontmatter` | `object` | Parsed YAML frontmatter |
|
|
40
|
+
| `$body` | `string` | Rendered HTML body |
|
|
41
|
+
| `$excerpt` | `string` | First paragraph as HTML |
|
|
42
|
+
| `$toc` | `array` | Table of contents (id, text, depth) |
|
|
43
|
+
| `$readingTime` | `number` | Estimated reading time in minutes |
|
|
44
|
+
| `$wordCount` | `number` | Word count |
|
|
45
|
+
|
|
46
|
+
## `MarkdownCollection`
|
|
47
|
+
|
|
48
|
+
Globs Markdown files into a sorted, filterable collection.
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"state": {
|
|
53
|
+
"posts": {
|
|
54
|
+
"$prototype": "MarkdownCollection",
|
|
55
|
+
"$src": "@jxsuite/parser/MarkdownCollection.class.json",
|
|
56
|
+
"src": "./content/posts/*.md",
|
|
57
|
+
"sortBy": "date",
|
|
58
|
+
"sortOrder": "desc",
|
|
59
|
+
"limit": 10
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Returns an array of `MarkdownFile` resolved objects.
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
| ----------- | -------- | -------- | ----------------------------------- |
|
|
69
|
+
| `src` | `string` | — | Glob pattern for Markdown files |
|
|
70
|
+
| `sortBy` | `string` | `"date"` | Frontmatter field to sort by |
|
|
71
|
+
| `sortOrder` | `string` | `"desc"` | `"asc"` or `"desc"` |
|
|
72
|
+
| `limit` | `number` | — | Maximum number of results |
|
|
73
|
+
| `filter` | `string` | — | Frontmatter field filter expression |
|
|
74
|
+
|
|
75
|
+
## `MarkdownDirective` (remark plugin)
|
|
76
|
+
|
|
77
|
+
Maps `::directive{attrs}` syntax to custom element tags in HTML output. Parameters are encoded as a `data-jx-props` JSON attribute so Jx components can receive them via reactive state.
|
|
78
|
+
|
|
79
|
+
```markdown
|
|
80
|
+
:::my-card{title="Hello" image="/img/hero.png"}
|
|
81
|
+
Card body content here.
|
|
82
|
+
:::
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Produces:
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<my-card data-jx-props='{"title":"Hello","image":"/img/hero.png"}'>
|
|
89
|
+
<p>Card body content here.</p>
|
|
90
|
+
</my-card>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## `transpileJxMarkdown`
|
|
94
|
+
|
|
95
|
+
Converts a Jx-flavored Markdown source string directly into a Jx component object (no file I/O).
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { transpileJxMarkdown } from "@jxsuite/parser/transpile";
|
|
99
|
+
|
|
100
|
+
const doc = transpileJxMarkdown(markdownString);
|
|
101
|
+
// { tagName: "article", children: [...] }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Parsing pipeline
|
|
105
|
+
|
|
106
|
+
1. `remark-parse` — Markdown → MDAST
|
|
107
|
+
2. `remark-frontmatter` + `remark-parse-frontmatter` — YAML extraction
|
|
108
|
+
3. `remark-gfm` — GitHub Flavored Markdown
|
|
109
|
+
4. `remark-directive` — directive syntax
|
|
110
|
+
5. `MarkdownDirective` — directive nodes → custom element tags
|
|
111
|
+
6. `remark-rehype` — MDAST → HAST
|
|
112
|
+
7. `rehype-stringify` — HAST → HTML
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jxsuite/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Jx markdown parser and external class integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@happy-dom/global-registrator": "^20.9.0",
|
|
44
|
-
"@jxsuite/runtime": "^0.10.
|
|
44
|
+
"@jxsuite/runtime": "^0.10.2"
|
|
45
45
|
}
|
|
46
46
|
}
|