@flint.fyi/markdown-language 0.15.0 → 0.15.2

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.
@@ -1,7 +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";
4
-
3
+ import { visit } from "unist-util-visit";
5
4
  //#region src/directives/parseDirectivesFromMarkdownFile.ts
6
5
  function parseDirectivesFromMarkdownFile(root, sourceText) {
7
6
  const collector = new DirectivesCollector(root.children.find((child) => child.position?.start.offset !== void 0)?.position?.start.offset ?? sourceText.length);
@@ -29,7 +28,7 @@ function parseDirectivesFromMarkdownFile(root, sourceText) {
29
28
  });
30
29
  return collector.collect();
31
30
  }
32
-
33
31
  //#endregion
34
32
  export { parseDirectivesFromMarkdownFile };
33
+
35
34
  //# sourceMappingURL=parseDirectivesFromMarkdownFile.js.map
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/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  import { markdownLanguage } from "./language.js";
2
-
3
- export { markdownLanguage };
2
+ export { 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, MarkdownFileServices>;
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,29 +1,41 @@
1
- import { createMarkdownFile } from "./createMarkdownFile.js";
2
- import { prepareMarkdownFile } from "./prepareMarkdownFile.js";
1
+ import { parseDirectivesFromMarkdownFile } from "./directives/parseDirectivesFromMarkdownFile.js";
3
2
  import { createLanguage } from "@flint.fyi/core";
4
- import fsSync from "node:fs";
5
-
3
+ import { fromMarkdown } from "mdast-util-from-markdown";
4
+ import { gfmFromMarkdown } from "mdast-util-gfm";
5
+ import { gfm } from "micromark-extension-gfm";
6
6
  //#region src/language.ts
7
7
  const markdownLanguage = createLanguage({
8
8
  about: { name: "Markdown" },
9
9
  createFileFactory: () => {
10
- return {
11
- prepareFromDisk: (data) => {
12
- const sourceText = fsSync.readFileSync(data.filePathAbsolute, "utf8");
13
- const { languageFile, root } = createMarkdownFile({
14
- ...data,
15
- sourceText
16
- });
17
- return prepareMarkdownFile(languageFile, root, sourceText);
18
- },
19
- prepareFromVirtual: (data) => {
20
- const { languageFile, root } = createMarkdownFile(data);
21
- return prepareMarkdownFile(languageFile, root, data.sourceText);
22
- }
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);
23
34
  };
35
+ visit(file.services.root);
24
36
  }
25
37
  });
26
-
27
38
  //#endregion
28
39
  export { markdownLanguage };
40
+
29
41
  //# sourceMappingURL=language.js.map
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.0",
3
+ "version": "0.15.2",
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,17 +23,18 @@
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.19.0",
30
- "@flint.fyi/utils": "^0.14.0"
32
+ "@flint.fyi/core": "^0.21.0",
33
+ "@flint.fyi/utils": "^0.14.1"
31
34
  },
32
35
  "devDependencies": {
33
- "@types/unist": "3.0.3",
34
- "tsdown": "0.19.0-beta.2",
35
- "vitest": "4.0.15"
36
+ "tsdown": "0.21.0",
37
+ "vitest": "4.1.0"
36
38
  },
37
39
  "engines": {
38
40
  "node": ">=24.0.0"
@@ -41,6 +43,6 @@
41
43
  "access": "public"
42
44
  },
43
45
  "scripts": {
44
- "test": "vitest --typecheck --project markdown-language"
46
+ "test": "vitest --project markdown-language"
45
47
  }
46
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