Files
plainleaf/plug-api/lib/attribute.test.ts
T
Zef HemelandGitHub a524c64884 Go backend (#1555)
* Replaces old Deno server with a Go implementation
* Restructured the code base accordingly
2025-09-19 13:23:20 +02:00

28 lines
1.1 KiB
TypeScript

import "./syscall_mock.ts";
import { parse } from "../../client/markdown_parser/parse_tree.ts";
import { extractAttributes } from "@silverbulletmd/silverbullet/lib/attribute";
import { assertEquals } from "@std/assert";
import { renderToText } from "./tree.ts";
import { extendedMarkdownLanguage } from "../../client/markdown_parser/parser.ts";
const inlineAttributeSample = `
# My document
Top level attributes: [name:: sup] [age:: 42] [children: [pete, "john", mary]]
* [ ] Attribute in a task [tag:: foo]
* Regular item [tag:: bar]
1. Itemized list [tag:: baz]
`;
Deno.test("Test attribute extraction", async () => {
const tree = parse(extendedMarkdownLanguage, inlineAttributeSample);
const toplevelAttributes = await extractAttributes(tree);
// console.log("All attributes", toplevelAttributes);
assertEquals(toplevelAttributes.name, "sup");
assertEquals(toplevelAttributes.age, 42);
assertEquals(toplevelAttributes.children, ["pete", "john", "mary"]);
// Check if the attributes are still there
assertEquals(renderToText(tree), inlineAttributeSample);
});