Skip to content

Commit

Permalink
fix: use old version of mdast libraries that can be used with require
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Aug 31, 2023
1 parent 09485ef commit b5446a8
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 464 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"js-yaml": "^4.1.0",
"libsodium-wrappers": "^0.7.11",
"lint-staged": "^13.1.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-gfm": "^3.0.0",
"micromark-extension-gfm": "^3.0.0",
"mdast-util-from-markdown": "^0.8.5",
"mdast-util-gfm": "^0.1.2",
"micromark-extension-gfm": "^0.3.3",
"ms": "^2.1.3",
"node-html-parser": "^6.1.5",
"node-html-to-image": "^3.3.0",
Expand Down
1 change: 1 addition & 0 deletions src/decs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "mdast-util-gfm";
10 changes: 4 additions & 6 deletions src/helpers/comment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { MarkdownItem } from "../types";
import fromMarkdown from "mdast-util-from-markdown";
import gfmFromMarkdown from "mdast-util-gfm";
import gfm from "micromark-extension-gfm";

type Node = {
type: MarkdownItem;
Expand Down Expand Up @@ -30,11 +33,6 @@ const traverse = (result: Record<MarkdownItem, string[]>, node: Node, itemsToExc
};

export const parseComments = async (comments: string[], itemsToExclude: string[]): Promise<Record<MarkdownItem, string[]>> => {
// dynamic import of mdast
const { fromMarkdown } = await import("mdast-util-from-markdown");
const { gfmFromMarkdown } = await import("mdast-util-gfm");
const { gfm } = await import("micromark-extension-gfm");

const result: Record<MarkdownItem, string[]> = {
[MarkdownItem.Text]: [],
[MarkdownItem.Paragraph]: [],
Expand Down Expand Up @@ -72,7 +70,7 @@ export const parseComments = async (comments: string[], itemsToExclude: string[]
for (const comment of comments) {
const tree = fromMarkdown(comment, {
extensions: [gfm()],
mdastExtensions: [gfmFromMarkdown()],
mdastExtensions: [gfmFromMarkdown.fromMarkdown],
});
console.log(`Comment Mdast Tree: ${JSON.stringify(tree, null, 2)}`);
traverse(result, tree as Node, itemsToExclude);
Expand Down
Loading

0 comments on commit b5446a8

Please sign in to comment.