silverbullet/web/cm_plugins/lint.ts

20 lines
673 B
TypeScript
Raw Permalink Normal View History

2024-07-30 23:33:33 +08:00
import { type Diagnostic, linter } from "@codemirror/lint";
import type { Client } from "../client.ts";
import { parse } from "$common/markdown_parser/parse_tree.ts";
2024-07-30 23:33:33 +08:00
import type { LintEvent } from "../../plug-api/types.ts";
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
export function plugLinter(client: Client) {
2023-11-21 23:56:21 +08:00
return linter(async (view): Promise<Diagnostic[]> => {
const tree = parse(
2024-01-24 20:34:12 +08:00
extendedMarkdownLanguage,
2023-11-21 23:56:21 +08:00
view.state.sliceDoc(),
);
const results = (await client.dispatchAppEvent("editor:lint", {
2024-01-24 21:44:39 +08:00
name: client.currentPage,
2023-11-21 23:56:21 +08:00
tree: tree,
} as LintEvent)).flat();
return results;
});
}