@flint.fyi/markdown-language 0.15.4 → 0.16.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/{lib/language.d.ts → dist/index.d.mts} +30 -5
- package/{lib/directives/parseDirectivesFromMarkdownFile.js → dist/index.mjs} +38 -4
- package/package.json +8 -8
- package/lib/directives/parseDirectivesFromMarkdownFile.d.ts +0 -6
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -2
- package/lib/language.js +0 -41
- package/lib/nodes.d.ts +0 -32
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as _flint_fyi_core0 from "@flint.fyi/core";
|
|
1
|
+
import { WithExitKeys } from "@flint.fyi/core";
|
|
3
2
|
import * as mdast from "mdast";
|
|
3
|
+
import { Point, Position } from "unist";
|
|
4
4
|
|
|
5
|
+
//#region src/nodes.d.ts
|
|
6
|
+
interface MarkdownNodesByName extends RootContentMapWithChildren {
|
|
7
|
+
root: WithPosition<mdast.Root>;
|
|
8
|
+
}
|
|
9
|
+
type MarkdownNodeVisitors = WithExitKeys<MarkdownNodesByName>;
|
|
10
|
+
/**
|
|
11
|
+
* A version of {@link Point} where the `offset` always exists.
|
|
12
|
+
*/
|
|
13
|
+
interface PointWithOffset extends Point {
|
|
14
|
+
offset: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A version of {@link Position} where the `end` and `start` points include offsets.
|
|
18
|
+
*/
|
|
19
|
+
interface PositionWithOffsets extends Position {
|
|
20
|
+
end: PointWithOffset;
|
|
21
|
+
start: PointWithOffset;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A version of {@link mdast.RootContentMap} that includes position information for each node.
|
|
25
|
+
*/
|
|
26
|
+
type RootContentMapWithChildren = { [K in keyof mdast.RootContentMap]: WithPosition<mdast.RootContentMap[K]> };
|
|
27
|
+
type WithPosition<T> = T & {
|
|
28
|
+
position: PositionWithOffsets;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
5
31
|
//#region src/language.d.ts
|
|
6
32
|
interface MarkdownFileServices {
|
|
7
33
|
root: WithPosition<mdast.Root>;
|
|
8
34
|
}
|
|
9
|
-
declare const markdownLanguage:
|
|
35
|
+
declare const markdownLanguage: import("@flint.fyi/core").Language<{
|
|
10
36
|
root: WithPosition<mdast.Root>;
|
|
11
37
|
blockquote: WithPosition<mdast.Blockquote>;
|
|
12
38
|
break: WithPosition<mdast.Break>;
|
|
@@ -61,5 +87,4 @@ declare const markdownLanguage: _flint_fyi_core0.Language<{
|
|
|
61
87
|
"root:exit": WithPosition<mdast.Root>;
|
|
62
88
|
}, MarkdownFileServices>;
|
|
63
89
|
//#endregion
|
|
64
|
-
export { MarkdownFileServices, markdownLanguage };
|
|
65
|
-
//# sourceMappingURL=language.d.ts.map
|
|
90
|
+
export { type MarkdownFileServices, type MarkdownNodeVisitors, type MarkdownNodesByName, type PointWithOffset, type PositionWithOffsets, type RootContentMapWithChildren, type WithPosition, markdownLanguage };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
+
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
3
|
+
import { gfm } from "micromark-extension-gfm";
|
|
4
|
+
import { DirectivesCollector, createLanguage } from "@flint.fyi/core";
|
|
2
5
|
import { visit } from "unist-util-visit";
|
|
3
6
|
import { nullThrows } from "@flint.fyi/utils";
|
|
4
7
|
//#region src/directives/parseDirectivesFromMarkdownFile.ts
|
|
@@ -29,6 +32,37 @@ function parseDirectivesFromMarkdownFile(root, sourceText) {
|
|
|
29
32
|
return collector.collect();
|
|
30
33
|
}
|
|
31
34
|
//#endregion
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
//#region src/language.ts
|
|
36
|
+
const markdownLanguage = createLanguage({
|
|
37
|
+
about: { name: "Markdown" },
|
|
38
|
+
createFileFactory: () => {
|
|
39
|
+
return { createFile: (data) => {
|
|
40
|
+
const root = fromMarkdown(data.sourceText, {
|
|
41
|
+
extensions: [gfm()],
|
|
42
|
+
mdastExtensions: [gfmFromMarkdown()]
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
...parseDirectivesFromMarkdownFile(root, data.sourceText),
|
|
46
|
+
about: data,
|
|
47
|
+
services: { root }
|
|
48
|
+
};
|
|
49
|
+
} };
|
|
50
|
+
},
|
|
51
|
+
runFileVisitors: (file, options, runtime) => {
|
|
52
|
+
if (!runtime.visitors) return;
|
|
53
|
+
const { visitors } = runtime;
|
|
54
|
+
const visitorServices = {
|
|
55
|
+
options,
|
|
56
|
+
...file.services
|
|
57
|
+
};
|
|
58
|
+
const visit = (node) => {
|
|
59
|
+
const key = node.type;
|
|
60
|
+
visitors[key]?.(node, visitorServices);
|
|
61
|
+
if ("children" in node && Array.isArray(node.children)) for (const child of node.children) visit(child);
|
|
62
|
+
visitors[`${key}:exit`]?.(node, visitorServices);
|
|
63
|
+
};
|
|
64
|
+
visit(file.services.root);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
//#endregion
|
|
68
|
+
export { markdownLanguage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flint.fyi/markdown-language",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "[Experimental] Markdown language for Flint.",
|
|
5
5
|
"homepage": "https://flint.fyi",
|
|
6
6
|
"repository": {
|
|
@@ -16,11 +16,10 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"type": "module",
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./
|
|
19
|
+
".": "./dist/index.mjs"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"
|
|
23
|
-
"!lib/**/*.map"
|
|
22
|
+
"dist/"
|
|
24
23
|
],
|
|
25
24
|
"dependencies": {
|
|
26
25
|
"@types/mdast": "^4.0.4",
|
|
@@ -29,12 +28,13 @@
|
|
|
29
28
|
"mdast-util-gfm": "^3.1.0",
|
|
30
29
|
"micromark-extension-gfm": "^3.0.0",
|
|
31
30
|
"unist-util-visit": "^5.0.0",
|
|
32
|
-
"@flint.fyi/core": "^0.
|
|
33
|
-
"@flint.fyi/utils": "^0.
|
|
31
|
+
"@flint.fyi/core": "^0.24.0",
|
|
32
|
+
"@flint.fyi/utils": "^0.15.0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"tsdown": "0.
|
|
37
|
-
"vitest": "4.1.0"
|
|
35
|
+
"tsdown": "0.22.3",
|
|
36
|
+
"vitest": "4.1.0",
|
|
37
|
+
"@flint.fyi/build": "^0.1.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=24.0.0"
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Root } from "mdast";
|
|
2
|
-
export declare function parseDirectivesFromMarkdownFile(root: Root, sourceText: string): {
|
|
3
|
-
directives: import("@flint.fyi/core").CommentDirective[];
|
|
4
|
-
reports: import("@flint.fyi/core").FileReport[];
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=parseDirectivesFromMarkdownFile.d.ts.map
|
package/lib/index.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition } from "./nodes.js";
|
|
2
|
-
import { MarkdownFileServices, markdownLanguage } from "./language.js";
|
|
3
|
-
export { type MarkdownFileServices, type MarkdownNodeVisitors, type MarkdownNodesByName, type PointWithOffset, type PositionWithOffsets, type RootContentMapWithChildren, type WithPosition, markdownLanguage };
|
package/lib/index.js
DELETED
package/lib/language.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { parseDirectivesFromMarkdownFile } from "./directives/parseDirectivesFromMarkdownFile.js";
|
|
2
|
-
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
3
|
-
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
4
|
-
import { gfm } from "micromark-extension-gfm";
|
|
5
|
-
import { createLanguage } from "@flint.fyi/core";
|
|
6
|
-
//#region src/language.ts
|
|
7
|
-
const markdownLanguage = createLanguage({
|
|
8
|
-
about: { name: "Markdown" },
|
|
9
|
-
createFileFactory: () => {
|
|
10
|
-
return { createFile: (data) => {
|
|
11
|
-
const root = fromMarkdown(data.sourceText, {
|
|
12
|
-
extensions: [gfm()],
|
|
13
|
-
mdastExtensions: [gfmFromMarkdown()]
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
...parseDirectivesFromMarkdownFile(root, data.sourceText),
|
|
17
|
-
about: data,
|
|
18
|
-
services: { root }
|
|
19
|
-
};
|
|
20
|
-
} };
|
|
21
|
-
},
|
|
22
|
-
runFileVisitors: (file, options, runtime) => {
|
|
23
|
-
if (!runtime.visitors) return;
|
|
24
|
-
const { visitors } = runtime;
|
|
25
|
-
const visitorServices = {
|
|
26
|
-
options,
|
|
27
|
-
...file.services
|
|
28
|
-
};
|
|
29
|
-
const visit = (node) => {
|
|
30
|
-
const key = node.type;
|
|
31
|
-
visitors[key]?.(node, visitorServices);
|
|
32
|
-
if ("children" in node && Array.isArray(node.children)) for (const child of node.children) visit(child);
|
|
33
|
-
visitors[`${key}:exit`]?.(node, visitorServices);
|
|
34
|
-
};
|
|
35
|
-
visit(file.services.root);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
//#endregion
|
|
39
|
-
export { markdownLanguage };
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=language.js.map
|
package/lib/nodes.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { WithExitKeys } from "@flint.fyi/core";
|
|
2
|
-
import * as mdast from "mdast";
|
|
3
|
-
import { Point, Position } from "unist";
|
|
4
|
-
|
|
5
|
-
//#region src/nodes.d.ts
|
|
6
|
-
interface MarkdownNodesByName extends RootContentMapWithChildren {
|
|
7
|
-
root: WithPosition<mdast.Root>;
|
|
8
|
-
}
|
|
9
|
-
type MarkdownNodeVisitors = WithExitKeys<MarkdownNodesByName>;
|
|
10
|
-
/**
|
|
11
|
-
* A version of {@link Point} where the `offset` always exists.
|
|
12
|
-
*/
|
|
13
|
-
interface PointWithOffset extends Point {
|
|
14
|
-
offset: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A version of {@link Position} where the `end` and `start` points include offsets.
|
|
18
|
-
*/
|
|
19
|
-
interface PositionWithOffsets extends Position {
|
|
20
|
-
end: PointWithOffset;
|
|
21
|
-
start: PointWithOffset;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A version of {@link mdast.RootContentMap} that includes position information for each node.
|
|
25
|
-
*/
|
|
26
|
-
type RootContentMapWithChildren = { [K in keyof mdast.RootContentMap]: WithPosition<mdast.RootContentMap[K]> };
|
|
27
|
-
type WithPosition<T> = T & {
|
|
28
|
-
position: PositionWithOffsets;
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
export { MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition };
|
|
32
|
-
//# sourceMappingURL=nodes.d.ts.map
|