Files
plainleaf/web/cm_plugins/clean.ts
T
aphymiandGitHub 309e1f8d85 Fix minor bugs in MD syntax rendering mode (#1537)
* fix: restore tag styles when syntax rendering on

`hashtagPlugin` was missed in previous commits. It's now included
whether markdown syntax rendering is on or off.

* fix: remove stray margins from md syntax rendering

Some elements were accidentally given margins while MD syntax rendering
is on, so this commit excludes them from that style rule.
2025-09-12 14:30:39 +02:00

59 lines
1.9 KiB
TypeScript

import type { Extension } from "@codemirror/state";
import type { Client } from "../client.ts";
import { blockquotePlugin } from "./block_quote.ts";
import { admonitionPlugin } from "./admonition.ts";
import { hideHeaderMarkPlugin, hideMarksPlugin } from "./hide_mark.ts";
import { cleanBlockPlugin } from "./block.ts";
import { linkPlugin } from "./link.ts";
import { listBulletPlugin } from "./list.ts";
import { tablePlugin } from "./table.ts";
import { taskListPlugin } from "./task.ts";
import { cleanWikiLinkPlugin } from "./wiki_link.ts";
import { fencedCodePlugin } from "./fenced_code.ts";
import { frontmatterPlugin } from "./frontmatter.ts";
import { cleanEscapePlugin } from "./escapes.ts";
import { luaDirectivePlugin } from "./lua_directive.ts";
import { hashtagPlugin } from "./hashtag.ts";
import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client";
export function cleanModePlugins(client: Client) {
const pluginsNeededEvenWhenRenderingSyntax = [
luaDirectivePlugin(client),
cleanWikiLinkPlugin(client),
hashtagPlugin(),
];
if (client.ui.viewState.uiOptions.markdownSyntaxRendering) {
return pluginsNeededEvenWhenRenderingSyntax;
}
return [
...pluginsNeededEvenWhenRenderingSyntax,
linkPlugin(client),
blockquotePlugin(),
admonitionPlugin(),
hideMarksPlugin(),
hideHeaderMarkPlugin(),
cleanBlockPlugin(),
frontmatterPlugin(),
fencedCodePlugin(client),
taskListPlugin({
// TODO: Move this logic elsewhere?
onCheckboxClick: (pos) => {
const clickEvent: ClickEvent = {
page: client.currentName(),
altKey: false,
ctrlKey: false,
metaKey: false,
pos: pos,
};
// Propagate click event from checkbox
client.dispatchClickEvent(clickEvent);
},
}),
listBulletPlugin(),
tablePlugin(client),
cleanEscapePlugin(),
] as Extension[];
}