1
0
silverbullet/web/cm_plugins/block.ts
Zef Hemel 91027af5fe
Awesome frontmatter (#617)
Live Frontmatter Templates
2024-01-04 20:08:12 +01:00

39 lines
1000 B
TypeScript

import { Decoration, EditorState, syntaxTree } from "../deps.ts";
import {
decoratorStateField,
invisibleDecoration,
isCursorInRange,
} from "./util.ts";
export function cleanBlockPlugin() {
return decoratorStateField(
(state: EditorState) => {
const widgets: any[] = [];
syntaxTree(state).iterate({
enter(node) {
if (
node.name === "HorizontalRule" &&
!isCursorInRange(state, [node.from, node.to])
) {
widgets.push(invisibleDecoration.range(node.from, node.to));
widgets.push(
Decoration.line({
class: "sb-line-hr",
}).range(node.from),
);
}
if (
node.name === "Image" &&
!isCursorInRange(state, [node.from, node.to])
) {
widgets.push(invisibleDecoration.range(node.from, node.to));
}
},
});
return Decoration.set(widgets, true);
},
);
}