markedin-parser 0.1.0 โ 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 +124 -0
- package/package.json +9 -2
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# markedin-parser
|
|
2
|
+
|
|
3
|
+
Parse and render `.mi` (markedin) files โ Structured data in the frontmatter, readable prose in the rendered body.
|
|
4
|
+
|
|
5
|
+
Markedin (`.mi`) is a file format for both machines and humans. ๐ค YAML frontmatter + templated Markdown. No framework required.
|
|
6
|
+
|
|
7
|
+
Full documentation at [markedin.dev](https://markedin.dev)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install markedin-parser
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Markedin .mi Format
|
|
16
|
+
|
|
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
|
+
---
|
|
34
|
+
|
|
35
|
+
# {{task}}
|
|
36
|
+
|
|
37
|
+
**Status:** {{status}} ยท **Owner:** {{owner.name}} ({{owner.team}}) ยท **Priority:** {{priority}}
|
|
38
|
+
|
|
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");
|
|
70
|
+
|
|
71
|
+
const source = fs.readFileSync("task.mi", "utf8");
|
|
72
|
+
|
|
73
|
+
// Extract frontmatter and body
|
|
74
|
+
const { data, body } = parse(source);
|
|
75
|
+
// data โ { task: 'Implement rate limiting', status: 'in_progress', owner: { name: 'Dana', ... }, ... }
|
|
76
|
+
|
|
77
|
+
// Render to markdown (template expressions resolved)
|
|
78
|
+
render(source);
|
|
79
|
+
|
|
80
|
+
// Render to HTML fragment
|
|
81
|
+
renderHtmlFrag(source);
|
|
82
|
+
|
|
83
|
+
// Render to full HTML document with styles
|
|
84
|
+
renderHtml(source);
|
|
85
|
+
|
|
86
|
+
// Embed frontmatter in output
|
|
87
|
+
render(source, { embed: true }); // appends as HTML comment
|
|
88
|
+
renderHtml(source, { embed: true }); // adds <script> tag in <head>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Markedin Parser API
|
|
92
|
+
|
|
93
|
+
### `parse(source)` โ `{ data, body }`
|
|
94
|
+
|
|
95
|
+
Extract YAML frontmatter and body. Does not resolve template expressions.
|
|
96
|
+
|
|
97
|
+
### `render(source, options?)` โ `string`
|
|
98
|
+
|
|
99
|
+
Resolve all template expressions and return rendered Markdown.
|
|
100
|
+
|
|
101
|
+
Options: `{ embed: true }` appends frontmatter as an HTML comment.
|
|
102
|
+
|
|
103
|
+
### `renderHtmlFrag(source)` โ `string`
|
|
104
|
+
|
|
105
|
+
Render to an HTML fragment โ no document wrapper.
|
|
106
|
+
|
|
107
|
+
### `renderHtml(source, options?)` โ `string`
|
|
108
|
+
|
|
109
|
+
Render to a full HTML document with styles.
|
|
110
|
+
|
|
111
|
+
Options: `{ embed: true }` includes frontmatter as a `<script type="application/json">` tag in `<head>`.
|
|
112
|
+
|
|
113
|
+
### `resolvePath(data, path)` โ `any`
|
|
114
|
+
|
|
115
|
+
Resolve a dotted/bracketed path against a data object.
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
resolvePath(data, "owner.name"); // โ 'Dana'
|
|
119
|
+
resolvePath(data, "notes[0]"); // โ 'Token bucket algorithm chosen over leaky bucket'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
Apache 2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markedin-parser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Parse and render .mi (markedin) files โ YAML frontmatter + templated Markdown",
|
|
5
5
|
"main": "parse.js",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"author": "Jason Stonebraker",
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"keywords": [
|
|
23
|
+
"keywords": [
|
|
24
|
+
"markedin",
|
|
25
|
+
"mi",
|
|
26
|
+
"frontmatter",
|
|
27
|
+
"yaml",
|
|
28
|
+
"markdown",
|
|
29
|
+
"template"
|
|
30
|
+
],
|
|
24
31
|
"dependencies": {
|
|
25
32
|
"js-yaml": "^4.1.1",
|
|
26
33
|
"marked": "^17.0.4"
|