markedin-parser 0.1.1 → 0.1.2
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 +59 -75
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,37 +12,67 @@ Full documentation at [markedin.dev](https://markedin.dev)
|
|
|
12
12
|
npm install markedin-parser
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Markedin .mi Format
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
|
|
17
|
+
A `.mi` file has YAML frontmatter between `---` delimiters and a Markdown body that renders from it.
|
|
18
|
+
|
|
19
|
+
`task.mi`:
|
|
20
|
+
```
|
|
21
|
+
---
|
|
22
|
+
task: Implement rate limiting
|
|
23
|
+
status: in_progress
|
|
24
|
+
owner:
|
|
25
|
+
name: Dana
|
|
26
|
+
team: Platform
|
|
27
|
+
priority: high
|
|
28
|
+
notes:
|
|
29
|
+
- Token bucket algorithm chosen over leaky bucket
|
|
30
|
+
- Limit is 100 req/min per API key
|
|
31
|
+
- Redis required for distributed enforcement
|
|
32
|
+
blocked: false
|
|
33
33
|
---
|
|
34
34
|
|
|
35
|
-
# {{
|
|
35
|
+
# {{task}}
|
|
36
|
+
|
|
37
|
+
**Status:** {{status}} · **Owner:** {{owner.name}} ({{owner.team}}) · **Priority:** {{priority}}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
First note: {{notes[0]}}
|
|
40
|
+
|
|
41
|
+
## Notes
|
|
42
|
+
|
|
43
|
+
{{#each notes}}
|
|
44
|
+
- {{this}}
|
|
45
|
+
{{/each}}
|
|
46
|
+
|
|
47
|
+
{{#if blocked}}
|
|
48
|
+
⚠️ This task is currently blocked.
|
|
49
|
+
{{else}}
|
|
50
|
+
✅ No blockers.
|
|
51
|
+
{{/if}}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Template Expressions
|
|
55
|
+
|
|
56
|
+
| Expression | Description |
|
|
57
|
+
| ---------------------------------- | -------------------------------------------- |
|
|
58
|
+
| `{{key}}` | Scalar value (arrays render comma-separated) |
|
|
59
|
+
| `{{key.nested}}` | Dot-path into objects |
|
|
60
|
+
| `{{array[0]}}` | Array index access |
|
|
61
|
+
| `{{#each items}}...{{/each}}` | Iterate an array |
|
|
62
|
+
| `{{#if key}}...{{else}}...{{/if}}` | Conditional block |
|
|
63
|
+
| `{{> key}}` | Inline a frontmatter string as raw text |
|
|
64
|
+
|
|
65
|
+
## Parsing and Rendering a Markedin File
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const fs = require("fs");
|
|
69
|
+
const { parse, render, renderHtmlFrag, renderHtml } = require("markedin-parser");
|
|
38
70
|
|
|
39
|
-
|
|
40
|
-
- **{{name}}** — {{status}}
|
|
41
|
-
{{/each}}`;
|
|
71
|
+
const source = fs.readFileSync("task.mi", "utf8");
|
|
42
72
|
|
|
43
73
|
// Extract frontmatter and body
|
|
44
74
|
const { data, body } = parse(source);
|
|
45
|
-
// data → {
|
|
75
|
+
// data → { task: 'Implement rate limiting', status: 'in_progress', owner: { name: 'Dana', ... }, ... }
|
|
46
76
|
|
|
47
77
|
// Render to markdown (template expressions resolved)
|
|
48
78
|
render(source);
|
|
@@ -54,11 +84,11 @@ renderHtmlFrag(source);
|
|
|
54
84
|
renderHtml(source);
|
|
55
85
|
|
|
56
86
|
// Embed frontmatter in output
|
|
57
|
-
render(source, { embed: true });
|
|
58
|
-
renderHtml(source, { embed: true });
|
|
87
|
+
render(source, { embed: true }); // appends as HTML comment
|
|
88
|
+
renderHtml(source, { embed: true }); // adds <script> tag in <head>
|
|
59
89
|
```
|
|
60
90
|
|
|
61
|
-
## API
|
|
91
|
+
## Markedin Parser API
|
|
62
92
|
|
|
63
93
|
### `parse(source)` → `{ data, body }`
|
|
64
94
|
|
|
@@ -85,56 +115,10 @@ Options: `{ embed: true }` includes frontmatter as a `<script type="application/
|
|
|
85
115
|
Resolve a dotted/bracketed path against a data object.
|
|
86
116
|
|
|
87
117
|
```javascript
|
|
88
|
-
resolvePath(data, "
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
## Template expressions
|
|
92
|
-
|
|
93
|
-
| Expression | Description |
|
|
94
|
-
| ---------------------------------- | -------------------------------------------- |
|
|
95
|
-
| `{{key}}` | Scalar value (arrays render comma-separated) |
|
|
96
|
-
| `{{key.nested}}` | Dot-path into objects |
|
|
97
|
-
| `{{array[0]}}` | Array index access |
|
|
98
|
-
| `{{#each items}}...{{/each}}` | Iterate an array |
|
|
99
|
-
| `{{#if key}}...{{else}}...{{/if}}` | Conditional block |
|
|
100
|
-
| `{{> key}}` | Inline a frontmatter string as raw text |
|
|
101
|
-
|
|
102
|
-
## Example
|
|
103
|
-
|
|
104
|
-
```
|
|
105
|
-
---
|
|
106
|
-
task: Implement rate limiting
|
|
107
|
-
status: in_progress
|
|
108
|
-
owner:
|
|
109
|
-
name: Dana
|
|
110
|
-
team: Platform
|
|
111
|
-
priority: high
|
|
112
|
-
notes:
|
|
113
|
-
- Token bucket algorithm chosen over leaky bucket
|
|
114
|
-
- Limit is 100 req/min per API key
|
|
115
|
-
- Redis required for distributed enforcement
|
|
116
|
-
blocked: false
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
# {{task}}
|
|
120
|
-
|
|
121
|
-
**Status:** {{status}} · **Owner:** {{owner.name}} ({{owner.team}}) · **Priority:** {{priority}}
|
|
122
|
-
|
|
123
|
-
First note: {{notes[0]}}
|
|
124
|
-
|
|
125
|
-
## Notes
|
|
126
|
-
|
|
127
|
-
{{#each notes}}
|
|
128
|
-
- {{this}}
|
|
129
|
-
{{/each}}
|
|
130
|
-
|
|
131
|
-
{{#if blocked}}
|
|
132
|
-
⚠️ This task is currently blocked.
|
|
133
|
-
{{else}}
|
|
134
|
-
✅ No blockers.
|
|
135
|
-
{{/if}}
|
|
118
|
+
resolvePath(data, "owner.name"); // → 'Dana'
|
|
119
|
+
resolvePath(data, "notes[0]"); // → 'Token bucket algorithm chosen over leaky bucket'
|
|
136
120
|
```
|
|
137
121
|
|
|
138
122
|
## License
|
|
139
123
|
|
|
140
|
-
|
|
124
|
+
Apache 2.0
|