1
0
silverbullet/web/cm_plugins/lint.ts

20 lines
669 B
TypeScript
Raw Normal View History

import { Diagnostic, linter } from "@codemirror/lint";
import type { Client } from "../client.ts";
2023-11-21 15:56:21 +00:00
import { parse } from "../../common/markdown_parser/parse_tree.ts";
import buildMarkdown from "../../common/markdown_parser/parser.ts";
import { LintEvent } from "$sb/app_event.ts";
export function plugLinter(client: Client) {
2023-11-21 15:56:21 +00:00
return linter(async (view): Promise<Diagnostic[]> => {
const tree = parse(
buildMarkdown(client.system.mdExtensions),
view.state.sliceDoc(),
);
const results = (await client.dispatchAppEvent("editor:lint", {
name: client.currentPage!,
2023-11-21 15:56:21 +00:00
tree: tree,
} as LintEvent)).flat();
return results;
});
}