* Fixes #529 by removing directives * Load builtin tags on space reindex
This commit is contained in:
@@ -3,7 +3,6 @@ import type { Extension } from "../deps.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import { blockquotePlugin } from "./block_quote.ts";
|
||||
import { admonitionPlugin } from "./admonition.ts";
|
||||
import { directivePlugin } from "./directive.ts";
|
||||
import { hideHeaderMarkPlugin, hideMarksPlugin } from "./hide_mark.ts";
|
||||
import { cleanBlockPlugin } from "./block.ts";
|
||||
import { linkPlugin } from "./link.ts";
|
||||
@@ -17,7 +16,6 @@ import { fencedCodePlugin } from "./fenced_code.ts";
|
||||
export function cleanModePlugins(editor: Client) {
|
||||
return [
|
||||
linkPlugin(editor),
|
||||
directivePlugin(),
|
||||
blockquotePlugin(),
|
||||
admonitionPlugin(editor),
|
||||
hideMarksPlugin(),
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
import {
|
||||
directiveEndRegex,
|
||||
directiveStartRegex,
|
||||
} from "../../plug-api/lib/query.ts";
|
||||
import { Decoration, EditorState, syntaxTree } from "../deps.ts";
|
||||
import { decoratorStateField, HtmlWidget, isCursorInRange } from "./util.ts";
|
||||
|
||||
// Does a few things: hides the directives when the cursor is not placed inside
|
||||
// Adds a class to the start and end of the directive when the cursor is placed inside
|
||||
export function directivePlugin() {
|
||||
return decoratorStateField((state: EditorState) => {
|
||||
const widgets: any[] = [];
|
||||
|
||||
syntaxTree(state).iterate({
|
||||
enter: ({ type, from, to, node }) => {
|
||||
const parent = node.parent;
|
||||
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cursorInRange = isCursorInRange(state, [parent.from, parent.to]);
|
||||
|
||||
if (type.name === "DirectiveStart") {
|
||||
if (cursorInRange) {
|
||||
// Cursor inside this directive
|
||||
widgets.push(
|
||||
Decoration.line({ class: "sb-directive-start" }).range(from),
|
||||
);
|
||||
} else {
|
||||
const text = state.sliceDoc(from, to);
|
||||
const match = directiveStartRegex.exec(text);
|
||||
if (!match) {
|
||||
console.error("Something went wrong with this directive");
|
||||
return;
|
||||
}
|
||||
const [_fullMatch, directiveName] = match;
|
||||
widgets.push(
|
||||
Decoration.widget({
|
||||
widget: new HtmlWidget(
|
||||
`#${directiveName}`,
|
||||
"sb-directive-placeholder",
|
||||
),
|
||||
}).range(from),
|
||||
);
|
||||
widgets.push(
|
||||
Decoration.line({
|
||||
class: "sb-directive-start sb-directive-start-outside",
|
||||
attributes: {
|
||||
spellcheck: "false",
|
||||
},
|
||||
}).range(
|
||||
from,
|
||||
),
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.name === "DirectiveEnd") {
|
||||
// Cursor outside this directive
|
||||
if (cursorInRange) {
|
||||
widgets.push(
|
||||
Decoration.line({ class: "sb-directive-end" }).range(from),
|
||||
);
|
||||
} else {
|
||||
const text = state.sliceDoc(from, to);
|
||||
const match = directiveEndRegex.exec(text);
|
||||
if (!match) {
|
||||
console.error("Something went wrong with this directive");
|
||||
return;
|
||||
}
|
||||
const [_fullMatch, directiveName] = match;
|
||||
widgets.push(
|
||||
Decoration.widget({
|
||||
widget: new HtmlWidget(
|
||||
`/${directiveName}`,
|
||||
"sb-directive-placeholder",
|
||||
),
|
||||
}).range(from),
|
||||
);
|
||||
widgets.push(
|
||||
Decoration.line({
|
||||
class: "sb-directive-end sb-directive-end-outside",
|
||||
}).range(
|
||||
from,
|
||||
),
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.name === "DirectiveBody") {
|
||||
const lines = state.sliceDoc(from, to).split("\n");
|
||||
let pos = from;
|
||||
for (const line of lines) {
|
||||
if (pos !== to) {
|
||||
widgets.push(
|
||||
Decoration.line({
|
||||
class: "sb-directive-body",
|
||||
}).range(pos),
|
||||
);
|
||||
}
|
||||
pos += line.length + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return Decoration.set(widgets, true);
|
||||
});
|
||||
}
|
||||
@@ -6,9 +6,8 @@ const straightQuoteContexts = [
|
||||
"FencedCode",
|
||||
"InlineCode",
|
||||
"FrontMatterCode",
|
||||
"DirectiveStart",
|
||||
"Attribute",
|
||||
"CommandLink"
|
||||
"CommandLink",
|
||||
];
|
||||
|
||||
// TODO: Add support for selection (put quotes around or create blockquote block?)
|
||||
|
||||
Reference in New Issue
Block a user