@flint.fyi/markdown-language 0.17.0 → 0.17.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.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- import { WithExitKeys } from "@flint.fyi/core";
1
+ import { Language, WithExitKeys } from "@flint.fyi/core";
2
2
  import * as mdast from "mdast";
3
3
  import { Point, Position } from "unist";
4
-
5
4
  //#region src/nodes.d.ts
6
5
  interface MarkdownNodesByName extends RootContentMapWithChildren {
7
6
  root: WithPosition<mdast.Root>;
@@ -23,7 +22,7 @@ interface PositionWithOffsets extends Position {
23
22
  /**
24
23
  * A version of {@link mdast.RootContentMap} that includes position information for each node.
25
24
  */
26
- type RootContentMapWithChildren = { [K in keyof mdast.RootContentMap]: WithPosition<mdast.RootContentMap[K]> };
25
+ type RootContentMapWithChildren = { [K in keyof mdast.RootContentMap]: WithPosition<mdast.RootContentMap[K]>; };
27
26
  type WithPosition<T> = T & {
28
27
  position: PositionWithOffsets;
29
28
  };
@@ -32,59 +31,6 @@ type WithPosition<T> = T & {
32
31
  interface MarkdownFileServices {
33
32
  root: WithPosition<mdast.Root>;
34
33
  }
35
- declare const markdownLanguage: import("@flint.fyi/core").Language<{
36
- root: WithPosition<mdast.Root>;
37
- blockquote: WithPosition<mdast.Blockquote>;
38
- break: WithPosition<mdast.Break>;
39
- code: WithPosition<mdast.Code>;
40
- definition: WithPosition<mdast.Definition>;
41
- delete: WithPosition<mdast.Delete>;
42
- emphasis: WithPosition<mdast.Emphasis>;
43
- footnoteDefinition: WithPosition<mdast.FootnoteDefinition>;
44
- footnoteReference: WithPosition<mdast.FootnoteReference>;
45
- heading: WithPosition<mdast.Heading>;
46
- html: WithPosition<mdast.Html>;
47
- image: WithPosition<mdast.Image>;
48
- imageReference: WithPosition<mdast.ImageReference>;
49
- inlineCode: WithPosition<mdast.InlineCode>;
50
- link: WithPosition<mdast.Link>;
51
- linkReference: WithPosition<mdast.LinkReference>;
52
- list: WithPosition<mdast.List>;
53
- listItem: WithPosition<mdast.ListItem>;
54
- paragraph: WithPosition<mdast.Paragraph>;
55
- strong: WithPosition<mdast.Strong>;
56
- table: WithPosition<mdast.Table>;
57
- tableCell: WithPosition<mdast.TableCell>;
58
- tableRow: WithPosition<mdast.TableRow>;
59
- text: WithPosition<mdast.Text>;
60
- thematicBreak: WithPosition<mdast.ThematicBreak>;
61
- yaml: WithPosition<mdast.Yaml>;
62
- "blockquote:exit": WithPosition<mdast.Blockquote>;
63
- "break:exit": WithPosition<mdast.Break>;
64
- "code:exit": WithPosition<mdast.Code>;
65
- "definition:exit": WithPosition<mdast.Definition>;
66
- "delete:exit": WithPosition<mdast.Delete>;
67
- "emphasis:exit": WithPosition<mdast.Emphasis>;
68
- "footnoteDefinition:exit": WithPosition<mdast.FootnoteDefinition>;
69
- "footnoteReference:exit": WithPosition<mdast.FootnoteReference>;
70
- "heading:exit": WithPosition<mdast.Heading>;
71
- "html:exit": WithPosition<mdast.Html>;
72
- "image:exit": WithPosition<mdast.Image>;
73
- "imageReference:exit": WithPosition<mdast.ImageReference>;
74
- "inlineCode:exit": WithPosition<mdast.InlineCode>;
75
- "link:exit": WithPosition<mdast.Link>;
76
- "linkReference:exit": WithPosition<mdast.LinkReference>;
77
- "list:exit": WithPosition<mdast.List>;
78
- "listItem:exit": WithPosition<mdast.ListItem>;
79
- "paragraph:exit": WithPosition<mdast.Paragraph>;
80
- "strong:exit": WithPosition<mdast.Strong>;
81
- "table:exit": WithPosition<mdast.Table>;
82
- "tableCell:exit": WithPosition<mdast.TableCell>;
83
- "tableRow:exit": WithPosition<mdast.TableRow>;
84
- "text:exit": WithPosition<mdast.Text>;
85
- "thematicBreak:exit": WithPosition<mdast.ThematicBreak>;
86
- "yaml:exit": WithPosition<mdast.Yaml>;
87
- "root:exit": WithPosition<mdast.Root>;
88
- }, MarkdownFileServices>;
34
+ export declare const markdownLanguage: Language<MarkdownNodeVisitors, MarkdownFileServices>;
89
35
  //#endregion
90
- export { type MarkdownFileServices, type MarkdownNodeVisitors, type MarkdownNodesByName, type PointWithOffset, type PositionWithOffsets, type RootContentMapWithChildren, type WithPosition, markdownLanguage };
36
+ export type { MarkdownFileServices, MarkdownNodeVisitors, MarkdownNodesByName, PointWithOffset, PositionWithOffsets, RootContentMapWithChildren, WithPosition };
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  import { fromMarkdown } from "mdast-util-from-markdown";
2
2
  import { gfmFromMarkdown } from "mdast-util-gfm";
3
3
  import { gfm } from "micromark-extension-gfm";
4
- import { DirectivesCollector, createLanguage } from "@flint.fyi/core";
4
+ import { DirectivesCollector, createLanguage, groupFileVisitors, runFileVisitorSubscriptions } from "@flint.fyi/core";
5
5
  import { visit } from "unist-util-visit";
6
6
  import { nullThrows } from "@flint.fyi/utils";
7
7
  //#region src/directives/parseDirectivesFromMarkdownFile.ts
8
8
  function parseDirectivesFromMarkdownFile(root, sourceText) {
9
- const collector = new DirectivesCollector(root.children.find((child) => child.position?.start.offset !== void 0)?.position?.start.offset ?? sourceText.length);
9
+ const index = root.children.find((child) => child.position?.start.offset !== void 0)?.position?.start.offset ?? sourceText.length;
10
+ const collector = new DirectivesCollector(index);
10
11
  visit(root, "html", (node) => {
11
12
  const regex = /<!--([\s\S]*?)-->/g;
12
13
  let commentMatch;
@@ -48,18 +49,14 @@ const markdownLanguage = createLanguage({
48
49
  };
49
50
  } };
50
51
  },
51
- runFileVisitors: (file, options, runtime) => {
52
- if (!runtime.visitors) return;
53
- const { visitors } = runtime;
54
- const visitorServices = {
55
- options,
56
- ...file.services
57
- };
52
+ runFileVisitors: (file, fileVisitors) => {
53
+ const { enter, exit } = groupFileVisitors(fileVisitors);
58
54
  const visit = (node) => {
59
- const key = node.type;
60
- visitors[key]?.(node, visitorServices);
55
+ const entering = enter?.get(node.type);
56
+ if (entering !== void 0) runFileVisitorSubscriptions(entering, node);
61
57
  if ("children" in node && Array.isArray(node.children)) for (const child of node.children) visit(child);
62
- visitors[`${key}:exit`]?.(node, visitorServices);
58
+ const exiting = exit?.get(node.type);
59
+ if (exiting !== void 0) runFileVisitorSubscriptions(exiting, node);
63
60
  };
64
61
  visit(file.services.root);
65
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/markdown-language",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "[Experimental] Markdown language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -22,19 +22,19 @@
22
22
  "dist/"
23
23
  ],
24
24
  "dependencies": {
25
+ "@flint.fyi/core": "^0.27.0",
26
+ "@flint.fyi/utils": "^0.16.0",
25
27
  "@types/mdast": "^4.0.4",
26
28
  "@types/unist": "^3.0.3",
27
29
  "mdast-util-from-markdown": "^2.0.2",
28
30
  "mdast-util-gfm": "^3.1.0",
29
31
  "micromark-extension-gfm": "^3.0.0",
30
- "unist-util-visit": "^5.0.0",
31
- "@flint.fyi/utils": "^0.16.0",
32
- "@flint.fyi/core": "^0.25.0"
32
+ "unist-util-visit": "^5.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "tsdown": "0.22.3",
36
- "vitest": "4.1.0",
37
- "@flint.fyi/build": "^0.1.0"
35
+ "@flint.fyi/build": "^0.1.0",
36
+ "tsdown": "0.23.0",
37
+ "vitest": "5.0.1"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=26.1.0"