@wazootech/linked-markdown 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +152 -2
- package/THIRD_PARTY_NOTICES.md +118 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +2847 -0
- package/package.json +57 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wazoo Technology
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,153 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://docs.wazoo.dev">
|
|
3
|
+
<img src="https://wazoo.dev/assets/wazoo.svg" alt="Wazoo Worlds" width="120" />
|
|
4
|
+
</a>
|
|
5
|
+
<br /><br />
|
|
6
|
+
<em>TypeScript implementation of Linked Markdown.</em>
|
|
7
|
+
<br /><br />
|
|
8
|
+
<a href="https://www.npmjs.com/package/@wazootech/linked-markdown"><img src="https://img.shields.io/npm/v/%40wazootech%2Flinked-markdown" alt="npm" /></a>
|
|
9
|
+
<a href="https://github.com/wazootech/linked-markdown-ts"><img src="https://img.shields.io/badge/GitHub-black?logo=github" alt="GitHub" /></a>
|
|
10
|
+
<a href="https://deepwiki.com/wazootech/linked-markdown-ts"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki" /></a>
|
|
11
|
+
</p>
|
|
2
12
|
|
|
3
|
-
|
|
13
|
+
Reads the YAML, JSON or TOML front matter of a Markdown document as JSON-LD. The
|
|
14
|
+
package has no dependencies, and works on Node.js, Bun, Deno and in browsers.
|
|
15
|
+
|
|
16
|
+
See the
|
|
17
|
+
[wazootech/linked-markdown](https://github.com/wazootech/linked-markdown)
|
|
18
|
+
repository for the specification, conformance suite, and reference
|
|
19
|
+
documentation.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @wazootech/linked-markdown # Node.js 22 or newer
|
|
25
|
+
bun add @wazootech/linked-markdown # Bun
|
|
26
|
+
deno add npm:@wazootech/linked-markdown # Deno
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Deno waits a day before it installs a new release. To get one sooner, add
|
|
30
|
+
`--minimum-dependency-age=0` to the command.
|
|
31
|
+
|
|
32
|
+
Version 0.1.0 was published on JSR as `@wazoo/linked-markdown`. The exports are
|
|
33
|
+
the same. One result changed: a document that is only an opening marker, such as
|
|
34
|
+
`+++`, now throws `LMD_INVALID_FRONTMATTER` instead of `LMD_NO_FRONTMATTER`.
|
|
35
|
+
|
|
36
|
+
### In a browser, without a build step
|
|
37
|
+
|
|
38
|
+
[esm.sh](https://esm.sh) serves the package as an ES module. An import map lets
|
|
39
|
+
browser modules import it by name.
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<script type="importmap">
|
|
43
|
+
{
|
|
44
|
+
"imports": {
|
|
45
|
+
"@wazootech/linked-markdown": "https://esm.sh/@wazootech/linked-markdown@0.1.1"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
<script type="module">
|
|
50
|
+
import { extract } from "@wazootech/linked-markdown";
|
|
51
|
+
</script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { extract, LinkedMarkdownError } from "@wazootech/linked-markdown";
|
|
58
|
+
|
|
59
|
+
const result = extract(markdown);
|
|
60
|
+
// => { attrs: { "@id": "...", "@type": "...", ... }, frontMatter: "...", body: "..." }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `extract<T>(content: string): { attrs: T, frontMatter: string, body: string }`
|
|
64
|
+
|
|
65
|
+
Parses frontmatter from a Linked Markdown document. Supports YAML (`---`,
|
|
66
|
+
`---yaml`, `= yaml =`), JSON (`---`, `---json`, `= json =`), and TOML
|
|
67
|
+
(`---toml`, `+++`, `= toml =`) formats.
|
|
68
|
+
|
|
69
|
+
- Strips UTF-8 BOM and normalizes CRLF to LF before parsing.
|
|
70
|
+
- Returns `frontMatter` with a trailing newline for non-empty frontmatter
|
|
71
|
+
(matching the conformance spec).
|
|
72
|
+
- `frontMatter` is `""` for empty frontmatter (`---\n---`).
|
|
73
|
+
- `body` has leading newlines stripped (after the closing delimiter).
|
|
74
|
+
|
|
75
|
+
### `LinkedMarkdownError`
|
|
76
|
+
|
|
77
|
+
Thrown for all error conditions. Has a `code` property for programmatic
|
|
78
|
+
handling:
|
|
79
|
+
|
|
80
|
+
| Code | When |
|
|
81
|
+
| ------------------------- | ------------------------------------------------------------------------------ |
|
|
82
|
+
| `LMD_NO_FRONTMATTER` | No frontmatter delimiters found |
|
|
83
|
+
| `LMD_INVALID_FRONTMATTER` | Unknown marker, unparseable content, non-object attrs, or no closing delimiter |
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
try {
|
|
87
|
+
extract(markdown);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (e instanceof LinkedMarkdownError && e.code === "LMD_NO_FRONTMATTER") {
|
|
90
|
+
// handle
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### RDF Compatibility
|
|
96
|
+
|
|
97
|
+
The `attrs` returned by `extract()` is valid JSON-LD, directly convertible to
|
|
98
|
+
RDF/JS quads:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import jsonld from "jsonld";
|
|
102
|
+
|
|
103
|
+
const result = extract(markdown);
|
|
104
|
+
const quads = await jsonld.toRDF(result.attrs);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
git submodule update --init --recursive
|
|
111
|
+
bun install
|
|
112
|
+
|
|
113
|
+
# Format, lint, type check and tests (what CI runs)
|
|
114
|
+
bun run ci
|
|
115
|
+
|
|
116
|
+
# Build the npm package, install it in an empty project, and use it on Node.js,
|
|
117
|
+
# Bun and Deno, which must all be on your PATH (CI runs this too)
|
|
118
|
+
bun run build && bun run check:package
|
|
119
|
+
|
|
120
|
+
# Run all tests
|
|
121
|
+
bun test
|
|
122
|
+
|
|
123
|
+
# Run conformance tests only
|
|
124
|
+
bun test test/conformance_test.ts
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The conformance suite is consumed from the `wazootech/linked-markdown` spec
|
|
128
|
+
repository as a git submodule.
|
|
129
|
+
|
|
130
|
+
## Releases
|
|
131
|
+
|
|
132
|
+
To publish a version, bump `version` in `package.json` in a pull request (a
|
|
133
|
+
patch, unless the change breaks callers) and merge it. There is no tag or GitHub
|
|
134
|
+
release to create. A merge that doesn't change the version publishes nothing.
|
|
135
|
+
|
|
136
|
+
The Publish workflow runs the tests, checks the packed file on Node.js, Bun and
|
|
137
|
+
Deno, and publishes that same file. A version with a suffix, such as
|
|
138
|
+
`0.2.0-rc.0`, goes to the `next` tag instead of `latest`.
|
|
139
|
+
|
|
140
|
+
npm accepts the publish because this repository's `publish.yml` is the package's
|
|
141
|
+
trusted publisher, so there is no npm token to store or rotate. After publishing,
|
|
142
|
+
a second job installs the new version from npm and checks it. If only that job
|
|
143
|
+
fails, re-run it on its own.
|
|
144
|
+
|
|
145
|
+
## Shoulders
|
|
146
|
+
|
|
147
|
+
This implementation stands on the shoulders of:
|
|
148
|
+
|
|
149
|
+
- [`@std/front-matter`](https://jsr.io/@std/front-matter): front matter
|
|
150
|
+
extraction for JSON, YAML, and TOML formats. It is built into the package;
|
|
151
|
+
[`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) has its license.
|
|
152
|
+
- [`wazootech/linked-markdown`](https://github.com/wazootech/linked-markdown):
|
|
153
|
+
the Linked Markdown specification and conformance suite
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`dist/index.js` includes code from the projects below. Their licenses are
|
|
4
|
+
reproduced as those licenses require.
|
|
5
|
+
|
|
6
|
+
## Deno Standard Library
|
|
7
|
+
|
|
8
|
+
`@std/front-matter`, `@std/toml`, `@std/yaml` and `@std/collections`, from
|
|
9
|
+
<https://github.com/denoland/std>.
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
MIT License
|
|
13
|
+
|
|
14
|
+
Copyright 2018-2022 the Deno authors.
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
SOFTWARE.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## front-matter
|
|
36
|
+
|
|
37
|
+
`@std/front-matter` is adapted from <https://github.com/jxson/front-matter>.
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
# The MIT License (MIT)
|
|
41
|
+
|
|
42
|
+
Copyright (c) Jason Campbell ("Author")
|
|
43
|
+
|
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
45
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
46
|
+
in the Software without restriction, including without limitation the rights
|
|
47
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
48
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
49
|
+
furnished to do so, subject to the following conditions:
|
|
50
|
+
|
|
51
|
+
The above copyright notice and this permission notice shall be included in
|
|
52
|
+
all copies or substantial portions of the Software.
|
|
53
|
+
|
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
55
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
56
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
57
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
58
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
59
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
60
|
+
SOFTWARE.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## js-yaml
|
|
64
|
+
|
|
65
|
+
`@std/yaml` is ported from <https://github.com/nodeca/js-yaml>.
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
(The MIT License)
|
|
69
|
+
|
|
70
|
+
Copyright (C) 2011-2015 by Vitaly Puzrin
|
|
71
|
+
|
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
73
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
74
|
+
in the Software without restriction, including without limitation the rights
|
|
75
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
77
|
+
furnished to do so, subject to the following conditions:
|
|
78
|
+
|
|
79
|
+
The above copyright notice and this permission notice shall be included in
|
|
80
|
+
all copies or substantial portions of the Software.
|
|
81
|
+
|
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
83
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
84
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
85
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
86
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
87
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
88
|
+
THE SOFTWARE.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## js-yaml-js-types
|
|
92
|
+
|
|
93
|
+
Parts of `@std/yaml` are ported from
|
|
94
|
+
<https://github.com/nodeca/js-yaml-js-types>.
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
(The MIT License)
|
|
98
|
+
|
|
99
|
+
Copyright (C) 2020 by authors
|
|
100
|
+
|
|
101
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
102
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
103
|
+
in the Software without restriction, including without limitation the rights
|
|
104
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
105
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
106
|
+
furnished to do so, subject to the following conditions:
|
|
107
|
+
|
|
108
|
+
The above copyright notice and this permission notice shall be included in
|
|
109
|
+
all copies or substantial portions of the Software.
|
|
110
|
+
|
|
111
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
112
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
113
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
114
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
115
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
116
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
117
|
+
THE SOFTWARE.
|
|
118
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Return type for {@linkcode extract} function. */ type Extract<T> = {
|
|
2
|
+
frontMatter: string;
|
|
3
|
+
body: string;
|
|
4
|
+
attrs: T;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* extract extracts front matter and body content from a LinkedMarkdown document.
|
|
8
|
+
*
|
|
9
|
+
* @param content The LinkedMarkdown document content.
|
|
10
|
+
* @returns An object containing the extracted front matter and body content.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extract<T>(content: string): Extract<T>;
|
|
13
|
+
/**
|
|
14
|
+
* LinkedMarkdownError is a custom error class for LinkedMarkdown errors.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LinkedMarkdownError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly cause?: Error;
|
|
19
|
+
constructor(code: string, message?: string, cause?: Error);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* LMD_NO_FRONTMATTER is an error code indicating that the LinkedMarkdown
|
|
23
|
+
* content does not contain frontmatter.
|
|
24
|
+
*/
|
|
25
|
+
export declare const LMD_NO_FRONTMATTER = "LMD_NO_FRONTMATTER";
|
|
26
|
+
/**
|
|
27
|
+
* LMD_INVALID_FRONTMATTER is an error code indicating that the frontmatter in
|
|
28
|
+
* the LinkedMarkdown content is invalid.
|
|
29
|
+
*/
|
|
30
|
+
export declare const LMD_INVALID_FRONTMATTER = "LMD_INVALID_FRONTMATTER";
|
|
31
|
+
export type { Extract };
|