mdast-util-block-id 1.0.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 +61 -0
- package/index.d.ts +12 -0
- package/index.js +1 -0
- package/lib/index.js +58 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# mdast-util-block-id
|
|
2
|
+
|
|
3
|
+
[mdast][] extensions to parse [Obsidian]-style inline footnotes
|
|
4
|
+
and convert them to [GFM footnotes][gfm-footnote].
|
|
5
|
+
Intended to be used with [micromark-extension-block-id][].
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
This package is [ESM only][esm].
|
|
10
|
+
In Node.js (version 16+), install with [npm][]:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install micromark-extension-block-id mdast-util-block-id
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
In Deno with [`esm.sh`][esmsh]:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { blockIdFromMarkdown } from "https://esm.sh/mdast-util-block-id@1";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
In browsers with [`esm.sh`][esmsh]:
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script type="module">
|
|
26
|
+
import { blockIdFromMarkdown } from "https://esm.sh/mdast-util-block-id12?bundle";
|
|
27
|
+
</script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
This package exports the identifiers
|
|
33
|
+
[`blockIdFromMarkdown`][api-frommarkdown].
|
|
34
|
+
There is no default export.
|
|
35
|
+
|
|
36
|
+
### `blockIdFromMarkdown()`
|
|
37
|
+
|
|
38
|
+
Create an extension for
|
|
39
|
+
[`mdast-util-from-markdown`][mdast-util-from-markdown]
|
|
40
|
+
to enable block ids in markdown.
|
|
41
|
+
|
|
42
|
+
###### Returns
|
|
43
|
+
|
|
44
|
+
Extension for `mdast-util-from-markdown`
|
|
45
|
+
([`FromMarkdownExtension`][frommarkdownextension]).
|
|
46
|
+
|
|
47
|
+
[Obsidian]: https://obsidian.md
|
|
48
|
+
[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
|
|
49
|
+
[micromark]: https://github.com/micromark/micromark
|
|
50
|
+
[mdast-util-block-id]: https://github.com/jajaperson/unified-block-id/tree/main/packages/mdast-util-block-id
|
|
51
|
+
[esmsh]: https://esm.sh
|
|
52
|
+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
53
|
+
[micromark-extension]: https://github.com/micromark/micromark#syntaxextension
|
|
54
|
+
[mdast]: https://github.com/syntax-tree/mdast
|
|
55
|
+
[gfm-footnote]: https://github.com/syntax-tree/mdast-util-gfm-footnote
|
|
56
|
+
[npm]: https://docs.npmjs.com/cli/install
|
|
57
|
+
[api-frommarkdown]: #blockidfrommarkdown
|
|
58
|
+
[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
|
|
59
|
+
[api-togfm]: #inlinefootnotetogfm
|
|
60
|
+
[micromark-extension-block-id]: https://github.com/jajaperson/unified-block-id/tree/main/packages/micromark-extension-block-id
|
|
61
|
+
[micromark-extension-block-id]: https://github.com/jajaperson/unified-block-id/tree/main/packages/micromark-extension-block-id
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/index.js";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** @import {Extension as FromMarkdownExtension, CompileContext, Handle as FromMarkdownHandle} from "mdast-util-from-markdown" */
|
|
2
|
+
/** @import {Root, FootnoteDefinition, FootnoteReference} from "mdast" */
|
|
3
|
+
import { ok as assert } from "devlop";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create an extension for `mdast-util-from-markdown` to enable GFM footnotes
|
|
7
|
+
* in markdown.
|
|
8
|
+
*
|
|
9
|
+
* @returns {FromMarkdownExtension}
|
|
10
|
+
* Extension for `mdast-util-from-markdown`.
|
|
11
|
+
*/
|
|
12
|
+
export function blockIdFromMarkdown() {
|
|
13
|
+
return {
|
|
14
|
+
enter: {
|
|
15
|
+
blockId: enterBlockId,
|
|
16
|
+
blockIdString: enterBlockIdString,
|
|
17
|
+
},
|
|
18
|
+
exit: {
|
|
19
|
+
blockIdString: exitBlockIdString,
|
|
20
|
+
blockId: exitBlockId,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @this {CompileContext}
|
|
27
|
+
* @type {FromMarkdownHandle}
|
|
28
|
+
*/
|
|
29
|
+
function enterBlockId(token) {
|
|
30
|
+
this.enter({ type: "blockId", value: "" }, token);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @this {CompileContext}
|
|
35
|
+
* @type {FromMarkdownHandle}
|
|
36
|
+
*/
|
|
37
|
+
function enterBlockIdString(token) {
|
|
38
|
+
this.buffer();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @this {CompileContext}
|
|
43
|
+
* @type {FromMarkdownHandle}
|
|
44
|
+
*/
|
|
45
|
+
function exitBlockIdString(token) {
|
|
46
|
+
const id = this.resume();
|
|
47
|
+
const node = this.stack[this.stack.length - 1];
|
|
48
|
+
assert(node.type === "blockId", "expected blockId on top of stack");
|
|
49
|
+
node.value = id;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @this {CompileContext}
|
|
54
|
+
* @type {FromMarkdownHandle}
|
|
55
|
+
*/
|
|
56
|
+
function exitBlockId(token) {
|
|
57
|
+
this.exit(token);
|
|
58
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "James Jensen <jamesarthurjensen@gmail.com> (https://jajaperson.me)",
|
|
3
|
+
"name": "mdast-util-block-id",
|
|
4
|
+
"repository": "https://github.com/jajaperson/unified-block-id/tree/main/packages/mdast-util-block-id",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"remark",
|
|
10
|
+
"markdown",
|
|
11
|
+
"obsidian",
|
|
12
|
+
"ast",
|
|
13
|
+
"mdast"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bugs": "https://github.com/jajaperson/unified-block-id/issues",
|
|
17
|
+
"contributors": [
|
|
18
|
+
"James Jensen <jamesarthurjensen@gmail.com> (https://jajaperson.me)"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"lib"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@types/mdast": "^4.0.4",
|
|
27
|
+
"devlop": "^1.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"mdast-util-from-markdown": "^2.0.3",
|
|
31
|
+
"micromark-extension-block-id": "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node --conditions development test/index.js",
|
|
35
|
+
"write-fixtures": "node --conditions development test/write-fixtures.js"
|
|
36
|
+
}
|
|
37
|
+
}
|