Skip to content

Commit

Permalink
Remove "syntax" support from plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Jan 24, 2024
1 parent aaacec6 commit ad4a795
Show file tree
Hide file tree
Showing 24 changed files with 185 additions and 315 deletions.
34 changes: 1 addition & 33 deletions common/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,8 @@ export type SilverBulletHooks =
& EndpointHookT
& PlugNamespaceHookT;

/** Syntax extension allow plugs to declaratively add new *inline* parse tree nodes to the markdown parser. */
export type SyntaxExtensions = {
/** A map of node **name** (also called "type"), to parsing and highlighting instructions. Each entry defines a new node. By convention node names (types) are UpperCamelCase (PascalCase).
*
* see: plug-api/lib/tree.ts#ParseTree
*/
syntax?: { [key: string]: NodeDef };
};

/** Parsing and highlighting instructions for SyntaxExtension */
export type NodeDef = {
/** An array of possible first characters to begin matching on.
*
* **Example**: If this node has the regex '[abc][123]', NodeDef.firstCharacters should be ["a", "b", "c"].
*/
firstCharacters: string[];

/** A regular expression that matches the *entire* syntax, including the first character. */
regex: string;

/** CSS styles to apply to the matched text.
*
* Key-value pair of CSS key to value:
*
* **Example**: `backgroundColor: "rgba(22,22,22,0.07)"`
*/
styles?: { [key: string]: string };

/** CSS class name to apply to the matched text */
className?: string;
};

/** A plug manifest configures hooks, declares syntax extensions, and describes plug metadata.
*
* Typically the manifest file is in a plug's root directory, named `${plugName}.plug.yaml`.
*/
export type Manifest = plugos.Manifest<SilverBulletHooks> & SyntaxExtensions;
export type Manifest = plugos.Manifest<SilverBulletHooks>;
6 changes: 6 additions & 0 deletions common/markdown_parser/customtags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const AttributeTag = Tag.define();
export const AttributeNameTag = Tag.define();
export const AttributeValueTag = Tag.define();

export const NamedAnchorTag = Tag.define();

export const TaskTag = Tag.define();
export const TaskMarkTag = Tag.define();
export const TaskStateTag = Tag.define();
export const TaskDeadlineTag = Tag.define();

export const HashtagTag = Tag.define();
export const NakedURLTag = Tag.define();
72 changes: 0 additions & 72 deletions common/markdown_parser/markdown_ext.ts

This file was deleted.

22 changes: 8 additions & 14 deletions common/markdown_parser/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { parse } from "./parse_tree.ts";
import buildMarkdown from "./parser.ts";
import {
collectNodesOfType,
findNodeOfType,
renderToText,
} from "../../plug-api/lib/tree.ts";
import { assertEquals, assertNotEquals } from "../../test_deps.ts";
import { extendedMarkdownLanguage } from "./parser.ts";

const sample1 = `---
type: page
Expand All @@ -26,8 +26,7 @@ name: Zef
Supper`;

Deno.test("Test parser", () => {
const lang = buildMarkdown([]);
let tree = parse(lang, sample1);
let tree = parse(extendedMarkdownLanguage, sample1);
// console.log("tree", JSON.stringify(tree, null, 2));
// Check if rendering back to text works
assertEquals(renderToText(tree), sample1);
Expand All @@ -45,7 +44,7 @@ Deno.test("Test parser", () => {
// Find frontmatter
let node = findNodeOfType(tree, "FrontMatter");
assertNotEquals(node, undefined);
tree = parse(lang, sampleInvalid1);
tree = parse(extendedMarkdownLanguage, sampleInvalid1);
node = findNodeOfType(tree, "FrontMatter");
// console.log("Invalid node", node);
assertEquals(node, undefined);
Expand All @@ -62,8 +61,7 @@ And one with nested brackets: [array: [1, 2, 3]]
`;

Deno.test("Test inline attribute syntax", () => {
const lang = buildMarkdown([]);
const tree = parse(lang, inlineAttributeSample);
const tree = parse(extendedMarkdownLanguage, inlineAttributeSample);
// console.log("Attribute parsed", JSON.stringify(tree, null, 2));
const attributes = collectNodesOfType(tree, "Attribute");
let nameNode = findNodeOfType(attributes[0], "AttributeName");
Expand All @@ -89,8 +87,7 @@ const multiStatusTaskExample = `
`;

Deno.test("Test multi-status tasks", () => {
const lang = buildMarkdown([]);
const tree = parse(lang, multiStatusTaskExample);
const tree = parse(extendedMarkdownLanguage, multiStatusTaskExample);
// console.log("Tasks parsed", JSON.stringify(tree, null, 2));
const tasks = collectNodesOfType(tree, "Task");
assertEquals(tasks.length, 3);
Expand All @@ -107,8 +104,7 @@ const commandLinkSample = `
`;

Deno.test("Test command links", () => {
const lang = buildMarkdown([]);
const tree = parse(lang, commandLinkSample);
const tree = parse(extendedMarkdownLanguage, commandLinkSample);
const commands = collectNodesOfType(tree, "CommandLink");
console.log("Command links parsed", JSON.stringify(commands, null, 2));
assertEquals(commands.length, 3);
Expand All @@ -125,8 +121,7 @@ const commandLinkArgsSample = `
`;

Deno.test("Test command link arguments", () => {
const lang = buildMarkdown([]);
const tree = parse(lang, commandLinkArgsSample);
const tree = parse(extendedMarkdownLanguage, commandLinkArgsSample);
const commands = collectNodesOfType(tree, "CommandLink");
assertEquals(commands.length, 2);

Expand All @@ -138,7 +133,6 @@ Deno.test("Test command link arguments", () => {
});

Deno.test("Test template directives", () => {
const lang = buildMarkdown([]);
const tree = parse(lang, `Hello there {{name}}!`);
const tree = parse(extendedMarkdownLanguage, `Hello there {{name}}!`);
console.log("Template directive", JSON.stringify(tree, null, 2));
});
Loading

0 comments on commit ad4a795

Please sign in to comment.