Refactoring about how proxy fetching happens

This commit is contained in:
Zef Hemel
2023-08-23 19:08:21 +02:00
parent 38a95d2382
commit 5a88254cde
18 changed files with 320 additions and 93 deletions
+14 -10
View File
@@ -1,7 +1,7 @@
import { Tag } from "../deps.ts";
import type { MarkdownConfig } from "../deps.ts";
import { System } from "../../plugos/system.ts";
import { Manifest } from "../manifest.ts";
import { Manifest, NodeDef } from "../manifest.ts";
export type MDExt = {
// unicode char code for efficiency .charCodeAt(0)
@@ -9,7 +9,7 @@ export type MDExt = {
regex: RegExp;
nodeType: string;
tag: Tag;
styles: { [key: string]: string };
styles?: { [key: string]: string };
className?: string;
};
@@ -53,16 +53,20 @@ export function loadMarkdownExtensions(system: System<any>): MDExt[] {
const manifest = plug.manifest as Manifest;
if (manifest.syntax) {
for (const [nodeType, def] of Object.entries(manifest.syntax)) {
mdExtensions.push({
nodeType,
tag: Tag.define(),
firstCharCodes: def.firstCharacters.map((ch) => ch.charCodeAt(0)),
regex: new RegExp("^" + def.regex),
styles: def.styles,
className: def.className,
});
mdExtensions.push(nodeDefToMDExt(nodeType, def));
}
}
}
return mdExtensions;
}
export function nodeDefToMDExt(nodeType: string, def: NodeDef): MDExt {
return {
nodeType,
tag: Tag.define(),
firstCharCodes: def.firstCharacters.map((ch) => ch.charCodeAt(0)),
regex: new RegExp("^" + def.regex),
styles: def.styles,
className: def.className,
};
}