-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0
import type {
CompileContext,
Extension,
HtmlExtension,
State,
Token,
} from "../../deps/esm.sh/micromark-util-types/types.ts";
import { codes } from "../../deps/esm.sh/micromark-util-symbol/mod.ts";
import {
asciiAlphanumeric,
markdownSpace,
} from "../../deps/esm.sh/micromark-util-character/mod.ts";
const enum TokenTypeMap {
block = "ofmBlockIdentifier",
caret = "ofmBlockIdentifierCaret",
ident = "ofmBlockIdentifierIdentifier",
}
export function ofmBlockIdentifierHtml(): HtmlExtension {
return {
enter: {
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
[TokenTypeMap.ident](this: CompileContext, token: Token) {
this.tag(`<span id="${this.sliceSerialize(token)}"></span>`);
},
},
};
}
export function ofmBlockIdentifier(): Extension {
return {
text: {
[codes.caret]: {
tokenize(effects, ok, nok) {
const { previous } = this;
const start: State = (code) => {
if (!markdownSpace(previous) || code !== codes.caret) {
return nok(code);
}
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
effects.enter(TokenTypeMap.block);
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
effects.enter(TokenTypeMap.caret);
effects.consume(code);
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
effects.exit(TokenTypeMap.caret);
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
effects.enter(TokenTypeMap.ident);
return ident;
};
const ident: State = (code) => {
if (asciiAlphanumeric(code) || code === codes.dash) {
effects.consume(code);
return ident;
}
if (code === codes.eof) {
// @ts-expect-error: micromark heavily relies on ambient module declarations,
// which Deno does not support. APIs also don't accept type parameters.
effects.exit(TokenTypeMap.ident);
return ok(code);
}
return nok(code);
};
return start;
},
},
},
};
}