2022-12-09 15:09:53 +00:00
|
|
|
import { Decoration, EditorState, syntaxTree } from "../deps.ts";
|
2022-11-18 15:04:37 +00:00
|
|
|
import {
|
2022-12-09 15:09:53 +00:00
|
|
|
decoratorStateField,
|
2022-11-18 15:04:37 +00:00
|
|
|
invisibleDecoration,
|
|
|
|
isCursorInRange,
|
|
|
|
} from "./util.ts";
|
|
|
|
|
2022-12-09 15:09:53 +00:00
|
|
|
function decorateBlockQuote(state: EditorState) {
|
|
|
|
const widgets: any[] = [];
|
|
|
|
syntaxTree(state).iterate({
|
|
|
|
enter: ({ type, from, to }) => {
|
|
|
|
if (isCursorInRange(state, [from, to])) return;
|
|
|
|
if (type.name === "QuoteMark") {
|
|
|
|
widgets.push(invisibleDecoration.range(from, to));
|
|
|
|
widgets.push(
|
|
|
|
Decoration.line({ class: "sb-blockquote-outside" }).range(from),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return Decoration.set(widgets, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function blockquotePlugin() {
|
|
|
|
return decoratorStateField(decorateBlockQuote);
|
2022-11-18 15:04:37 +00:00
|
|
|
}
|