@flint.fyi/markdown-language 0.15.0 → 0.15.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/lib/directives/parseDirectivesFromMarkdownFile.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/language.d.ts +28 -1
- package/lib/language.js +29 -16
- package/lib/nodes.d.ts +3 -1
- package/package.json +6 -4
- package/lib/createMarkdownFile.d.ts +0 -8
- package/lib/createMarkdownFile.js +0 -33
- package/lib/prepareMarkdownFile.d.ts +0 -10
- package/lib/prepareMarkdownFile.js +0 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DirectivesCollector } from "@flint.fyi/core";
|
|
2
|
-
import { visit } from "unist-util-visit";
|
|
3
2
|
import { nullThrows } from "@flint.fyi/utils";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
4
|
|
|
5
5
|
//#region src/directives/parseDirectivesFromMarkdownFile.ts
|
|
6
6
|
function parseDirectivesFromMarkdownFile(root, sourceText) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition } from "./nodes.js";
|
|
1
|
+
import { MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition } from "./nodes.js";
|
|
2
2
|
import { MarkdownFileServices, markdownLanguage } from "./language.js";
|
|
3
|
-
export { MarkdownFileServices, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition, markdownLanguage };
|
|
3
|
+
export { MarkdownFileServices, MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition, markdownLanguage };
|
package/lib/language.d.ts
CHANGED
|
@@ -6,7 +6,34 @@ import * as mdast from "mdast";
|
|
|
6
6
|
interface MarkdownFileServices {
|
|
7
7
|
root: WithPosition<mdast.Root>;
|
|
8
8
|
}
|
|
9
|
-
declare const markdownLanguage: _flint_fyi_core0.Language<MarkdownNodesByName
|
|
9
|
+
declare const markdownLanguage: _flint_fyi_core0.Language<_flint_fyi_core0.Simplify<MarkdownNodesByName & {
|
|
10
|
+
"blockquote:exit"?: WithPosition<mdast.Blockquote>;
|
|
11
|
+
"break:exit"?: WithPosition<mdast.Break>;
|
|
12
|
+
"code:exit"?: WithPosition<mdast.Code>;
|
|
13
|
+
"definition:exit"?: WithPosition<mdast.Definition>;
|
|
14
|
+
"delete:exit"?: WithPosition<mdast.Delete>;
|
|
15
|
+
"emphasis:exit"?: WithPosition<mdast.Emphasis>;
|
|
16
|
+
"footnoteDefinition:exit"?: WithPosition<mdast.FootnoteDefinition>;
|
|
17
|
+
"footnoteReference:exit"?: WithPosition<mdast.FootnoteReference>;
|
|
18
|
+
"heading:exit"?: WithPosition<mdast.Heading>;
|
|
19
|
+
"html:exit"?: WithPosition<mdast.Html>;
|
|
20
|
+
"image:exit"?: WithPosition<mdast.Image>;
|
|
21
|
+
"imageReference:exit"?: WithPosition<mdast.ImageReference>;
|
|
22
|
+
"inlineCode:exit"?: WithPosition<mdast.InlineCode>;
|
|
23
|
+
"link:exit"?: WithPosition<mdast.Link>;
|
|
24
|
+
"linkReference:exit"?: WithPosition<mdast.LinkReference>;
|
|
25
|
+
"list:exit"?: WithPosition<mdast.List>;
|
|
26
|
+
"listItem:exit"?: WithPosition<mdast.ListItem>;
|
|
27
|
+
"paragraph:exit"?: WithPosition<mdast.Paragraph>;
|
|
28
|
+
"strong:exit"?: WithPosition<mdast.Strong>;
|
|
29
|
+
"table:exit"?: WithPosition<mdast.Table>;
|
|
30
|
+
"tableCell:exit"?: WithPosition<mdast.TableCell>;
|
|
31
|
+
"tableRow:exit"?: WithPosition<mdast.TableRow>;
|
|
32
|
+
"text:exit"?: WithPosition<mdast.Text>;
|
|
33
|
+
"thematicBreak:exit"?: WithPosition<mdast.ThematicBreak>;
|
|
34
|
+
"yaml:exit"?: WithPosition<mdast.Yaml>;
|
|
35
|
+
"root:exit"?: WithPosition<mdast.Root>;
|
|
36
|
+
}>, MarkdownFileServices>;
|
|
10
37
|
//#endregion
|
|
11
38
|
export { MarkdownFileServices, markdownLanguage };
|
|
12
39
|
//# sourceMappingURL=language.d.ts.map
|
package/lib/language.js
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { prepareMarkdownFile } from "./prepareMarkdownFile.js";
|
|
1
|
+
import { parseDirectivesFromMarkdownFile } from "./directives/parseDirectivesFromMarkdownFile.js";
|
|
3
2
|
import { createLanguage } from "@flint.fyi/core";
|
|
4
|
-
import
|
|
3
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
4
|
+
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
5
|
+
import { gfm } from "micromark-extension-gfm";
|
|
5
6
|
|
|
6
7
|
//#region src/language.ts
|
|
7
8
|
const markdownLanguage = createLanguage({
|
|
8
9
|
about: { name: "Markdown" },
|
|
9
10
|
createFileFactory: () => {
|
|
10
|
-
return {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
return { createFile: (data) => {
|
|
12
|
+
const root = fromMarkdown(data.sourceText, {
|
|
13
|
+
extensions: [gfm()],
|
|
14
|
+
mdastExtensions: [gfmFromMarkdown()]
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
...parseDirectivesFromMarkdownFile(root, data.sourceText),
|
|
18
|
+
about: data,
|
|
19
|
+
services: { root }
|
|
20
|
+
};
|
|
21
|
+
} };
|
|
22
|
+
},
|
|
23
|
+
runFileVisitors: (file, options, runtime) => {
|
|
24
|
+
if (!runtime.visitors) return;
|
|
25
|
+
const { visitors } = runtime;
|
|
26
|
+
const visitorServices = {
|
|
27
|
+
options,
|
|
28
|
+
...file.services
|
|
23
29
|
};
|
|
30
|
+
const visit = (node) => {
|
|
31
|
+
const key = node.type;
|
|
32
|
+
visitors[key]?.(node, visitorServices);
|
|
33
|
+
if ("children" in node && Array.isArray(node.children)) for (const child of node.children) visit(child);
|
|
34
|
+
visitors[`${key}:exit`]?.(node, visitorServices);
|
|
35
|
+
};
|
|
36
|
+
visit(file.services.root);
|
|
24
37
|
}
|
|
25
38
|
});
|
|
26
39
|
|
package/lib/nodes.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WithExitKeys } from "@flint.fyi/core";
|
|
1
2
|
import * as mdast from "mdast";
|
|
2
3
|
import { Point, Position } from "unist";
|
|
3
4
|
|
|
@@ -5,6 +6,7 @@ import { Point, Position } from "unist";
|
|
|
5
6
|
interface MarkdownNodesByName extends RootContentMapWithChildren {
|
|
6
7
|
root: WithPosition<mdast.Root>;
|
|
7
8
|
}
|
|
9
|
+
type MarkdownNodeVisitors = WithExitKeys<MarkdownNodesByName>;
|
|
8
10
|
/**
|
|
9
11
|
* A version of {@link Point} where the `offset` always exists.
|
|
10
12
|
*/
|
|
@@ -26,5 +28,5 @@ type WithPosition<T> = T & {
|
|
|
26
28
|
position: PositionWithOffsets;
|
|
27
29
|
};
|
|
28
30
|
//#endregion
|
|
29
|
-
export { MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition };
|
|
31
|
+
export { MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition };
|
|
30
32
|
//# sourceMappingURL=nodes.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flint.fyi/markdown-language",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "[Experimental] Markdown language for Flint.",
|
|
5
|
+
"homepage": "https://flint.fyi",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "git+https://github.com/flint-fyi/flint.git",
|
|
@@ -22,16 +23,17 @@
|
|
|
22
23
|
"!lib/**/*.map"
|
|
23
24
|
],
|
|
24
25
|
"dependencies": {
|
|
26
|
+
"@types/mdast": "^4.0.4",
|
|
27
|
+
"@types/unist": "^3.0.3",
|
|
25
28
|
"mdast-util-from-markdown": "^2.0.2",
|
|
26
29
|
"mdast-util-gfm": "^3.1.0",
|
|
27
30
|
"micromark-extension-gfm": "^3.0.0",
|
|
28
31
|
"unist-util-visit": "^5.0.0",
|
|
29
|
-
"@flint.fyi/core": "^0.
|
|
32
|
+
"@flint.fyi/core": "^0.20.0",
|
|
30
33
|
"@flint.fyi/utils": "^0.14.0"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"
|
|
34
|
-
"tsdown": "0.19.0-beta.2",
|
|
36
|
+
"tsdown": "0.20.1",
|
|
35
37
|
"vitest": "4.0.15"
|
|
36
38
|
},
|
|
37
39
|
"engines": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { FileDiskData, LanguageFileDefinition } from "@flint.fyi/core";
|
|
2
|
-
import type { MarkdownFileServices } from "./language.ts";
|
|
3
|
-
import type { MarkdownNodesByName } from "./nodes.ts";
|
|
4
|
-
export declare function createMarkdownFile(data: FileDiskData): {
|
|
5
|
-
languageFile: LanguageFileDefinition<MarkdownNodesByName, MarkdownFileServices>;
|
|
6
|
-
root: import("mdast").Root;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=createMarkdownFile.d.ts.map
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
-
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
3
|
-
import { gfm } from "micromark-extension-gfm";
|
|
4
|
-
import { visit } from "unist-util-visit";
|
|
5
|
-
|
|
6
|
-
//#region src/createMarkdownFile.ts
|
|
7
|
-
function createMarkdownFile(data) {
|
|
8
|
-
const root = fromMarkdown(data.sourceText, {
|
|
9
|
-
extensions: [gfm()],
|
|
10
|
-
mdastExtensions: [gfmFromMarkdown()]
|
|
11
|
-
});
|
|
12
|
-
return {
|
|
13
|
-
languageFile: {
|
|
14
|
-
about: data,
|
|
15
|
-
runVisitors(options, runtime) {
|
|
16
|
-
if (!runtime.visitors) return;
|
|
17
|
-
const { visitors } = runtime;
|
|
18
|
-
const fileServices = {
|
|
19
|
-
options,
|
|
20
|
-
root
|
|
21
|
-
};
|
|
22
|
-
visit(root, (node) => {
|
|
23
|
-
visitors[node.type]?.(node, fileServices);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
root
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
export { createMarkdownFile };
|
|
33
|
-
//# sourceMappingURL=createMarkdownFile.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LanguageFileDefinition } from "@flint.fyi/core";
|
|
2
|
-
import type { Root } from "mdast";
|
|
3
|
-
import type { MarkdownFileServices } from "./language.ts";
|
|
4
|
-
import type { MarkdownNodesByName } from "./nodes.ts";
|
|
5
|
-
export declare function prepareMarkdownFile(languageFile: LanguageFileDefinition<MarkdownNodesByName, MarkdownFileServices>, root: Root, sourceText: string): {
|
|
6
|
-
file: LanguageFileDefinition<MarkdownNodesByName, MarkdownFileServices>;
|
|
7
|
-
directives: import("@flint.fyi/core").CommentDirective[];
|
|
8
|
-
reports: import("@flint.fyi/core").FileReport[];
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=prepareMarkdownFile.d.ts.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { parseDirectivesFromMarkdownFile } from "./directives/parseDirectivesFromMarkdownFile.js";
|
|
2
|
-
|
|
3
|
-
//#region src/prepareMarkdownFile.ts
|
|
4
|
-
function prepareMarkdownFile(languageFile, root, sourceText) {
|
|
5
|
-
return {
|
|
6
|
-
...parseDirectivesFromMarkdownFile(root, sourceText),
|
|
7
|
-
file: languageFile
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { prepareMarkdownFile };
|
|
13
|
-
//# sourceMappingURL=prepareMarkdownFile.js.map
|