Attributes now have YAML values
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import "$sb/lib/syscall_mock.ts";
|
||||
import { parse } from "../../common/markdown_parser/parse_tree.ts";
|
||||
import buildMarkdown from "../../common/markdown_parser/parser.ts";
|
||||
import { extractAttributes } from "$sb/lib/attribute.ts";
|
||||
@@ -6,7 +7,7 @@ import { renderToText } from "$sb/lib/tree.ts";
|
||||
|
||||
const inlineAttributeSample = `
|
||||
# My document
|
||||
Top level attributes: [name:: sup] [age:: 42]
|
||||
Top level attributes: [name:: sup] [age:: 42] [children: [pete, "john", mary]]
|
||||
|
||||
* [ ] Attribute in a task [tag:: foo]
|
||||
* Regular item [tag:: bar]
|
||||
@@ -16,7 +17,7 @@ Top level attributes: [name:: sup] [age:: 42]
|
||||
|
||||
const cleanedInlineAttributeSample = `
|
||||
# My document
|
||||
Top level attributes:
|
||||
Top level attributes:
|
||||
|
||||
* [ ] Attribute in a task [tag:: foo]
|
||||
* Regular item [tag:: bar]
|
||||
@@ -24,16 +25,17 @@ Top level attributes:
|
||||
1. Itemized list [tag:: baz]
|
||||
`;
|
||||
|
||||
Deno.test("Test attribute extraction", () => {
|
||||
Deno.test("Test attribute extraction", async () => {
|
||||
const lang = buildMarkdown([]);
|
||||
const tree = parse(lang, inlineAttributeSample);
|
||||
const toplevelAttributes = extractAttributes(tree, false);
|
||||
assertEquals(Object.keys(toplevelAttributes).length, 2);
|
||||
const toplevelAttributes = await extractAttributes(tree, false);
|
||||
// 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);
|
||||
// Now once again with cleaning
|
||||
extractAttributes(tree, true);
|
||||
await extractAttributes(tree, true);
|
||||
assertEquals(renderToText(tree), cleanedInlineAttributeSample);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user