micromark-extension-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 +67 -0
- package/index.d.ts +15 -0
- package/index.js +1 -0
- package/lib/index.js +91 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# micromark-extension-gfm-strikethrough
|
|
2
|
+
|
|
3
|
+
Syntax-only [micromark][] extension
|
|
4
|
+
for parsing [Obsidian][]-style inline footnotes.
|
|
5
|
+
|
|
6
|
+
```md
|
|
7
|
+
Sentence.^[Footnote]
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Note this extension does not extend the html compiler.
|
|
11
|
+
Instead, this is intended to be used together with [mdast-util-block-id][]
|
|
12
|
+
which includes a utility for converting inline footnotes to GFM footnote reference/definition pairs.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
This package is [ESM only][esm].
|
|
17
|
+
In Node.js (version 16+), install with [npm][]:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install micromark-extension-block-id
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
In Deno with [`esm.sh`][esmsh]:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { blockId } from "https://esm.sh/micromark-extension-block-id@1";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
In browsers with [`esm.sh`][esmsh]:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script type="module">
|
|
33
|
+
import { blockId } from "https://esm.sh/micromark-extension-block-id@1?bundle";
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
This package exports the identifier [`blockId`][api-block-id].
|
|
40
|
+
There is no default export.
|
|
41
|
+
|
|
42
|
+
The export map supports the [`development` condition][development].
|
|
43
|
+
Run `node --conditions development module.js` to get instrumented dev code.
|
|
44
|
+
Without this condition, production code is loaded.
|
|
45
|
+
|
|
46
|
+
### `blockId()`
|
|
47
|
+
|
|
48
|
+
Create an extension for `micromark` to enable block id syntax.
|
|
49
|
+
|
|
50
|
+
###### Returns
|
|
51
|
+
|
|
52
|
+
Extension for `micromark` that can be passed in `extensions`,
|
|
53
|
+
to enable block ids ([`Extension`][micromark-extension]).
|
|
54
|
+
|
|
55
|
+
## Security
|
|
56
|
+
|
|
57
|
+
This package is safe.
|
|
58
|
+
|
|
59
|
+
[micromark]: https://github.com/micromark/micromark
|
|
60
|
+
[mdast-util-block-id]: https://github.com/jajaperson/unified-block-id/tree/main/packages/mdast-util-block-id
|
|
61
|
+
[esmsh]: https://esm.sh
|
|
62
|
+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
63
|
+
[micromark-extension]: https://github.com/micromark/micromark#syntaxextension
|
|
64
|
+
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
|
|
65
|
+
[api-block-id]: #blockid
|
|
66
|
+
[npm]: https://docs.npmjs.com/cli/install
|
|
67
|
+
[Obsidian]: https://obsidian.md
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { blockId } from "./lib/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Augment.
|
|
5
|
+
*/
|
|
6
|
+
declare module "micromark-util-types" {
|
|
7
|
+
/**
|
|
8
|
+
* Token types.
|
|
9
|
+
*/
|
|
10
|
+
interface TokenTypeMap {
|
|
11
|
+
blockId: "blockId";
|
|
12
|
+
blockIdMarker: "blockIdMarker";
|
|
13
|
+
blockIdString: "blockIdString";
|
|
14
|
+
}
|
|
15
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/index.js";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Extension, TokenizeContext, Tokenizer, State, Construct} from "micromark-util-types"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ok as assert } from "devlop";
|
|
6
|
+
import { codes } from "micromark-util-symbol";
|
|
7
|
+
import {
|
|
8
|
+
asciiAlphanumeric,
|
|
9
|
+
markdownLineEnding,
|
|
10
|
+
markdownLineEndingOrSpace,
|
|
11
|
+
} from "micromark-util-character";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates an extension for `micromark` to enable Obsidian-style block id syntax
|
|
15
|
+
*
|
|
16
|
+
* @returns {Extension}
|
|
17
|
+
* Extension for the `micromark` package that can be passed in `extensions` to enable
|
|
18
|
+
* Obsidian-style block id syntax.
|
|
19
|
+
*/
|
|
20
|
+
export function blockId() {
|
|
21
|
+
/** @type {Construct} */
|
|
22
|
+
const construct = {
|
|
23
|
+
name: "blockId",
|
|
24
|
+
tokenize: blockIdTokenize,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
text: {
|
|
29
|
+
[codes.caret]: construct,
|
|
30
|
+
},
|
|
31
|
+
flow: {
|
|
32
|
+
[codes.caret]: construct,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @this {TokenizeContext}
|
|
39
|
+
* @type {Tokenizer}
|
|
40
|
+
*/
|
|
41
|
+
function blockIdTokenize(effects, ok, nok) {
|
|
42
|
+
let empty = true;
|
|
43
|
+
return start;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Start of block id
|
|
47
|
+
*
|
|
48
|
+
* ```markdown
|
|
49
|
+
* > | a ^b
|
|
50
|
+
* ^
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @type {State}
|
|
54
|
+
*/
|
|
55
|
+
function start(code) {
|
|
56
|
+
assert(code === codes.caret, "expected `^`");
|
|
57
|
+
effects.enter("blockId");
|
|
58
|
+
effects.enter("blockIdMarker");
|
|
59
|
+
effects.consume(code);
|
|
60
|
+
effects.exit("blockIdMarker");
|
|
61
|
+
effects.enter("blockIdString");
|
|
62
|
+
effects.enter("chunkString", { contentType: "string" });
|
|
63
|
+
|
|
64
|
+
return id;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* After `^` at word character
|
|
69
|
+
*
|
|
70
|
+
* ```markdown
|
|
71
|
+
* > | a ^b
|
|
72
|
+
* ^
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @type {State}
|
|
76
|
+
*/
|
|
77
|
+
function id(code) {
|
|
78
|
+
if (asciiAlphanumeric(code) || code === codes.dash) {
|
|
79
|
+
effects.consume(code);
|
|
80
|
+
empty = false;
|
|
81
|
+
return id;
|
|
82
|
+
} else if (!empty && (markdownLineEnding(code) || code === null)) {
|
|
83
|
+
effects.exit("chunkString");
|
|
84
|
+
effects.exit("blockIdString");
|
|
85
|
+
effects.exit("blockId");
|
|
86
|
+
return ok(code);
|
|
87
|
+
} else {
|
|
88
|
+
return nok(code);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "James Jensen <jamesarthurjensen@gmail.com> (https://jajaperson.me)",
|
|
3
|
+
"name": "micromark-extension-block-id",
|
|
4
|
+
"repository": "https://github.com/jajaperson/unified-block-id/tree/main/packages/micromark-extension-block-id",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"remark",
|
|
10
|
+
"markdown",
|
|
11
|
+
"obsidian",
|
|
12
|
+
"micromark"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"bugs": "https://github.com/jajaperson/unified-block-id/issues",
|
|
16
|
+
"contributors": [
|
|
17
|
+
"James Jensen <jamesarthurjensen@gmail.com> (https://jajaperson.me)"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"index.d.ts",
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"devlop": "^1.1.0",
|
|
26
|
+
"micromark-util-symbol": "^2.0.1",
|
|
27
|
+
"micromark-util-types": "^2.0.2",
|
|
28
|
+
"micromark-util-character": "^2.1.1"
|
|
29
|
+
}
|
|
30
|
+
}
|