@flint.fyi/markdown-language 0.0.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/LICENSE.md +20 -0
- 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 +47 -51
- 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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -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,52 +1,48 @@
|
|
|
1
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
|
-
".": "./lib/index.js"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
2
|
+
"name": "@flint.fyi/markdown-language",
|
|
3
|
+
"version": "0.15.1",
|
|
4
|
+
"description": "[Experimental] Markdown language for Flint.",
|
|
5
|
+
"homepage": "https://flint.fyi",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/flint-fyi/flint.git",
|
|
9
|
+
"directory": "packages/markdown-language"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "JoshuaKGoldberg",
|
|
14
|
+
"email": "npm@joshuakgoldberg.com"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"lib/",
|
|
23
|
+
"!lib/**/*.map"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@types/mdast": "^4.0.4",
|
|
27
|
+
"@types/unist": "^3.0.3",
|
|
28
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
29
|
+
"mdast-util-gfm": "^3.1.0",
|
|
30
|
+
"micromark-extension-gfm": "^3.0.0",
|
|
31
|
+
"unist-util-visit": "^5.0.0",
|
|
32
|
+
"@flint.fyi/core": "^0.20.0",
|
|
33
|
+
"@flint.fyi/utils": "^0.14.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsdown": "0.20.1",
|
|
37
|
+
"vitest": "4.0.15"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=24.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"test": "vitest --typecheck --project markdown-language"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -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
|