Remove "syntax" support from plugs
This commit is contained in:
+1
-22
@@ -94,17 +94,6 @@ export class Client {
|
||||
.catch((e) => console.error("Error dispatching editor:updated event", e));
|
||||
}, 1000);
|
||||
|
||||
debouncedPlugsUpdatedEvent = throttle(async () => {
|
||||
// To register new commands, update editor state based on new plugs
|
||||
this.rebuildEditorState();
|
||||
await this.dispatchAppEvent(
|
||||
"editor:pageLoaded",
|
||||
this.currentPage,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
}, 1000);
|
||||
|
||||
// Track if plugs have been updated since sync cycle
|
||||
fullSyncCompleted = false;
|
||||
|
||||
@@ -195,7 +184,7 @@ export class Client {
|
||||
|
||||
this.focus();
|
||||
|
||||
await this.system.init();
|
||||
this.system.init();
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
@@ -773,7 +762,6 @@ export class Client {
|
||||
|
||||
async loadPlugs() {
|
||||
await this.system.reloadPlugsFromSpace(this.space);
|
||||
this.rebuildEditorState();
|
||||
await this.eventHook.dispatchEvent("system:ready");
|
||||
await this.dispatchAppEvent("plugs:loaded");
|
||||
}
|
||||
@@ -782,12 +770,7 @@ export class Client {
|
||||
const editorView = this.editorView;
|
||||
console.log("Rebuilding editor state");
|
||||
|
||||
this.system.updateMarkdownParser();
|
||||
|
||||
if (this.currentPage) {
|
||||
// And update the editor if a page is loaded
|
||||
// this.openPages.saveState(this.currentPage);
|
||||
|
||||
editorView.setState(
|
||||
createEditorState(
|
||||
this,
|
||||
@@ -801,8 +784,6 @@ export class Client {
|
||||
editorView.contentDOM,
|
||||
);
|
||||
}
|
||||
|
||||
// this.openPages.restoreState(this.currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -930,8 +911,6 @@ export class Client {
|
||||
const editorView = this.editorView;
|
||||
const previousPage = this.currentPage;
|
||||
|
||||
// console.log("Navigating to", pageName, restoreState);
|
||||
|
||||
// Persist current page state and nicely close page
|
||||
if (previousPage) {
|
||||
// this.openPages.saveState(previousPage);
|
||||
|
||||
+4
-25
@@ -1,6 +1,5 @@
|
||||
import { PlugNamespaceHook } from "../common/hooks/plug_namespace.ts";
|
||||
import { Manifest, SilverBulletHooks } from "../common/manifest.ts";
|
||||
import buildMarkdown from "../common/markdown_parser/parser.ts";
|
||||
import { SilverBulletHooks } from "../common/manifest.ts";
|
||||
import { CronHook } from "../plugos/hooks/cron.ts";
|
||||
import { EventHook } from "../plugos/hooks/event.ts";
|
||||
import { createSandbox } from "../plugos/sandboxes/web_worker_sandbox.ts";
|
||||
@@ -23,10 +22,6 @@ import { syncSyscalls } from "./syscalls/sync.ts";
|
||||
import { systemSyscalls } from "./syscalls/system.ts";
|
||||
import { yamlSyscalls } from "../common/syscalls/yaml.ts";
|
||||
import { Space } from "./space.ts";
|
||||
import {
|
||||
loadMarkdownExtensions,
|
||||
MDExt,
|
||||
} from "../common/markdown_parser/markdown_ext.ts";
|
||||
import { MQHook } from "../plugos/hooks/mq.ts";
|
||||
import { mqSyscalls } from "../plugos/syscalls/mq.ts";
|
||||
import { mqProxySyscalls } from "./syscalls/mq.proxy.ts";
|
||||
@@ -51,7 +46,6 @@ export class ClientSystem {
|
||||
slashCommandHook: SlashCommandHook;
|
||||
namespaceHook: PlugNamespaceHook;
|
||||
codeWidgetHook: CodeWidgetHook;
|
||||
mdExtensions: MDExt[] = [];
|
||||
system: System<SilverBulletHooks>;
|
||||
panelWidgetHook: PanelWidgetHook;
|
||||
|
||||
@@ -139,22 +133,17 @@ export class ClientSystem {
|
||||
const plugName = plugNameExtractRegex.exec(path)![1];
|
||||
console.log("Plug updated, reloading", plugName, "from", path);
|
||||
this.system.unload(path);
|
||||
const plug = await this.system.load(
|
||||
await this.system.load(
|
||||
plugName,
|
||||
createSandbox(new URL(`/${path}`, location.href)),
|
||||
newHash,
|
||||
);
|
||||
if ((plug.manifest! as Manifest).syntax) {
|
||||
// If there are syntax extensions, rebuild the markdown parser immediately
|
||||
this.updateMarkdownParser();
|
||||
}
|
||||
this.client.debouncedPlugsUpdatedEvent();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async init() {
|
||||
init() {
|
||||
// Slash command hook
|
||||
this.slashCommandHook = new SlashCommandHook(this.client);
|
||||
this.system.addHook(this.slashCommandHook);
|
||||
@@ -166,7 +155,7 @@ export class ClientSystem {
|
||||
editorSyscalls(this.client),
|
||||
spaceSyscalls(this.client),
|
||||
systemSyscalls(this.system, this.client),
|
||||
markdownSyscalls(buildMarkdown(this.mdExtensions)),
|
||||
markdownSyscalls(),
|
||||
assetSyscalls(this.system),
|
||||
yamlSyscalls(),
|
||||
handlebarsSyscalls(),
|
||||
@@ -222,16 +211,6 @@ export class ClientSystem {
|
||||
}));
|
||||
}
|
||||
|
||||
updateMarkdownParser() {
|
||||
// Load all syntax extensions
|
||||
this.mdExtensions = loadMarkdownExtensions(this.system);
|
||||
// And reload the syscalls to use the new syntax extensions
|
||||
this.system.registerSyscalls(
|
||||
[],
|
||||
markdownSyscalls(buildMarkdown(this.mdExtensions)),
|
||||
);
|
||||
}
|
||||
|
||||
localSyscall(name: string, args: any[]) {
|
||||
return this.system.localSyscall(name, args);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Diagnostic, linter } from "@codemirror/lint";
|
||||
import type { Client } from "../client.ts";
|
||||
import { parse } from "../../common/markdown_parser/parse_tree.ts";
|
||||
import buildMarkdown from "../../common/markdown_parser/parser.ts";
|
||||
import { LintEvent } from "$sb/app_event.ts";
|
||||
import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts";
|
||||
|
||||
export function plugLinter(client: Client) {
|
||||
return linter(async (view): Promise<Diagnostic[]> => {
|
||||
const tree = parse(
|
||||
buildMarkdown(client.system.mdExtensions),
|
||||
extendedMarkdownLanguage,
|
||||
view.state.sliceDoc(),
|
||||
);
|
||||
const results = (await client.dispatchAppEvent("editor:lint", {
|
||||
|
||||
@@ -4,8 +4,8 @@ import type { CodeWidgetButton, CodeWidgetCallback } from "$sb/types.ts";
|
||||
import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts";
|
||||
import { resolveAttachmentPath } from "$sb/lib/resolve.ts";
|
||||
import { parse } from "../../common/markdown_parser/parse_tree.ts";
|
||||
import buildMarkdown from "../../common/markdown_parser/parser.ts";
|
||||
import { parsePageRef } from "$sb/lib/page.ts";
|
||||
import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts";
|
||||
|
||||
const activeWidgets = new Set<MarkdownWidget>();
|
||||
|
||||
@@ -59,9 +59,8 @@ export class MarkdownWidget extends WidgetType {
|
||||
);
|
||||
return;
|
||||
}
|
||||
const lang = buildMarkdown(this.client.system.mdExtensions);
|
||||
let mdTree = parse(
|
||||
lang,
|
||||
extendedMarkdownLanguage,
|
||||
widgetContent.markdown!,
|
||||
);
|
||||
mdTree = await this.client.system.localSyscall(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CompletionContext, CompletionResult } from "../deps.ts";
|
||||
import { PageMeta } from "$sb/types.ts";
|
||||
import { isFederationPath } from "$sb/lib/resolve.ts";
|
||||
|
||||
const tagRegex = /#[^#\d\s\[\]]+\w+/g;
|
||||
export const tagRegex = /#[^#\d\s\[\]]+\w+/g;
|
||||
|
||||
export function PageNavigator({
|
||||
allPages,
|
||||
|
||||
+5
-8
@@ -1,6 +1,4 @@
|
||||
import buildMarkdown, {
|
||||
commandLinkRegex,
|
||||
} from "../common/markdown_parser/parser.ts";
|
||||
import { commandLinkRegex } from "../common/markdown_parser/parser.ts";
|
||||
import { readonlyMode } from "./cm_plugins/readonly.ts";
|
||||
import customMarkdownStyle from "./style.ts";
|
||||
import {
|
||||
@@ -46,6 +44,7 @@ import { postScriptPrefacePlugin } from "./cm_plugins/top_bottom_panels.ts";
|
||||
import { languageFor } from "../common/languages.ts";
|
||||
import { plugLinter } from "./cm_plugins/lint.ts";
|
||||
import { Compartment, Extension } from "@codemirror/state";
|
||||
import { extendedMarkdownLanguage } from "../common/markdown_parser/parser.ts";
|
||||
|
||||
export function createEditorState(
|
||||
client: Client,
|
||||
@@ -55,8 +54,6 @@ export function createEditorState(
|
||||
): EditorState {
|
||||
let touchCount = 0;
|
||||
|
||||
const markdownLanguage = buildMarkdown(client.system.mdExtensions);
|
||||
|
||||
// Ugly: keep the keyhandler compartment in the client, to be replaced later once more commands are loaded
|
||||
client.keyHandlerCompartment = new Compartment();
|
||||
const keyBindings = client.keyHandlerCompartment.of(
|
||||
@@ -82,7 +79,7 @@ export function createEditorState(
|
||||
|
||||
// The uber markdown mode
|
||||
markdown({
|
||||
base: markdownLanguage,
|
||||
base: extendedMarkdownLanguage,
|
||||
codeLanguages: (info) => {
|
||||
const lang = languageFor(info);
|
||||
if (lang) {
|
||||
@@ -96,10 +93,10 @@ export function createEditorState(
|
||||
},
|
||||
addKeymap: true,
|
||||
}),
|
||||
markdownLanguage.data.of({
|
||||
extendedMarkdownLanguage.data.of({
|
||||
closeBrackets: { brackets: ["(", "{", "[", "`"] },
|
||||
}),
|
||||
syntaxHighlighting(customMarkdownStyle(client.system.mdExtensions)),
|
||||
syntaxHighlighting(customMarkdownStyle()),
|
||||
autocompletion({
|
||||
override: [
|
||||
client.editorComplete.bind(client),
|
||||
|
||||
+5
-5
@@ -1,9 +1,8 @@
|
||||
import { HighlightStyle } from "../common/deps.ts";
|
||||
import { tagHighlighter, tags as t } from "./deps.ts";
|
||||
import * as ct from "../common/markdown_parser/customtags.ts";
|
||||
import { MDExt } from "../common/markdown_parser/markdown_ext.ts";
|
||||
|
||||
export default function highlightStyles(mdExtension: MDExt[]) {
|
||||
export default function highlightStyles() {
|
||||
tagHighlighter;
|
||||
return HighlightStyle.define([
|
||||
{ tag: t.heading1, class: "sb-h1" },
|
||||
@@ -49,8 +48,9 @@ export default function highlightStyles(mdExtension: MDExt[]) {
|
||||
{ tag: t.processingInstruction, class: "sb-meta" },
|
||||
{ tag: t.punctuation, class: "sb-punctuation" },
|
||||
{ tag: ct.HorizontalRuleTag, class: "sb-hr" },
|
||||
...mdExtension.map((mdExt) => {
|
||||
return { tag: mdExt.tag, ...mdExt.styles, class: mdExt.className };
|
||||
}),
|
||||
{ tag: ct.HashtagTag, class: "sb-hashtag" },
|
||||
{ tag: ct.NakedURLTag, class: "sb-naked-url" },
|
||||
{ tag: ct.TaskDeadlineTag, class: "sb-task-deadline" },
|
||||
{ tag: ct.NamedAnchorTag, class: "sb-named-anchor" },
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -317,6 +317,10 @@
|
||||
font-size: 91%;
|
||||
}
|
||||
|
||||
.sb-task-deadline {
|
||||
background-color: rgba(22, 22, 22, 0.07)
|
||||
}
|
||||
|
||||
.sb-line-frontmatter-outside,
|
||||
.sb-line-code-outside {
|
||||
.sb-meta {
|
||||
|
||||
Reference in New Issue
Block a user